Skip to content
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
1 change: 0 additions & 1 deletion frontmatter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ def load(
else:
raise ValueError(f"Cannot open filename using type {type(fd)}")

handler = handler or detect_format(text, handlers)
return loads(text, encoding, handler, **defaults)


Expand Down
23 changes: 23 additions & 0 deletions tests/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

import os
from io import BytesIO, StringIO
import shutil
import tempfile
import textwrap
Expand All @@ -27,6 +28,28 @@ class FrontmatterTest(unittest.TestCase):

maxDiff = None

def test_load_binary_stream(self):
text = "---\ntitle: Café\n---\nBonjour"
for encoding in ("utf-8", "utf-16"):
with self.subTest(encoding=encoding):
post = frontmatter.load(BytesIO(text.encode(encoding)), encoding=encoding)
self.assertEqual(post.metadata, {"title": "Café"})
self.assertEqual(post.content, "Bonjour")
self.assertIsInstance(post.handler, YAMLHandler)

post = frontmatter.load(StringIO(text))
self.assertEqual(post.metadata, {"title": "Café"})
self.assertEqual(post.content, "Bonjour")

def test_load_binary_file(self):
with tempfile.TemporaryFile("w+b") as stream:
stream.write(b'{\n"title": "Hello"\n}\nBody')
stream.seek(0)
post = frontmatter.load(stream, author="Ada")
self.assertEqual(post.metadata, {"title": "Hello", "author": "Ada"})
self.assertEqual(post.content, "Body")
self.assertIsInstance(post.handler, JSONHandler)

def test_with_markdown_content(self):
"Parse frontmatter and only the frontmatter"
post = frontmatter.load("tests/yaml/hello-markdown.md")
Expand Down