-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #111 : Covering xml:lang on /text
- Loading branch information
1 parent
db9c094
commit c861ccb
Showing
6 changed files
with
144 additions
and
20 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
Empty file.
Empty file.
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,80 @@ | ||
from MyCapytain.common.utils import xmlparser | ||
from lxml.etree import tostring | ||
|
||
TEMPLATES = """<TEI xmlns="http://www.tei-c.org/ns/1.0"> | ||
<teiHeader> | ||
<encodingDesc> | ||
<refsDecl n="CTS"> | ||
<cRefPattern n="chapter" matchPattern="(.+).(.+)" replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div[@type='edition']/tei:div[@n='$1']/tei:div[@n='$2'])"/> | ||
<cRefPattern n="book" matchPattern="(.+)" replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div[@type='edition']/tei:div[@n='$1'])"/> | ||
</refsDecl> | ||
</encodingDesc> | ||
</teiHeader> | ||
<text><body><div></div></body></text> | ||
</TEI>""" | ||
URN = "urn:cts:latinLit:phi1294.phi002.perseus-lat2" | ||
LANG = "lat" | ||
|
||
# The following variable is a list of element with error that they should throw and status (XML_OBJECT, STATUS, ERROR) | ||
XMLLANG_DOCUMENTS = [ | ||
("tei", "<text>", "<text xml:base='{urn}' xml:lang='{lang}'>", True, "TEI works with urn and xml lang on @base/text"), | ||
("tei", "<text>", "<text n='{urn}' xml:lang='{lang}'>", False, "TEI fails with urn and xml lang on @n/text"), | ||
("tei", "<text>", "<text xml:base='{urn}'>", False, "TEI fails with urn without xml lang on @base/text"), | ||
("tei", "<text>", "<text n='{urn}'>", False, "TEI fails with urn without xml lang on @n/text"), | ||
|
||
("epidoc", "<text>", "<text xml:base='{urn}' xml:lang='{lang}'>", False, "Epidoc fails with urn and xml lang on @base/text"), | ||
("epidoc", "<text>", "<text n='{urn}' xml:lang='{lang}'>", False, "Epidoc fails with urn and xml lang on @n/text"), | ||
("epidoc", "<text>", "<text xml:base='{urn}'>", False, "Epidoc fails with urn without xml lang on @base/text"), | ||
("epidoc", "<text>", "<text n='{urn}'>", False, "Epidoc fails with urn without xml lang on @n/text"), | ||
|
||
("tei", "<body>", "<body xml:base='{urn}' xml:lang='{lang}'>", False, "TEI fails with urn and xml lang on @base/body"), | ||
("tei", "<body>", "<body n='{urn}' xml:lang='{lang}'>", True, "TEI works with urn and xml lang on @n/body"), | ||
("tei", "<body>", "<body xml:base='{urn}'>", False, "TEI fails with urn without xml lang on @base/body"), | ||
("tei", "<body>", "<body n='{urn}'>", False, "TEI fails with urn without xml lang on @n/body"), | ||
|
||
("epidoc", "<body>", "<body xml:base='{urn}' xml:lang='{lang}'>", False, "Epidoc fails with urn and xml lang on @base/body"), | ||
("epidoc", "<body>", "<body n='{urn}' xml:lang='{lang}'>", False, "Epidoc fails with urn and xml lang on @n/body"), | ||
("epidoc", "<body>", "<body xml:base='{urn}'>", False, "Epidoc fails with urn without xml lang on @base/body"), | ||
("epidoc", "<body>", "<body n='{urn}'>", False, "Epidoc fails with urn without xml lang on @n/body"), | ||
|
||
] | ||
# Epidocs Tests | ||
XMLLANG_DOCUMENTS += [ | ||
(scheme, source, replacement.replace("{epidoc}", type_epidoc), boolean, message.replace("{epidoc}", type_epidoc)) | ||
for scheme, source, replacement, boolean, message in | ||
[ | ||
("tei", "<div>", "<div type='{epidoc}' n='{urn}' xml:lang='{lang}'>", False, | ||
"TEI fails with urn and xml lang on @n/div-{epidoc}"), | ||
|
||
("tei", "<div>", "<div type='{epidoc}' xml:base='{urn}' xml:lang='{lang}'>", False, | ||
"TEI fails with urn and xml lang on @xml:base/div-{epidoc}"), | ||
|
||
("tei", "<div>", "<div type='{epidoc}' xml:base='{urn}' xml:lang='{lang}'>", False, | ||
"TEI fails with urn and without xml lang on @n/div-{epidoc}"), | ||
|
||
("tei", "<div>", "<div type='{epidoc}' n='{urn}' xml:lang='{lang}'>", False, | ||
"TEI fails with urn and without xml lang on @xml:base/div-{epidoc}"), | ||
|
||
("epidoc", "<div>", "<div type='{epidoc}' n='{urn}' xml:lang='{lang}'>", True, | ||
"Epidoc works with urn and xml lang on @n/div-{epidoc}"), | ||
|
||
("epidoc", "<div>", "<div type='{epidoc}' xml:base='{urn}' xml:lang='{lang}'>", False, | ||
"Epidoc fails with urn and xml lang on @xml:base/div-{epidoc}"), | ||
|
||
("epidoc", "<div>", "<div type='{epidoc}' xml:base='{urn}'>", False, | ||
"Epidoc fails with urn and without xml lang on @n/div-{epidoc}"), | ||
|
||
("epidoc", "<div>", "<div type='{epidoc}' n='{urn}'>", False, | ||
"Epidoc fails with urn and without xml lang on @xml:base/div-{epidoc}") | ||
] | ||
for type_epidoc in ["edition", "translation", "commentary"] | ||
] | ||
XMLLANG_DOCUMENTS = [ | ||
( | ||
scheme, | ||
tostring(xmlparser(TEMPLATES.replace(source, replacement).format(urn=URN, lang=LANG)), encoding=str), | ||
boolean, | ||
msg + " ("+replacement.format(urn=URN, lang=LANG)+")" | ||
) | ||
for scheme, source, replacement, boolean, msg in XMLLANG_DOCUMENTS | ||
] |
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,41 @@ | ||
import unittest | ||
import HookTest.capitains_units.cts | ||
import HookTest.units | ||
import tests.test_cts.mocks.xmllang_data as CAPITAINS_MOCKS | ||
from lxml import etree | ||
|
||
class TestCTS(unittest.TestCase): | ||
""" Test the UnitTest for __cts__ | ||
""" | ||
pass | ||
|
||
|
||
class TestText(unittest.TestCase): | ||
""" Test the UnitTests for Text | ||
""" | ||
|
||
def setUp(self): | ||
self.backup = [x for x in HookTest.capitains_units.cts.CTSText_TestUnit.tests] | ||
|
||
def tearDown(self): | ||
HookTest.capitains_units.cts.CTSText_TestUnit.tests = self.backup | ||
|
||
def unit_from_string(self, xml_string, scheme): | ||
""" Generates a test unit based on xml_string and scheme | ||
:param xml_string: String representation of the XML Document | ||
:param scheme: Scheme to apply | ||
:return: HookTest.capitains_units.cts.CTSText_TestUnit | ||
""" | ||
node = HookTest.capitains_units.cts.CTSText_TestUnit("/false/path") | ||
node.scheme = scheme | ||
node.xml = etree.fromstring(xml_string, HookTest.units.TESTUnit.PARSER) | ||
return node | ||
|
||
def test_xml_lang(self): | ||
""" Ensure the XML:LANG test checks against the guideline | ||
""" | ||
for scheme, xml, status, message in CAPITAINS_MOCKS.XMLLANG_DOCUMENTS: | ||
unit = self.unit_from_string(xml, scheme) | ||
results = [result for result in unit.language()] | ||
self.assertEqual(results[0], status, message) |