-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: complements build article element (#763)
* Adiciona 'docstring' e elementos filhos * Complementa testes * Adiciona parâmetro 'nodes' * Atualiza testes
- Loading branch information
1 parent
306b3b8
commit fd48eb2
Showing
2 changed files
with
91 additions
and
26 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 |
---|---|---|
@@ -1,46 +1,63 @@ | ||
import unittest | ||
from xml.etree.ElementTree import Element | ||
import xml.etree.ElementTree as ET | ||
|
||
|
||
from packtools.sps.formats.sps_xml.article import build_article_node | ||
|
||
|
||
class TestBuildArticleNode(unittest.TestCase): | ||
def test_build_article_node(self): | ||
article_node = build_article_node( | ||
article_data={ | ||
article = build_article_node( | ||
data={ | ||
'dtd-version': '1.1', | ||
'specific-use': 'sps-1.8', | ||
'article-type': 'research-article', | ||
'xml:lang': 'pt' | ||
} | ||
}, | ||
nodes=[ | ||
ET.fromstring('<front />'), | ||
ET.fromstring('<body />'), | ||
ET.fromstring('<back />'), | ||
ET.fromstring('<sub-article />') | ||
] | ||
) | ||
|
||
self.assertIsInstance(article_node, Element) | ||
|
||
self.assertEqual(article_node.tag, 'article') | ||
|
||
expected_attributes = { | ||
'xmlns:xlink': 'http://www.w3.org/1999/xlink', | ||
'xmlns:mml': 'http://www.w3.org/1998/Math/MathML', | ||
'dtd-version': '1.1', | ||
'specific-use': 'sps-1.8', | ||
'article-type': 'research-article', | ||
'xml:lang': 'pt' | ||
} | ||
|
||
self.assertDictEqual(article_node.attrib, expected_attributes) | ||
expected_xml_str = ( | ||
'<article xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mml="http://www.w3.org/1998/Math/MathML" ' | ||
'dtd-version="1.1" specific-use="sps-1.8" article-type="research-article" xml:lang="pt">' | ||
'<front />' | ||
'<body />' | ||
'<back />' | ||
'<sub-article />' | ||
'</article>' | ||
) | ||
generated_xml_str = ET.tostring(article, encoding="unicode", method="xml") | ||
self.assertEqual(generated_xml_str.strip(), expected_xml_str.strip()) | ||
|
||
def test_build_article_node_error(self): | ||
def test_build_article_node_error_attribs(self): | ||
with self.assertRaises(KeyError) as e: | ||
build_article_node( | ||
article_data={ | ||
data={ | ||
'specific-use': 'sps-1.8', | ||
'article-type': 'research-article', | ||
'xml:lang': 'pt' | ||
} | ||
}, | ||
nodes=None | ||
) | ||
self.assertEqual(str(e.exception), '"\'dtd-version\' is required"') | ||
|
||
def test_build_article_node_error_children(self): | ||
with self.assertRaises(ValueError) as e: | ||
build_article_node( | ||
data={ | ||
'dtd-version': '1.1', | ||
'specific-use': 'sps-1.8', | ||
'article-type': 'research-article', | ||
'xml:lang': 'pt', | ||
}, | ||
nodes=None | ||
) | ||
self.assertEqual(str(e.exception), "A list of children nodes is required") | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |