1+ import pytest
2+
13from hyperbrowser .client .managers .page_params_utils import (
24 DEFAULT_PAGE_BATCH_SIZE ,
35 build_page_batch_params ,
46)
7+ from hyperbrowser .exceptions import HyperbrowserError
58from hyperbrowser .models .crawl import GetCrawlJobParams
69from hyperbrowser .models .scrape import GetBatchScrapeJobParams
710
@@ -20,3 +23,54 @@ def test_build_page_batch_params_accepts_custom_batch_size():
2023 assert isinstance (params , GetCrawlJobParams )
2124 assert params .page == 2
2225 assert params .batch_size == 25
26+
27+
28+ def test_build_page_batch_params_rejects_non_plain_int_page ():
29+ with pytest .raises (HyperbrowserError , match = "page must be a plain integer" ):
30+ build_page_batch_params (GetBatchScrapeJobParams , page = True ) # type: ignore[arg-type]
31+
32+
33+ def test_build_page_batch_params_rejects_non_positive_page ():
34+ with pytest .raises (HyperbrowserError , match = "page must be a positive integer" ):
35+ build_page_batch_params (GetBatchScrapeJobParams , page = 0 )
36+
37+
38+ def test_build_page_batch_params_rejects_non_plain_int_batch_size ():
39+ class _IntSubclass (int ):
40+ pass
41+
42+ with pytest .raises (HyperbrowserError , match = "batch_size must be a plain integer" ):
43+ build_page_batch_params (
44+ GetBatchScrapeJobParams ,
45+ page = 1 ,
46+ batch_size = _IntSubclass (10 ), # type: ignore[arg-type]
47+ )
48+
49+
50+ def test_build_page_batch_params_rejects_non_positive_batch_size ():
51+ with pytest .raises (HyperbrowserError , match = "batch_size must be a positive integer" ):
52+ build_page_batch_params (GetBatchScrapeJobParams , page = 1 , batch_size = 0 )
53+
54+
55+ def test_build_page_batch_params_wraps_runtime_constructor_errors ():
56+ class _BrokenParams :
57+ def __init__ (self , * , page , batch_size ): # noqa: ARG002
58+ raise RuntimeError ("boom" )
59+
60+ with pytest .raises (
61+ HyperbrowserError , match = "Failed to build paginated page params"
62+ ) as exc_info :
63+ build_page_batch_params (_BrokenParams , page = 1 )
64+
65+ assert isinstance (exc_info .value .original_error , RuntimeError )
66+
67+
68+ def test_build_page_batch_params_preserves_hyperbrowser_errors ():
69+ class _BrokenParams :
70+ def __init__ (self , * , page , batch_size ): # noqa: ARG002
71+ raise HyperbrowserError ("custom failure" )
72+
73+ with pytest .raises (HyperbrowserError , match = "custom failure" ) as exc_info :
74+ build_page_batch_params (_BrokenParams , page = 1 )
75+
76+ assert exc_info .value .original_error is None
0 commit comments