Skip to content

Commit 15329e5

Browse files
committed
Fixes to tests
1 parent 1e00e3b commit 15329e5

3 files changed

Lines changed: 22 additions & 40 deletions

File tree

snakebids/core/_table.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ def get(self, wildcard: str):
8282
def pick(self, wildcards: Iterable[str]):
8383
"""Select wildcards without deduplication."""
8484
# Use dict.fromkeys for de-duplication to preserve order
85-
indices = [self.wildcards.index(w) for w in dict.fromkeys(wildcards)]
85+
unique_keys = list(dict.fromkeys(wildcards))
86+
indices = [self.wildcards.index(w) for w in unique_keys]
8687

8788
entries = [tuple(entry[i] for i in indices) for entry in self.entries]
8889

89-
return self.__class__(wildcards=wildcards, entries=entries)
90+
return self.__class__(wildcards=unique_keys, entries=entries)
9091

9192
def filter(
9293
self,

snakebids/core/input_generation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
Any,
1313
Iterable,
1414
Literal,
15-
cast,
1615
overload,
1716
)
1817

snakebids/tests/test_printing.py

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
from hypothesis import strategies as st
99

1010
import snakebids.tests.strategies as sb_st
11+
from snakebids.core._table import BidsTable
1112
from snakebids.core.datasets import BidsComponent, BidsDataset
12-
from snakebids.io.printing import format_zip_lists
13-
from snakebids.types import ZipList
1413

1514

1615
def 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

Comments
 (0)