Skip to content

Commit

Permalink
Merge pull request #109 from Capitains/java_options
Browse files Browse the repository at this point in the history
Fixed java options in Travis causing test failure
  • Loading branch information
sonofmun committed Sep 19, 2017
2 parents 85295c5 + 8e39bb8 commit 0d2a34b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 36 deletions.
58 changes: 22 additions & 36 deletions HookTest/capitains_units/cts.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,13 @@ def refsDecl(self):
else:
yield False

def epidoc(self):
""" Check the original file against Epidoc rng through a java pipe
def run_rng(self, rng_path):
""" Run the RNG through JingTrang
:param rng_path: Path to the RelaxNG file to run against the XML to test
"""
test = subprocess.Popen(
["java", "-jar", TESTUnit.JING, TESTUnit.EPIDOC, self.path],
["java", "-jar", TESTUnit.JING, rng_path, self.path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False
Expand All @@ -389,52 +391,36 @@ def epidoc(self):
yield False
pass
finally:
if timer.isAlive() == False:
if not timer.isAlive():
self.log("Timeout on RelaxNG")
yield False
timer.cancel()
pass
timer.cancel()

# This is to deal with Travis printing a message about the _JAVA_OPTIONS when a java command is run
# Travis printing this command resulted in this test not passing
out = '\n'.join([x for x in out.decode().split('\n') if '_JAVA_OPTIONS' not in x]).encode()
error = '\n'.join([x for x in error.decode().split('\n') if '_JAVA_OPTIONS' not in x]).encode()

if len(out) > 0:
for error in TESTUnit.rng_logs(out):
self.log(error)
self.dtd_errors.append(error)
for issue in TESTUnit.rng_logs(out):
self.log(issue)
self.dtd_errors.append(issue)
yield len(out) == 0 and len(error) == 0

def epidoc(self):
""" Check the original file against Epidoc rng through a java pipe
"""
for status in self.run_rng(TESTUnit.EPIDOC):
yield status

def tei(self):
""" Check the original file against TEI rng through a java pipe
"""
test = subprocess.Popen(
["java", "-jar", TESTUnit.JING, TESTUnit.TEI_ALL, self.path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False,
)

out = []
error = []
timer = Timer(self.timeout, test.kill)
try:
timer.start()
out, error = test.communicate()
except Exception as E:
self.error(E)
yield False
pass
finally:
if timer.isAlive() == False:
self.log("Timeout on RelaxNG")
yield False
timer.cancel()
pass
timer.cancel()

if len(out) > 0:
for error in TESTUnit.rng_logs(out):
self.log(error)
self.dtd_errors.append(error)
yield len(out) == 0 and len(error) == 0
for status in self.run_rng(TESTUnit.TEI_ALL):
yield status

def passages(self):
""" Check that passages are available at each level. On top of that, it checks for forbidden characters \
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ requests>=2.8.1
six>=1.10.0
mock==1.3.0
prettytable==0.7.2
ansicolors==1.0.2
10 changes: 10 additions & 0 deletions tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,16 @@ def test_incorrect_xml_lang_epidoc_edition(self):
self.assertEqual(results, [False], "Non-existent xml:lang attribute should return False")
self.assertEqual(unit.lang, "UNK", "Non-existing xml:lang attribute should result in unit.lang being set to 'UNK'")

def test_run_relaxng(self):
""" Tests to make sure that an epidoc edition text with an xml:lang attribute on the div[@type="edition"] passes
"""
unit = HookTest.capitains_units.cts.CTSText_TestUnit("tests/lang_tests/xml_lang_failing_epidoc.xml")
unit.xml = etree.parse("tests/lang_tests/xml_lang_failing_epidoc.xml", HookTest.units.TESTUnit.PARSER)
unit.scheme = "epidoc"
unit.flush()
results = [result for result in unit.epidoc()]
self.assertEqual(results, [True], "Epidoc RelaxNG should run correctly")

def test_correct_xml_lang_tei_edition(self):
""" Tests to make sure that an epidoc edition text with an xml:lang attribute on the div[@type="edition"] passes
"""
Expand Down

0 comments on commit 0d2a34b

Please sign in to comment.