Skip to content

Commit

Permalink
0.1.1 Final Release
Browse files Browse the repository at this point in the history
- Upgraded to MyCapytain 1.0.4
- Fixed bug where Work or Textgroup would be None
- Fixed bug where missing `@urn` attribute would raise AttributeError
- Added Tests
  • Loading branch information
PonteIneptique committed Dec 20, 2016
1 parent 09284b9 commit c0d6233
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: python
python:
- "3.4"
- "3.4.5"
- "3.5"
# command to install dependencies
install:
- pip install -r requirements.txt
Expand Down
21 changes: 15 additions & 6 deletions HookTest/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import MyCapytain.resources.texts.local
import MyCapytain.resources.inventory
import MyCapytain.common.reference
import MyCapytain.common.utils
import MyCapytain.errors
import pkg_resources
import subprocess
Expand Down Expand Up @@ -159,17 +160,26 @@ def capitain(self):
if textgroup:
self.type = "textgroup"
self.log("TextGroup detected")
self.Text = MyCapytain.resources.inventory.TextGroup(resource=self.xml.getroot())
Trait = MyCapytain.resources.inventory.TextGroup
elif work:
self.type = "work"
self.log("Work detected")
self.Text = MyCapytain.resources.inventory.Work(resource=self.xml.getroot())
Trait = MyCapytain.resources.inventory.Work
else:
self.log("No metadata type detected (neither work nor textgroup)")
self.log("Inventory can't be read through Capitains standards")
yield False

if self.Text:
if self.type in ["textgroup", "work"]:
try:
self.Text = Trait(resource=self.xml.getroot())
except AttributeError as E:
self.log("Missing URN attribute")
self.error(E)
except Exception as E:
self.error(E)

if self.Text is not False:
yield True
else:
yield False
Expand All @@ -178,10 +188,9 @@ def metadata(self):
""" Check the presence of all metadata
"""
status = False
if self.xml is not None and self.Text:
if self.xml is not None and self.Text is not False:

if self.type == "textgroup":

groups = len(self.Text.metadata["groupname"].children)
self.log("{0} groupname found".format(str(groups)))
status = groups > 0
Expand Down Expand Up @@ -332,7 +341,7 @@ def test(self):
:returns: List of urns
:rtype: list.<str>
"""
self.urns = []

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MyCapytain==1.0.1
MyCapytain==1.0.4
jingtrang==0.1.1
GitPython==1.0.1
requests>=2.8.1
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
license='MIT',
packages=find_packages(exclude=("tests")),
install_requires=[
"MyCapytain==1.0.3",
"MyCapytain==1.0.4",
"jingtrang==0.1.1",
"GitPython==1.0.1",
"requests>=2.7.0"
Expand Down
49 changes: 47 additions & 2 deletions tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TestCTS(unittest.TestCase):
def test_lang(self):
""" Test lang in translation check
"""
success = """<work xmlns="http://chs.harvard.edu/xmlns/cts" xml:lang="far">
success = """<work xmlns="http://chs.harvard.edu/xmlns/cts" xml:lang="far" urn="urn:cts:farsiLit:hafez.divan">
<title xml:lang="eng">Div&#257;n</title>
<edition urn="urn:cts:farsiLit:hafez.divan.perseus-far1" workUrn="urn:cts:farsiLit:hafez.divan">
<label xml:lang="eng">Divan</label>
Expand All @@ -25,7 +25,7 @@ def test_lang(self):
<description xml:lang="eng">as</description>
</translation>
</work>"""
fail = """<work xmlns="http://chs.harvard.edu/xmlns/cts">
fail = """<work xmlns="http://chs.harvard.edu/xmlns/cts" urn="urn:cts:farsiLit:hafez.divan">
<title xml:lang="eng">Div&#257;n</title>
<edition urn="urn:cts:farsiLit:hafez.divan.perseus-far1" workUrn="urn:cts:farsiLit:hafez.divan">
<label xml:lang="eng">Divan</label>
Expand Down Expand Up @@ -55,6 +55,51 @@ def test_lang(self):
self.assertEqual(unit.metadata().__next__(), False, "When lang fails, test should fail")
self.assertIn(">>>>>> Translation(s) are missing lang attribute", unit.logs)

def test_miss_urn_parse(self):
""" Test lang in translation check
"""
fail = """<work xmlns="http://chs.harvard.edu/xmlns/cts">
<title xml:lang="eng">Div&#257;n</title>
<edition urn="urn:cts:farsiLit:hafez.divan.perseus-far1" workUrn="urn:cts:farsiLit:hafez.divan">
<label xml:lang="eng">Divan</label>
<description xml:lang="eng">as</description>
</edition>
<translation xml:lang="eng" urn="urn:cts:farsiLit:hafez.divan.perseus-eng1" workUrn="urn:cts:farsiLit:hafez.divan">
<label xml:lang="eng">Divan</label>
<description xml:lang="eng">as</description>
</translation>
<translation urn="urn:cts:farsiLit:hafez.divan.perseus-ger1" workUrn="urn:cts:farsiLit:hafez.divan">
<label xml:lang="eng">Divan</label>
<description xml:lang="eng">as</description>
</translation>
</work>"""
unit = HookTest.units.INVUnit("/a/b")
unit.xml = etree.ElementTree(etree.fromstring(fail))
self.assertEqual(
list(unit.capitain()), [False],
"Parsing should fail but not raise"
)
print(unit.logs)

def test_capitains_parse(self):
unit = HookTest.units.INVUnit("./tests/repo2/data/wrongmetadata/__cts__.xml")
self.assertEqual(
list(unit.parsable()) + list(unit.capitain()), [True, True],
"Parsing should work"
)

def test_capitains_metadatatextgroup(self):
unit = HookTest.units.INVUnit("./tests/repo2/data/wrongmetadata/__cts__.xml")
self.assertEqual(
list(unit.parsable()) + list(unit.capitain()) + list(unit.metadata()), [True, True, False],
"No lang in groupname should fail"
)
unit = HookTest.units.INVUnit("./tests/repo2/data/tlg2255/__cts__.xml")
self.assertEqual(
list(unit.parsable()) + list(unit.capitain()) + list(unit.metadata()), [True, True, True],
"Lang in groupname should fail"
)


class TestText(unittest.TestCase):
""" Test the UnitTests for Text
Expand Down

0 comments on commit c0d6233

Please sign in to comment.