-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
118 additions
and
5 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
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,90 @@ | ||
import unittest | ||
import datetime | ||
from docdata import yamldata | ||
|
||
class TestYamlData(unittest.TestCase): | ||
def test_yaml_data(self): | ||
doc = '''--- | ||
Author: John Doe | ||
Date: 2015-05-08 14:15:16 | ||
Integer: 0x2A | ||
--- | ||
Document content. | ||
''' | ||
self.assertEqual( | ||
yamldata.get_data(doc), | ||
( | ||
'Document content.\n', | ||
{ | ||
'Author': 'John Doe', | ||
'Date': datetime.datetime(2015, 5, 8, 14, 15, 16), | ||
'Integer': 42 | ||
} | ||
) | ||
) | ||
|
||
def test_end_deliminator(self): | ||
doc = '''--- | ||
Author: John Doe | ||
Date: 2015-05-08 | ||
Integer: 42 | ||
... | ||
Document content. | ||
''' | ||
self.assertEqual( | ||
yamldata.get_data(doc), | ||
( | ||
'Document content.\n', | ||
{ | ||
'Author': 'John Doe', | ||
'Date': datetime.date(2015, 5, 8), | ||
'Integer': 42 | ||
} | ||
) | ||
) | ||
|
||
def test_bad_deliminator(self): | ||
doc = '''--- | ||
Author: John Doe | ||
Date: 2015-05-08 | ||
Integer: 42 | ||
-.- | ||
Document content. | ||
''' | ||
self.assertEqual( | ||
yamldata.get_data(doc), | ||
(doc, {}) | ||
) | ||
|
||
def test_blank_first_line(self): | ||
doc = ''' | ||
--- | ||
Author: John Doe | ||
Date: 2015-05-08 | ||
Integer: 42 | ||
--- | ||
Document content. | ||
''' | ||
self.assertEqual( | ||
yamldata.get_data(doc), | ||
(doc, {}) | ||
) | ||
|
||
def test_bad_yaml(self): | ||
doc = '''--- | ||
foo | ||
... | ||
Document content. | ||
''' | ||
self.assertEqual( | ||
yamldata.get_data(doc), | ||
(doc, {}) | ||
) | ||
|
||
def test_no_yaml(self): | ||
doc = 'Document content.' | ||
self.assertEqual( | ||
yamldata.get_data(doc), | ||
(doc, {}) | ||
) |