-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
9 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
"""Tests to validate yaml features.""" | ||
from nelkit.exceptions import FileNotFound, ParsingError | ||
from nelkit.parsing.yaml.loader import YamlLoader | ||
import os | ||
import pytest | ||
s = os.sep | ||
|
||
|
||
def test_YamlLoader(): | ||
"""Test to see that the YamlLoader returns a dict.""" | ||
yl = YamlLoader(filename='tests/parsing/yaml/data/base.yml') | ||
yl = YamlLoader(filename='tests%sparsing%syaml%sdata%sbase.yml' % (s, s, s, s)) | ||
assert isinstance(yl.data, dict) | ||
|
||
|
||
def test_load_missing_file(): | ||
"""Test to verify that an exception is raised when trying to load a non-existing file.""" | ||
with pytest.raises(FileNotFound) as excinfo: | ||
YamlLoader(filename='tests/parsing/yaml/data/file_that_does_not_exist.yml') | ||
assert 'Unable to read: tests/parsing/yaml/data/file_that_does_not_exist.yml' == str(excinfo.value) | ||
YamlLoader(filename='tests%sparsing%syaml%sdata%sfile_that_does_not_exist.yml' % (s, s, s, s)) | ||
assert 'Unable to read: tests%sparsing%syaml%sdata%sfile_that_does_not_exist.yml' % ( | ||
s, s, s, s) == str(excinfo.value) | ||
|
||
|
||
def test_load_invalid_file(): | ||
"""Test to verify that an exception is raised when the yaml file is invalid.""" | ||
with pytest.raises(ParsingError) as excinfo: | ||
YamlLoader(filename='tests/parsing/yaml/data/invalid_yaml.yml') | ||
assert 'tests/parsing/yaml/data/invalid_yaml.yml is not a valid yaml file' == str(excinfo.value) | ||
YamlLoader(filename='tests%sparsing%syaml%sdata%sinvalid_yaml.yml' % (s, s, s, s)) | ||
assert 'tests%sparsing%syaml%sdata%sinvalid_yaml.yml is not a valid yaml file' % ( | ||
s, s, s, s) == str(excinfo.value) |