88from hypothesis import strategies as st
99
1010import snakebids .tests .strategies as sb_st
11+ from snakebids .core ._table import BidsTable
1112from snakebids .core .datasets import BidsComponent , BidsDataset
12- from snakebids .io .printing import format_zip_lists
13- from snakebids .types import ZipList
1413
1514
1615def zip_list_parser () -> pp .ParserElement :
@@ -26,39 +25,22 @@ def zip_list_parser() -> pp.ParserElement:
2625
2726
2827@given (zip_list = sb_st .bids_tables (max_entities = 1 , restrict_patterns = True ))
29- def test_ellipses_appears_when_maxwidth_too_short (zip_list : ZipList ):
30- width = len (format_zip_lists (zip_list , tabstop = 0 ).splitlines ()[1 ])
31- parsed = zip_list_parser ().parse_string (
32- format_zip_lists (zip_list , width - 1 , tabstop = 0 )
33- )
28+ def test_ellipses_appears_when_maxwidth_too_short (zip_list : BidsTable ):
29+ width = len (zip_list .pformat (tabstop = 0 ).splitlines ()[1 ])
30+ parsed = zip_list_parser ().parse_string (zip_list .pformat (width - 1 , tabstop = 0 ))
3431 assert "ellipse" in parsed [0 ]
3532
3633
3734@given (zip_list = sb_st .bids_tables (max_entities = 1 , restrict_patterns = True ))
38- def test_no_ellipses_when_no_max_width (zip_list : ZipList ):
39- parsed = zip_list_parser ().parse_string (format_zip_lists ( zip_list , tabstop = 0 ))
35+ def test_no_ellipses_when_no_max_width (zip_list : BidsTable ):
36+ parsed = zip_list_parser ().parse_string (zip_list . pformat ( tabstop = 0 ))
4037 assert "ellipse" not in parsed [0 ]
4138
4239
4340@given (zip_list = sb_st .bids_tables (max_entities = 1 , restrict_patterns = True ))
44- def test_no_ellipses_when_max_width_long_enouth (zip_list : ZipList ):
45- width = len (format_zip_lists (zip_list , tabstop = 0 ).splitlines ()[1 ])
46- parsed = zip_list_parser ().parse_string (
47- format_zip_lists (zip_list , width , tabstop = 0 )
48- )
49- assert "ellipse" not in parsed [0 ]
50-
51-
52- @given (
53- zip_list = sb_st .bids_tables (
54- max_entities = 1 , min_values = 0 , max_values = 0 , restrict_patterns = True
55- )
56- )
57- def test_no_ellipses_appears_when_ziplist_empty (zip_list : ZipList ):
58- width = len (format_zip_lists (zip_list , tabstop = 0 ).splitlines ()[1 ])
59- parsed = zip_list_parser ().parse_string (
60- format_zip_lists (zip_list , width - 1 , tabstop = 0 )
61- )
41+ def test_no_ellipses_when_max_width_long_enough (zip_list : BidsTable ):
42+ width = len (zip_list .pformat (tabstop = 0 ).splitlines ()[1 ])
43+ parsed = zip_list_parser ().parse_string (zip_list .pformat (width , tabstop = 0 ))
6244 assert "ellipse" not in parsed [0 ]
6345
6446
@@ -68,9 +50,9 @@ def test_no_ellipses_appears_when_ziplist_empty(zip_list: ZipList):
6850 ),
6951 width = st .integers (min_value = 10 , max_value = 200 ),
7052)
71- def test_values_balanced_around_elision_correctly (zip_list : ZipList , width : int ):
53+ def test_values_balanced_around_elision_correctly (zip_list : BidsTable , width : int ):
7254 parsed : pp .ParseResults = zip_list_parser ().parse_string (
73- format_zip_lists ( zip_list , max_width = width , tabstop = 0 )
55+ zip_list . pformat ( max_width = width , tabstop = 0 )
7456 )
7557 assert parsed
7658 assert parsed [0 ]
@@ -95,9 +77,9 @@ class TestCorrectNumberOfLinesCreated:
9577 min_values = 0 , max_values = 1 , max_entities = 6 , restrict_patterns = True
9678 ),
9779 )
98- def test_in_zip_list (self , zip_list : ZipList ):
80+ def test_in_zip_list (self , zip_list : BidsTable ):
9981 assert (
100- len (format_zip_lists ( zip_list , tabstop = 0 ).splitlines ()) == len (zip_list ) + 2
82+ len (zip_list . pformat ( tabstop = 0 ).splitlines ()) == len (zip_list . wildcards ) + 2
10183 )
10284
10385 @given (
@@ -124,8 +106,8 @@ class TestIsValidPython:
124106 @given (
125107 zip_list = sb_st .bids_tables (restrict_patterns = True , min_values = 0 , min_entities = 0 )
126108 )
127- def test_in_zip_list (self , zip_list : ZipList ):
128- assert eval (format_zip_lists ( zip_list , inf )) == zip_list
109+ def test_in_zip_list (self , zip_list : BidsTable ):
110+ assert eval (zip_list . pformat ( inf )) == zip_list . to_dict ()
129111
130112 @given (component = sb_st .bids_components (restrict_patterns = True , min_values = 0 ))
131113 def test_in_component (self , component : BidsComponent ):
@@ -144,9 +126,9 @@ def test_in_dataset(self, dataset: BidsDataset):
144126 width = st .integers (10 , 100 ),
145127 tab = st .integers (0 , 10 ),
146128)
147- def test_line_never_longer_than_max_width (zip_list : ZipList , width : int , tab : int ):
129+ def test_line_never_longer_than_max_width (zip_list : BidsTable , width : int , tab : int ):
148130 assume (width > tab + 10 )
149- formatted = format_zip_lists ( zip_list , width , tab )
131+ formatted = zip_list . pformat ( width , tab )
150132 parsed = zip_list_parser ().parse_string (formatted )
151133 assume ("left" in parsed [0 ])
152134 assert all (len (line ) <= width for line in formatted .splitlines ())
@@ -161,8 +143,8 @@ class TestIndentLengthMultipleOfTabStop:
161143 zip_list = sb_st .bids_tables (restrict_patterns = True , min_values = 0 ),
162144 tabstop = st .integers (1 , 10 ),
163145 )
164- def test_in_zip_list (self , zip_list : ZipList , tabstop : int ):
165- for line in format_zip_lists ( zip_list , tabstop = tabstop ).splitlines ():
146+ def test_in_zip_list (self , zip_list : BidsTable , tabstop : int ):
147+ for line in zip_list . pformat ( tabstop = tabstop ).splitlines ():
166148 assert get_indent_length (line ) / tabstop in {0 , 1 }
167149
168150 @given (
0 commit comments