-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port test_docparser.py to pytest. Use pytest for running tests.
- Loading branch information
Showing
6 changed files
with
50 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# -*- coding: utf-8 -*- | ||
from pathlib import Path | ||
|
||
from logya.docparser import parse | ||
|
||
|
||
def content_type(path): | ||
if path.suffix in ['.html', '.htm']: | ||
return 'html' | ||
if path.suffix in ['.md', '.markdown']: | ||
return 'markdown' | ||
|
||
|
||
def read(filename): | ||
path = Path(filename) | ||
content = path.read_text().strip() | ||
try: | ||
return parse(content, content_type=content_type(path)) | ||
except Exception as err: | ||
print(f'Error parsing: {filename}\n{err}') | ||
# TODO add url, created and updated attrs if not set | ||
|
||
|
||
def write(filename, doc): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
url: /test/markdown/ | ||
--- | ||
* [Link](/url/) | ||
* [Link with attributes](/url/){: class="foo bar" title="Some title!" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
from logya.content import read, write | ||
|
||
|
||
def test_read_markdown(): | ||
doc = read('tests/fixtures/site/content/markdown.md') | ||
assert isinstance(doc, dict) | ||
assert '/test/markdown/' == doc['url'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
|
||
from logya.docparser import parse | ||
|
||
import tests.fixtures.docs as docs | ||
|
||
|
||
class TestDocParser(unittest.TestCase): | ||
def test_parse_markdown_link(): | ||
doc = parse(docs.markdown_link, content_type='markdown') | ||
assert '<a href="/url/">Link</a>' in doc['body'] | ||
|
||
def test_markdown_link(self): | ||
parsed = parse(docs.markdown_link, content_type='markdown') | ||
self.assertIn( | ||
'<a href="/sample/link/">Sample Link</a>', parsed.get('body')) | ||
|
||
def test_markdown_attr_list(self): | ||
parsed = parse(docs.markdown_attr_list, content_type='markdown') | ||
self.assertIn( | ||
'<a class="foo bar" href="/sample/link/" title="Some title!">Sample Link</a>', parsed.get('body')) | ||
def test_parse_markdown_attrs(): | ||
doc = parse(docs.markdown_attrs, content_type='markdown') | ||
assert '<a class="foo bar" href="/url/" title="Some title!">Link with attributes</a>' in doc['body'] |