Skip to content
Permalink
Browse files
run tests for metadata extraction again
  • Loading branch information
ralsina committed Jul 20, 2015
1 parent 94e695d commit 378ae40e7e0826a2741f7a6b7d2d176ed20a2ce6
Showing with 25 additions and 25 deletions.
  1. +11 −24 nikola/post.py
  2. +1 −1 setup.py
  3. +13 −0 tests/test_utils.py
@@ -836,36 +836,23 @@ def get_metadata_from_file(source_path, config=None, lang=None):


def _get_metadata_from_file(meta_data):
"""Parse file contents and obtain metadata.
>>> g = _get_metadata_from_file
>>> list(g([]).values())
[]
>>> str(g(["======","FooBar","======"])["title"])
'FooBar'
>>> str(g(["FooBar","======"])["title"])
'FooBar'
>>> str(g(["#FooBar"])["title"])
'FooBar'
>>> str(g([".. title: FooBar"])["title"])
'FooBar'
>>> 'title' in g(["","",".. title: FooBar"])
False
>>> 'title' in g(["",".. title: FooBar"]) # for #520
True
>>> 'title' in g([".. foo: bar","","FooBar", "------"]) # for #1895
True
>>> 1 == 0
True
"""
Extract metadata from a post's source file.
"""
meta = {}
if not meta_data:
return meta

re_md_title = re.compile(r'^{0}([^{0}].*)'.format(re.escape('#')))
# Assuming rst titles are going to be at least 4 chars long
# otherwise this detects things like ''' wich breaks other markups.
re_rst_title = re.compile(r'^([{0}]{{4,}})'.format(re.escape(
string.punctuation)))

# Skip up to one empty line at the beginning (for txt2tags)

if not meta_data[0]:
meta_data = meta_data[1:]

meta = {}

# First, get metadata from the beginning of the file,
# up to first empty line
@@ -14,7 +14,7 @@
class PyTest(TestCommand):
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = ['--doctest-modules']
self.test_args = []
self.test_suite = True

def run_tests(self):
@@ -322,5 +322,18 @@ def test_dict_input_lang(self):
self.assertEqual(inp['zz'], cn)


def test_get_metadata_from_file():
# These were doctests and not running :-P
from nikola.post import _get_metadata_from_file
g = _get_metadata_from_file
assert list(g([]).values()) == []
assert str(g(["======","FooBar","======"])["title"]) == 'FooBar'
assert str(g(["FooBar","======"])["title"]) == 'FooBar'
assert str(g(["#FooBar"])["title"]) == 'FooBar'
assert str(g([".. title: FooBar"])["title"]) == 'FooBar'
assert 'title' not in g(["","",".. title: FooBar"])
assert 'title' in g(["",".. title: FooBar"])
assert 'title' in g([".. foo: bar","","FooBar", "------"])

if __name__ == '__main__':
unittest.main()

0 comments on commit 378ae40

Please sign in to comment.