Skip to content

Commit

Permalink
reformat paremetrize args
Browse files Browse the repository at this point in the history
  • Loading branch information
xflr6 committed Dec 15, 2021
1 parent 4d3cdca commit c809276
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 54 deletions.
60 changes: 32 additions & 28 deletions tests/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from conftest import TEST_OUTPUT


@pytest.mark.parametrize('name, expected', [
('table', formats.Table),
('cxt', formats.Cxt),
('csv', formats.Csv),
('wiki-table', formats.WikiTable),
])
@pytest.mark.parametrize(
'name, expected',
[('table', formats.Table),
('cxt', formats.Cxt),
('csv', formats.Csv),
('wiki-table', formats.WikiTable)])
def test_getitem(name, expected):
assert formats.Format[name] is expected is formats.Format[name.upper()]

Expand All @@ -22,11 +22,11 @@ def test_getitem_invalid():
formats.Format['spam']


@pytest.mark.parametrize('filename, expected', [
('spam.TXT', 'table'),
('spam.cxt', 'cxt'),
('spam.spam.csv', 'csv')
])
@pytest.mark.parametrize(
'filename, expected',
[('spam.TXT', 'table'),
('spam.cxt', 'cxt'),
('spam.spam.csv', 'csv')])
def test_infer_format(filename, expected):
assert formats.Format.infer_format(filename) == expected

Expand Down Expand Up @@ -171,13 +171,14 @@ class TestCsvUnicode(unittest.TestCase, Unicode):
'''


@pytest.mark.parametrize('source, kwargs', [
('''\
@pytest.mark.parametrize(
'source, kwargs',
[('''\
cheese,in_stock,sold_out\r
Cheddar,0,1\r
Limburger,0,1\r
''', {}),
('''\
('''\
cheese,in_stock,sold_out\r
Cheddar,,X\r
Limburger,,X\r
Expand All @@ -190,13 +191,14 @@ def test_csv_loads_auto_as_int(source, kwargs):
assert args.bools == [(False, True), (False, True)]


@pytest.mark.parametrize('source, expected, match', [
('''\
@pytest.mark.parametrize(
'source, expected, match',
[('''\
cheese,in_stock,sold_out\r
Cheddar,0,\r
Limburger,0,1\r
''', ValueError, r"first row: \['Cheddar', '0', ''\]"),
('''\
('''\
cheese,in_stock,sold_out\r
Cheddar,0,1\r
Limburger,X,1\r
Expand Down Expand Up @@ -269,8 +271,9 @@ class TestFimi(unittest.TestCase, Ascii):
'''


@pytest.mark.parametrize('frmat, label, kwargs, expected', [
('table', None, {}, '''\
@pytest.mark.parametrize(
'frmat, label, kwargs, expected',
[('table', None, {}, '''\
|+1|-1|+2|-2|+3|-3|+sg|+pl|-sg|-pl|
1sg|X | | |X | |X |X | | |X |
1pl|X | | |X | |X | |X |X | |
Expand All @@ -279,7 +282,7 @@ class TestFimi(unittest.TestCase, Ascii):
3sg| |X | |X |X | |X | | |X |
3pl| |X | |X |X | | |X |X | |
'''),
('cxt', None, {}, '''\
('cxt', None, {}, '''\
B
6
Expand Down Expand Up @@ -308,7 +311,7 @@ class TestFimi(unittest.TestCase, Ascii):
.X.XX.X..X
.X.XX..XX.
'''),
('python-literal', 'literal', {}, '''\
('python-literal', 'literal', {}, '''\
{
'objects': (
'1sg', '1pl', '2sg', '2pl', '3sg', '3pl',
Expand All @@ -326,7 +329,7 @@ class TestFimi(unittest.TestCase, Ascii):
],
}
'''),
('csv', 'str', {'bools_as_int': False}, '''\
('csv', 'str', {'bools_as_int': False}, '''\
,+1,-1,+2,-2,+3,-3,+sg,+pl,-sg,-pl
1sg,X,,,X,,X,X,,,X
1pl,X,,,X,,X,,X,X,
Expand All @@ -335,7 +338,7 @@ class TestFimi(unittest.TestCase, Ascii):
3sg,,X,,X,X,,X,,,X
3pl,,X,,X,X,,,X,X,
'''),
('csv', 'int', {'bools_as_int': True}, '''\
('csv', 'int', {'bools_as_int': True}, '''\
,+1,-1,+2,-2,+3,-3,+sg,+pl,-sg,-pl
1sg,1,0,0,1,0,1,1,0,0,1
1pl,1,0,0,1,0,1,0,1,1,0
Expand All @@ -344,15 +347,15 @@ class TestFimi(unittest.TestCase, Ascii):
3sg,0,1,0,1,1,0,1,0,0,1
3pl,0,1,0,1,1,0,0,1,1,0
'''),
('fimi', None, {}, '''\
('fimi', None, {}, '''\
0 3 5 6 9
0 3 5 7 8
1 2 5 6 9
1 2 5 7 8
1 3 4 6 9
1 3 4 7 8
'''),
('wiki-table', 'wiki-table', {}, '''\
('wiki-table', 'wiki-table', {}, '''\
{| class="featuresystem"
!
!+1!!-1!!+2!!-2!!+3!!-3!!+sg!!+pl!!-sg!!-pl
Expand Down Expand Up @@ -409,8 +412,9 @@ def write_format(target, objects, properties, bools, *, Format, **kwargs):
return result


@pytest.mark.parametrize('extents, label, expected', [
(False, 'intents', '''\
@pytest.mark.parametrize(
'extents, label, expected',
[(False, 'intents', '''\
0 1 2 3 4 5 6 7 8 9
0 3 5 6 9
0 3 5 7 8
Expand All @@ -434,7 +438,7 @@ def write_format(target, objects, properties, bools, *, Format, **kwargs):
1
'''),
(True, 'extents', '''\
(True, 'extents', '''\
0
1
Expand Down
34 changes: 17 additions & 17 deletions tests/test_lattices.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,34 +86,34 @@ def test_len(lattice):
assert len(lattice) == 22


@pytest.mark.parametrize('concepts, expected', [
([('+1',), ('+2',)], [('+1',), ('+2',),
('-3',), ('-2',), ('-1',),
()]),
])
@pytest.mark.parametrize(
'concepts, expected',
[([('+1',), ('+2',)], [('+1',), ('+2',),
('-3',), ('-2',), ('-1',),
()])])
def test_upset_union(lattice, concepts, expected):
concepts, expected = ([lattice[a] for a in arg] for arg in (concepts, expected))
assert list(lattice.upset_union(concepts)) == expected


@pytest.mark.parametrize('concepts, expected', [
([('+1',), ('+2',)], [('+1',), ('+2',),
('+1', '+sg'), ('+1', '+pl'),
('+2', '+sg'), ('+2', '+pl'),
('+1', '-1', '+2', '-2', '+3', '-3', '+sg', '+pl', '-sg', '-pl')]),
])
@pytest.mark.parametrize(
'concepts, expected',
[([('+1',), ('+2',)], [('+1',), ('+2',),
('+1', '+sg'), ('+1', '+pl'),
('+2', '+sg'), ('+2', '+pl'),
('+1', '-1', '+2', '-2', '+3', '-3', '+sg', '+pl', '-sg', '-pl')])])
def test_downset_union(lattice, concepts, expected):
concepts, expected = ([lattice[a] for a in arg]
for arg in (concepts, expected))
assert list(lattice.downset_union(concepts)) == expected


@pytest.mark.parametrize('concepts, expected', [
([('+1', '+sg'), ('+2', '+sg'), ('+3', '+sg')],
[('+1', '+sg'), ('+2', '+sg'), ('+3', '+sg'),
('-3', '+sg'), ('-2', '+sg'), ('-1', '+sg'),
('+sg',)]),
])
@pytest.mark.parametrize(
'concepts, expected',
[([('+1', '+sg'), ('+2', '+sg'), ('+3', '+sg')],
[('+1', '+sg'), ('+2', '+sg'), ('+3', '+sg'),
('-3', '+sg'), ('-2', '+sg'), ('-1', '+sg'),
('+sg',)])])
def test_upset_generalization(lattice, concepts, expected):
concepts, expected = ([lattice[a] for a in arg]
for arg in (concepts, expected))
Expand Down
19 changes: 10 additions & 9 deletions tests/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@
'context': list(SERIALIZED['context'])}


@pytest.mark.parametrize('source, filename, includes_lattice', [
(repr(SERIALIZED), None, True),
(repr(SERIALIZED_NOLATTICE), None, False),
(repr(SERIALIZED), 'example-serialized-lattice.py', True),
(repr(SERIALIZED_NOLATTICE), 'example-serialized-lattice.py', False),
])
@pytest.mark.parametrize(
'source, filename, includes_lattice',
[(repr(SERIALIZED), None, True),
(repr(SERIALIZED_NOLATTICE), None, False),
(repr(SERIALIZED), 'example-serialized-lattice.py', True),
(repr(SERIALIZED_NOLATTICE), 'example-serialized-lattice.py', False)])
def test_fromstring_serialized(tmp_path, source, filename, includes_lattice):
if filename is None:
context = Context.fromstring(source, frmat='python-literal')
Expand Down Expand Up @@ -248,8 +248,9 @@ def test_dict_roundtrip(context, ignore_lattice):


@pytest.mark.parametrize('to_file', [False, True])
@pytest.mark.parametrize('with_lattice, expected_doc, expected_str', [
(False, SERIALIZED_NOLATTICE,
@pytest.mark.parametrize(
'with_lattice, expected_doc, expected_str',
[(False, SERIALIZED_NOLATTICE,
'''\
{
'objects': (
Expand All @@ -268,7 +269,7 @@ def test_dict_roundtrip(context, ignore_lattice):
],
}
'''),
(True, SERIALIZED,
(True, SERIALIZED,
'''\
{
'objects': (
Expand Down

0 comments on commit c809276

Please sign in to comment.