Skip to content

Commit a31c516

Browse files
committed
Merge pull request #472 from jmchilton/test_report_fixes
Have `planemo test` verify output reports are actually updated by Gal…
2 parents f6adde0 + e5aa94e commit a31c516

2 files changed

Lines changed: 71 additions & 9 deletions

File tree

planemo/galaxy/test/actions.py

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
NO_JSON_REPORT_MESSAGE = ("Cannot locate JSON report [%s] for tests - "
2121
"required to build planemo report and summarize "
2222
"tests.")
23+
REPORT_NOT_CHANGED = ("Galaxy failed to update test report [%s] for tests - "
24+
"required to build planemo report and summarize "
25+
"tests.")
2326
NO_TESTS_MESSAGE = "No tests were executed - see Galaxy output for details."
2427
ALL_TESTS_PASSED_MESSAGE = "All %d test(s) executed passed."
2528
PROBLEM_COUNT_MESSAGE = ("There were problems with %d test(s) - out of %d "
@@ -43,7 +46,9 @@ def run_in_config(ctx, config, run=run_galaxy_command, **kwds):
4346
job_output_files = os.path.join(config_directory, "jobfiles")
4447

4548
xunit_report_file = _xunit_state(kwds, config)
49+
xunit_report_file_tracker = _FileChangeTracker(xunit_report_file)
4650
structured_report_file = _structured_report_file(kwds, config)
51+
structured_report_file_tracker = _FileChangeTracker(structured_report_file)
4752

4853
info("Testing using galaxy_root %s", config.galaxy_root)
4954
# TODO: Allow running dockerized Galaxy here instead.
@@ -85,15 +90,7 @@ def run_in_config(ctx, config, run=run_galaxy_command, **kwds):
8590
update_cp_args = (job_output_files, config.test_data_dir)
8691
shell('cp -r "%s"/* "%s"' % update_cp_args)
8792

88-
if not os.path.exists(xunit_report_file):
89-
message = NO_XUNIT_REPORT_MESSAGE % xunit_report_file
90-
error(message)
91-
raise Exception(message)
92-
93-
if not os.path.exists(structured_report_file):
94-
message = NO_JSON_REPORT_MESSAGE % structured_report_file
95-
error(message)
96-
raise Exception(message)
93+
_check_test_outputs(xunit_report_file_tracker, structured_report_file_tracker)
9794

9895
test_results = test_structures.GalaxyTestResults(
9996
structured_report_file,
@@ -248,6 +245,31 @@ def _print_command_line(structured_data, test_id):
248245
click.echo("| command: %s" % command)
249246

250247

248+
def _check_test_outputs(
249+
xunit_report_file_tracker,
250+
structured_report_file_tracker
251+
):
252+
if not os.path.exists(xunit_report_file_tracker.path):
253+
message = NO_XUNIT_REPORT_MESSAGE % xunit_report_file_tracker.path
254+
error(message)
255+
raise Exception(message)
256+
257+
if not os.path.exists(structured_report_file_tracker.path):
258+
message = NO_JSON_REPORT_MESSAGE % structured_report_file_tracker.path
259+
error(message)
260+
raise Exception(message)
261+
262+
if not xunit_report_file_tracker.changed():
263+
message = REPORT_NOT_CHANGED % xunit_report_file_tracker.path
264+
error(message)
265+
raise Exception(message)
266+
267+
if not structured_report_file_tracker.changed():
268+
message = REPORT_NOT_CHANGED % structured_report_file_tracker.path
269+
error(message)
270+
raise Exception(message)
271+
272+
251273
def _xunit_state(kwds, config):
252274
# This has been supported in Galaxy for well over a year, just going to assume
253275
# it from here on out.
@@ -278,6 +300,24 @@ def _structured_report_file(kwds, config):
278300
return structured_report_file
279301

280302

303+
class _FileChangeTracker(object):
304+
305+
def __init__(self, path):
306+
modification_time = None
307+
if os.path.exists(path):
308+
modification_time = os.path.getmtime(path)
309+
310+
self.path = path
311+
self.modification_time = modification_time
312+
313+
def changed(self):
314+
if self.modification_time:
315+
new_modification_time = os.path.getmtime(self.path)
316+
return self.modification_time != new_modification_time
317+
else:
318+
return os.path.exists(self.path)
319+
320+
281321
__all__ = [
282322
"run_in_config",
283323
"handle_reports",

tests/test_galaxy_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,28 @@ def mock_galaxy_run(ctx_, command, env, action):
6363
with self.assertRaises(Exception):
6464
self._do_run(mock_galaxy_run)
6565

66+
def test_failed_to_update_xml(self):
67+
"""Test an exception is thrown if XUnit report isn't updated."""
68+
self._copy_good_artifacts(["xml", "html", "json"])
69+
70+
def mock_galaxy_run(ctx_, command, env, action):
71+
self._copy_good_artifacts(["json", "html"])
72+
return 0
73+
74+
with self.assertRaises(Exception):
75+
self._do_run(mock_galaxy_run)
76+
77+
def test_failed_to_update_json(self):
78+
"""Test an exception is thrown if XUnit report isn't updated."""
79+
self._copy_good_artifacts(["xml", "html", "json"])
80+
81+
def mock_galaxy_run(ctx_, command, env, action):
82+
self._copy_good_artifacts(["xml", "html"])
83+
return 0
84+
85+
with self.assertRaises(Exception):
86+
self._do_run(mock_galaxy_run)
87+
6688
def _copy_good_artifacts(self, extensions):
6789
for extension in extensions:
6890
source = os.path.join(TEST_DATA_DIR, "tt_success.%s" % extension)

0 commit comments

Comments
 (0)