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

Yml is not always a dict #11

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
8 changes: 8 additions & 0 deletions tests/test_yamldown.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ def test_load_md_first(self):
self.assertEqual(yml_contents, expected_yml)
self.assertEqual(md_contents, expected_md)

def test_return_empty_dict_when_no_yaml(self):
doc = string_document(just_md())
yml_contents, md_contents = yamldown._load(doc)

expected_yml = {}

self.assertEqual(yml_contents, expected_yml)

class TestDump(unittest.TestCase):

def test_dump_yaml_first(self):
Expand Down
2 changes: 1 addition & 1 deletion yamldown/yamldown.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _load(stream: IO[str]) -> Tuple[Dict, str]:

current_buffer.append(line)

yml_dict = yaml.load(yml_contents.contents, Loader=yaml.FullLoader) # type: Dict
yml_dict = yaml.load(yml_contents.contents, Loader=yaml.FullLoader) or {} # type: Dict
return (yml_dict, md_contents.contents.strip("\n"))

def _is_yaml_start(line: str, yml_buffer: Buffer) -> bool:
Expand Down