Skip to content

Commit

Permalink
Add Test for Recursive Include Support
Browse files Browse the repository at this point in the history
To guard against regression, and prove functionality, added a test and
associated example data to make sure nested `!include` directives work
and a test to make sure loading non-yaml and non-json files works.
  • Loading branch information
Ben Hamill committed May 16, 2015
1 parent 7912817 commit 5822b6f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
5 changes: 5 additions & 0 deletions tests/data/examples/includes/all-the-properties.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#%RAML 0.8

external: !include properties.raml
foo: !include foo-properties.raml
not_yaml: !include not_yaml.txt
1 change: 1 addition & 0 deletions tests/data/examples/includes/not_yaml.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is just a string.
4 changes: 4 additions & 0 deletions tests/data/examples/nested-includes.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#%RAML 0.8
title: GitHub API Demo - Includes
version: v3
include_one: !include includes/all-the-properties.raml
4 changes: 4 additions & 0 deletions tests/data/examples/nonyaml-includes.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#%RAML 0.8
title: GitHub API Demo - Includes
version: v3
not_yaml: !include includes/not_yaml.txt
46 changes: 38 additions & 8 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,44 @@ def test_load_file():
assert dict_equal(raml, expected_data)


def test_load_file_with_nested_includes():
raml_file = os.path.join(EXAMPLES + "nested-includes.raml")
with open(raml_file) as f:
raml = loader.RAMLLoader().load(f)

expected_data = {
'include_one': {
'external': {
'propertyA': 'valueA',
'propertyB': 'valueB'
},
'foo': {
'foo': 'FooBar',
'bar': 'BarBaz'
},
'not_yaml': "This is just a string.\n",
},
'title': 'GitHub API Demo - Includes',
'version': 'v3'
}

assert dict_equal(raml, expected_data)


def test_load_file_with_nonyaml_include():
raml_file = os.path.join(EXAMPLES + "nonyaml-includes.raml")
with open(raml_file) as f:
raml = loader.RAMLLoader().load(f)

expected_data = {
'not_yaml': "This is just a string.\n",
'title': 'GitHub API Demo - Includes',
'version': 'v3'
}

assert dict_equal(raml, expected_data)


def test_load_string():
raml_str = ("""
- foo
Expand All @@ -62,14 +100,6 @@ def test_yaml_parser_error():
assert msg in e.value.args[0]


def test_cyclic_includes_raises_error():
raml_file = os.path.join(EXAMPLES + "cyclic_includes.raml")
with pytest.raises(LoadRAMLError) as e:
loader.RAMLLoader().load(open(raml_file))
msg = "Recursively-including files not supported."
assert msg in e.value.args[0]


def test_include_json():
raml_file = os.path.join(EXAMPLES + "json_includes.raml")
with open(raml_file) as f:
Expand Down

0 comments on commit 5822b6f

Please sign in to comment.