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

Fix parse string #120

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion ramlfications/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ def parse(raml, config_file=None):
:raises InvalidParameterError: Named parameter is invalid \
according to RAML `specification <http://raml.org/spec.html>`_.
"""
loader = load(raml)
if "#%RAML" in raml:
# This has RAML declaration so it's not a filepath
# Load from string
loader = loads(raml)
else:
loader = load(raml)
config = setup_config(config_file)
return parse_raml(loader, config)

Expand Down
1 change: 1 addition & 0 deletions ramlfications/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def _load_media_types():
with open(media_types_file, "r") as f:
return json.load(f)


HTTP_METHODS = [
"get", "post", "put", "delete", "patch", "head",
"options", "trace", "connect"
Expand Down
9 changes: 8 additions & 1 deletion tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,20 @@ def raml_string():
"""


def test_parse(raml):
def test_parse_filepath(raml):
config = os.path.join(EXAMPLES + "test-config.ini")
result = parse(raml, config)
assert result
assert isinstance(result, RootNode)


def test_parse_string(raml_string):
config = os.path.join(EXAMPLES + "test-config.ini")
result = parse(raml_string, config)
assert result
assert isinstance(result, RootNode)


def test_parse_nonexistant_file():
raml_file = "/tmp/non-existant-raml-file.raml"
with pytest.raises(LoadRAMLError):
Expand Down