Skip to content

Commit

Permalink
Use parametrized TestModule.test_fields_of_type_list
Browse files Browse the repository at this point in the history
Instead of test_source_field and test_build_commands_field.
  • Loading branch information
jiri-janousek committed Jan 12, 2019
1 parent 97c3f7a commit 86abe57
Showing 1 changed file with 23 additions and 34 deletions.
57 changes: 23 additions & 34 deletions nufb/tests/test_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,45 +238,34 @@ def test_name_field(self):
module.name = 123
assert module.name == name

def test_sources_field(self):
"""The sources property."""
assert wrappers.Module().sources == []

sources = []
data = {'sources': sources}
module = wrappers.Module(data)
assert module.sources == []
assert id(module.sources) == id(sources)

sources.append({'path': 'file.txt'})
module = wrappers.Module(data)
assert module.sources == [{'path': 'file.txt'}]
assert id(module.sources) == id(sources)

data = {'sources': 'file.txt'}
@pytest.mark.parametrize('field,key,values', [
('sources', None, [{'path': 'file.txt'}]),
('build_commands', None, [{'path': 'file.txt'}]),
])
def test_fields_of_type_list(self, field: str, key: str, values: list):
"""Properties which return a list."""
if not key:
key = field.replace('_', '-')

assert getattr(wrappers.Module(), field) == []

empty: list = []
data: dict = {key: empty}
module = wrappers.Module(data)
with pytest.raises(TypeError):
__ = module.sources # noqa

def test_build_commands_field(self):
"""The sources property."""
assert wrappers.Module().sources == []
result = getattr(module, field)
assert result == []
assert id(result) == id(empty)

build_commands = []
data = {'build-commands': build_commands}
data = {key: values}
original_values = values[:]
module = wrappers.Module(data)
assert module.build_commands == []
assert id(module.build_commands) == id(build_commands)
result = getattr(module, field)
assert result == original_values
assert id(result) == id(values)

build_commands.append({'path': 'file.txt'})
module = wrappers.Module(data)
assert module.build_commands == [{'path': 'file.txt'}]
assert id(module.build_commands) == id(build_commands)

data = {'build-commands': 'file.txt'}
module = wrappers.Module(data)
data = {key: 123456}
with pytest.raises(TypeError):
__ = module.build_commands # noqa
getattr(wrappers.Module(data), field)

def test_str(self):
"""str() shouldn't raise an error"""
Expand Down

0 comments on commit 86abe57

Please sign in to comment.