Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace try:/expect: by 'with pytest.raise(ValueError):' #80

Merged
merged 5 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions yamale/tests/command_line_fixtures/empty_schema/data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a: 1
46 changes: 15 additions & 31 deletions yamale/tests/test_command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,22 @@

@pytest.mark.parametrize('parser', parsers)
def test_bad_yaml(capsys, parser):
try:
with pytest.raises(ValueError, match='Validation failed!'):
command_line._router(
'yamale/tests/command_line_fixtures/yamls/bad.yaml',
'schema.yaml', 1, parser)
except ValueError as e:
assert 'Validation failed!' in str(e)
captured = capsys.readouterr()
assert "map.bad: '12.5' is not a str." in captured.out
return
assert False
captured = capsys.readouterr()
assert "map.bad: '12.5' is not a str." in captured.out


@pytest.mark.parametrize('parser', parsers)
def test_required_keys_yaml(capsys, parser):
try:
with pytest.raises(ValueError, match='Validation failed!'):
command_line._router(
'yamale/tests/command_line_fixtures/yamls/required_keys_bad.yaml',
'required_keys_schema.yaml', 1, parser)
except ValueError as e:
assert 'Validation failed!' in str(e)
captured = capsys.readouterr()
assert "map.key: Required field missing" in captured.out
return
assert False
captured = capsys.readouterr()
assert "map.key: Required field missing" in captured.out


@pytest.mark.parametrize('parser', parsers)
Expand All @@ -58,13 +50,13 @@ def test_external_glob_schema(parser):
os.path.join(dir_path, 'command_line_fixtures/schema_dir/ex*.yaml'), 1, parser)


def test_empty_schema_file():
try:
def test_empty_schema_file(capsys):
with pytest.raises(ValueError, match='Validation failed!'):
command_line._router(
'yamale/tests/command_line_fixtures/empty_schema',
'yamale/tests/command_line_fixtures/empty_schema/data.yaml',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find! This test was missing the final assert False. Please add the data.yaml file to git. Thanks!

'empty_schema.yaml' , 1, 'PyYAML')
except ValueError as e:
assert 'empty_schema.yaml is an empty file!' in str(e)
captured = capsys.readouterr()
assert 'empty_schema.yaml is an empty file!' in captured.out


def test_external_schema():
Expand All @@ -74,25 +66,17 @@ def test_external_schema():


def test_bad_dir():
try:
with pytest.raises(ValueError, match='Validation failed!'):
command_line._router(
'yamale/tests/command_line_fixtures/yamls',
'schema.yaml', 4, 'PyYAML')
except ValueError as e:
assert 'Validation failed!' in str(e)
return
assert False


def test_bad_strict(capsys):
try:
with pytest.raises(ValueError, match='Validation failed!'):
command_line._router(
'yamale/tests/command_line_fixtures/yamls/required_keys_extra_element.yaml',
'required_keys_schema.yaml',
4, 'PyYAML', strict=True)
except ValueError as e:
assert 'Validation failed!' in str(e)
captured = capsys.readouterr()
assert "map.key2: Unexpected element" in captured.out
return
assert False
captured = capsys.readouterr()
assert "map.key2: Unexpected element" in captured.out