Skip to content

Commit

Permalink
Changes to comply with MyCapytain 2.0.8 (#126)
Browse files Browse the repository at this point in the history
* Changes to comply with MyCapytain 2.0.8
With unit test updates
* Updated CHANGES.md and bumped version number
  • Loading branch information
sonofmun authored and PonteIneptique committed Jun 26, 2018
1 parent 3c8e1b4 commit b1c4b0f
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 33 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.1.9 - 2018-06-26

- Added tests for new EmptyRefsDecl exception
- Edited several tests and unit tests to deal with this new exception

## 1.1.8 - 2018-06-25

- Removed legacy functions
Expand Down
11 changes: 9 additions & 2 deletions HookTest/capitains_units/cts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import MyCapytain.common
from MyCapytain.common.constants import Mimetypes
from MyCapytain.errors import DuplicateReference, EmptyReference
from MyCapytain.errors import DuplicateReference, EmptyReference, MissingRefsDecl
from MyCapytain.resources.collections.cts import XmlCtsTextgroupMetadata, XmlCtsWorkMetadata
from MyCapytain.resources.texts.local.capitains.cts import CapitainsCtsText

Expand Down Expand Up @@ -339,6 +339,7 @@ def __init__(self, path, countwords=False, timeout=30, *args, **kwargs):
self.duplicates = list()
self.forbiddens = list()
self.empties = list()
self.capitains_errors = list()
self.test_status = defaultdict(bool)
self.lang = ''
self.dtd_errors = list()
Expand All @@ -353,7 +354,13 @@ def parsable(self):
super(CTSText_TestUnit, self).parsable()
)
if status is True:
self.Text = CapitainsCtsText(resource=self.xml.getroot())
try:
self.Text = CapitainsCtsText(resource=self.xml.getroot())
except MissingRefsDecl as E:
self.Text = None
self.log(str(E))
self.capitains_errors.append(str(E))
yield False
else:
self.Text = None
yield status
Expand Down
25 changes: 22 additions & 3 deletions HookTest/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ def unit(self, filepath):
additional["forbiddens"] = unit.forbiddens
additional["dtd_errors"] = unit.dtd_errors
additional['language'] = unit.lang
additional['empties'] = unit.empties
additional['capitains_errors'] = unit.capitains_errors
if self.countwords:
additional["words"] = unit.count
return self.cover(filepath, results, testtype=texttype, logs=logs, additional=additional), filepath, additional
Expand Down Expand Up @@ -498,6 +500,8 @@ def end(self):
duplicate_nodes = ''
forbidden_chars = ''
dtd_errors = ''
capitains_errors = ''
empty_refs = ''
num_texts = 0
num_failed = 0
print('', flush=True)
Expand Down Expand Up @@ -542,6 +546,14 @@ def end(self):
dtd_errors += '\t{name}\t{nodes}\n'.format(name=magenta(os.path.basename(unit.name)),
nodes=', '.join(unit.additional["dtd_errors"]))

if unit.additional["capitains_errors"]:
capitains_errors += '\t{name}\t{nodes}\n'.format(name=magenta(os.path.basename(unit.name)),
nodes=', '.join(unit.additional["capitains_errors"]))

if unit.additional["empties"]:
empty_refs += '\t{name}\t{nodes}\n'.format(name=magenta(os.path.basename(unit.name)),
nodes=', '.join(unit.additional["empties"]))

if self.verbose >= 7 or unit.status is False:
if self.countwords:
row = [
Expand Down Expand Up @@ -575,12 +587,19 @@ def end(self):
forbidden_chars = magenta('Forbidden characters found:\n') + forbidden_chars + '\n'
if dtd_errors:
dtd_errors = magenta('DTD errors found:\n') + dtd_errors + '\n'
if empty_refs:
empty_refs = magenta('Empty references found:\n') + empty_refs + '\n'
else:
duplicate_nodes = forbidden_chars = dtd_errors = ''

print("{dupes}{forbs}{dtds}>>> End of the test !\n".format(dupes=duplicate_nodes,
forbs=forbidden_chars,
dtds=dtd_errors))
if capitains_errors:
capitains_errors = magenta('CapiTainS parsing errors found:\n') + capitains_errors + '\n'

print("{caps}{dupes}{forbs}{dtds}{empts}>>> End of the test !\n".format(caps=capitains_errors,
dupes=duplicate_nodes,
forbs=forbidden_chars,
dtds=dtd_errors,
empts=empty_refs))
t_pass = num_texts - num_failed
cov = round(statistics.mean([test.coverage for test in self.results.values()]), ndigits=2)
results_table = PT(["HookTestResults", ""])
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name='HookTest',
version="1.1.8",
version="1.1.9",
description='Hook Test Script for GitHub/CapiTainS repositories',
long_description=long_description,
url='http://github.com/Capitains/HookTest',
Expand Down
85 changes: 85 additions & 0 deletions tests/repo2/data/tlg2255/perseus001/refsDecl_no_targets.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml-model href="http://www.stoa.org/epidoc/schema/latest/tei-epidoc.rng" schematypens="http://relaxng.org/ns/structure/1.0"?><TEI xmlns="http://www.tei-c.org/ns/1.0"><teiHeader><fileDesc>
<titleStmt>
<title>Encomium of Helen</title>
<author>Gorgias</author>
<editor role="editor">Friedrich Blass</editor>
</titleStmt>
<publicationStmt><publisher>Trustees of Tufts University</publisher><pubPlace>Medford, MA</pubPlace><authority>Perseus Project</authority></publicationStmt>
<sourceDesc>
<biblStruct>
<monogr>
<title>ΕΛΕΝΗΣ ΕΓΚΩΜΙΟΝ</title>
<author>ΓΟΡΓΙΟΥ</author>
<editor role="editor">Friedrich Blass</editor>
<imprint>
<publisher>Teubner</publisher>
<pubPlace>Leipzig</pubPlace>
<date>1908</date>
</imprint>
</monogr>
</biblStruct>

</sourceDesc>
</fileDesc><encodingDesc>
<refsDecl n="CTS">
<cRefPattern n="section" matchPattern="(.+)" replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div[@type='edition']/tei:p/tei:div[@n='$1'])"/>
</refsDecl>

</encodingDesc><profileDesc>
<langUsage>
<language ident="grc">Greek</language>
</langUsage>
</profileDesc>

<revisionDesc>
<change who="Thibault Clerice" when="2016-05-17">Changed refsDecl, added seg element for capitains scheme, added del to reflect [spurious text]</change>
</revisionDesc>
</teiHeader>

<text><body> <div type="edition" n="urn:cts:greekLit:tlg2255.perseus001.perseus-grc1" xml:lang="grc">
<pb ed="alt" n="p. 91 R."/> <head>ΓΟΡΓΙΟΥ ΕΛΕΝΗΣ ΕΓΚΩΜΙΟΝ.</head>
<p><seg n="1"><milestone unit="section" n="1"/> Κόσμος πόλει μὲν εὐανδρία, σώματι δὲ κάλλος,
<pb ed="alt" n="679"/> ψυχῇ δὲ σοφία, πράγματι δὲ ἀρετή, λόγῳ δὲ ἀλήθεια·

<pb xml:id="v.3.p.151"/>

τὰ δ᾿ ἐναντία τούτων ἀκοσμία. ἄνδρα δὲ καὶ γυναῖκα
καὶ λόγον καὶ ἔργον καὶ πόλιν καὶ πρᾶγμα χρὴ τὸ μὲν
<pb ed="alt" n="680"/> ἄξιον ἐπαίνου ἐπαίνῳ τιμᾶν, τῷ δὲ ἀναξίῳ μῶμον
ἐπιτιθέναι· ἴση γὰρ ἁμαρτία καὶ ἀμαθία μέμφεσθαί τε
τὰ ἐπαινετὰ καὶ ἐπαινεῖν τὰ μωμητά.</seg> <milestone unit="section" n="2"/><seg n="2">τοῦ δ᾿ αὐτοῦ
ἀνδρὸς λέξαι τε τὸ δέον ὀρθῶς καὶ ἐλέγξαι . . . . . .

<add>ἐλέγξαι</add> τοὺς μεμφομένους Ἑλένην, γυναῖκα περὶ ἧς
ὁμόφωνος καὶ ὁμόψηφος γέγονεν ἥ τε τῶν ποιητῶν
. . . . <add>ἥ τε τῶν</add> ἀκουσάντων πίστις, ἥ τε τοῦ ὀνόματος
φήμη τῶν συμφορῶν μνήμη γέγονεν. ἐγὼ δὲ βούλομαι
λογισμόν τινα τῷ λόγῳ δοὺς τὴν μὲν κακῶς
ἀκούουσαν παῦσαι τῆς αἰτίας, τοὺς δὲ μεμφομένους
ψευδομένους ἐπιδείξας καὶ δείξας τἀληθὲς παῦσαι τῆς
ἀμαθίας.</seg></p>
<p><milestone unit="section" n="3"/><seg n="3">Ὅτι μὲν οὖν φύσει καὶ γένει τὰ πρῶτα τῶν πρώτων
ἀνδρῶν καὶ γυναικῶν ἡ γυνὴ περὶ ἧς ὅδε ὁ λόγος,
<pb xml:id="v.3.p.152"/>

οὐκ ἄδηλον οὐδ᾿ ὀλίγοις. δῆλον γὰρ ὡς μητρὸς μὲν
Λήδας, πατρὸς δὲ τοῦ μὲν γενομένου θεοῦ, λεγομένου
δὲ θνητοῦ, Τυνδάρεω καὶ Διός, ὧν ὁ μὲν διὰ τὸ εἶναι
ἔδοξεν, ὁ δὲ διὰ τὸ φάναι ἐλέχθη, καὶ ἦν ὁ μὲν
ἀνδρῶν κράτιστος, ὁ δὲ πάντων τύραννος.</seg> <milestone unit="section" n="4"/><seg n="4">ἐκ τοιούτων
δὲ γενομένη ἔσχε τὸ ἰσόθεον κάλλος, ὃ λαβοῦσα
[καὶ] οὐ λαθοῦσα ἔσχε, πλείστας δὲ πλείστοις ἐπιθυμίας
ἔρωτος ἐνειργάσατο, ἑνὶ δὲ σώματι πολλὰ σώματα
συνήγαγεν ἀνδρῶν ἐπὶ μεγάλοις μεγάλα φρονούντων,
ὧν οἱ μὲν πλούτου μεγέθη, οἱ δὲ εὐγενείας παλαιᾶς
εὐδοξίαν, οἱ δὲ ἀλκῆς οἰκείας εὐεξίαν, οἱ δὲ σοφίας
ἐπικτήτου δύναμιν ἔσχον, καὶ ἧκον ἅπαντες ὑπ᾿ ἔρωτός
τε φιλονίκου φιλοτιμίας τε ἀνικήτου. </seg><milestone unit="section" n="5"/><seg n="5">ὅστις μὲν
οὖν καὶ δι᾿ ὅ τι καὶ ὅπως ἀπέπλησε τὸν ἔρωτα τὴν
Ἑλένην λαβών, οὐ λέξω· τὸ γὰρ τοῖς εἰδόσιν ἃ ἴσασι
λέγειν πίστιν μὲν ἔχει, τέρψιν δὲ οὐ φέρει. τὸν χρόνον
δὲ τῷ λόγῳ τὸν τότε <add>τῷ</add> νῦν ὑπερβὰς ἐπὶ τὴν
ἀρχὴν τοῦ μέλλοντος λόγου προβήσομαι, καὶ προθήσομαι
τὰς αἰτίας δι᾿ ἃς εἰκὸς ἦν γενέσθαι τὸν τῆς Ἑλένης
εἰς τὴν Τροίαν στόλον.</seg></p>
</div></body></text></TEI>
5 changes: 3 additions & 2 deletions tests/repotei/data/tei/tei/tei.tei.tei.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
</biblStruct>

</sourceDesc>
</fileDesc><encodingDesc>

</fileDesc><encodingDesc><refsDecl n="CTS">
<cRefPattern n="section" matchPattern="(.+)" replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div[@type='edition']/tei:p/tei:seg[@n='$1'])"/>
</refsDecl>
</encodingDesc><profileDesc>
<langUsage>
<language ident="grc">Greek</language>
Expand Down
20 changes: 3 additions & 17 deletions tests/repotei/data/tei/tei/tei.tei.weirdurn.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,9 @@
<editor role="editor">Friedrich Blass</editor>
</titleStmt>
<publicationStmt><publisher>Trustees of Tufts University</publisher><pubPlace>Medford, MA</pubPlace><authority>Perseus Project</authority></publicationStmt>
<sourceDesc>
<biblStruct>
<monogr>
<title>ΕΛΕΝΗΣ ΕΓΚΩΜΙΟΝ</title>
<author>ΓΟΡΓΙΟΥ</author>
<editor role="editor">Friedrich Blass</editor>
<imprint>
<publisher>Teubner</publisher>
<pubPlace>Leipzig</pubPlace>
<date>1908</date>
</imprint>
</monogr>
</biblStruct>

</sourceDesc>
</fileDesc><encodingDesc>

</fileDesc><encodingDesc><refsDecl n="CTS">
<cRefPattern n="section" matchPattern="(.+)" replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div[@type='edition']/tei:p/tei:seg[@n='$1'])"/>
</refsDecl>
</encodingDesc><profileDesc>
<langUsage>
<language ident="grc">Greek</language>
Expand Down
9 changes: 5 additions & 4 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,21 @@ def test_run_local_repo_errors(self):
####
#
# /data/capitainingest/tei2/tlg4089.tlg004.1st1k-grc1.xml
# Has wrong root node
# Has wrong root node and a capitains_error
#
####
text = self.filter(parsed, "/data/capitainingest/tei2/tlg4089.tlg004.1st1k-grc1.xml")
self.assertEqual(
{'Naming conventions': False, 'RefsDecl parsing': False, 'Epidoc DTD validation': False,
'URN informations': False, 'File parsing': True, 'Passage level parsing': False,
'URN informations': False, 'File parsing': False, 'Passage level parsing': False,
'Available in inventory': False, 'Unique nodes found by XPath': False,
'Duplicate passages': False, 'Forbidden characters': False, 'Correct xml:lang attribute': False,
'Empty References': False}
,
text["units"], "Everything but XML parsing should fail in TEI.2 files"
text["units"], "Everything should fail in TEI.2 files"
)
self.assertFalse(text["status"], "Wrong XML scheme should fail file")
self.assertEqual(text['capitains_errors'], ['No reference declaration (refsDecl) found.'])

####
#
Expand Down Expand Up @@ -380,7 +381,7 @@ def test_run_tei_errors(self):
####
text = self.filter(parsed, "/data/tei/tei/tei.tei.weirdurn.xml")
self.assertIn(
'>>>>>> error: element "encodingDesc" incomplete [In (L27 C20)]', text["logs"],
'>>>>>> error: element "fileDesc" incomplete [In (L10 C16)]', text["logs"],
"TEI RNG Error should show"
)
self.assertIn(
Expand Down
Loading

0 comments on commit b1c4b0f

Please sign in to comment.