Skip to content

Commit

Permalink
Add unit tests for compile_job_summary()
Browse files Browse the repository at this point in the history
  • Loading branch information
mxk62 committed May 20, 2024
1 parent 1cf0cd2 commit 0a9a85a
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

"""Tests for reporting mechanism."""

import dataclasses
import io
import unittest

Expand All @@ -39,6 +40,7 @@
WmsJobReport,
WmsRunReport,
WmsStates,
compile_job_summary,
)


Expand Down Expand Up @@ -349,5 +351,50 @@ def testAddWithoutRunSummary(self):
self.assertRegex(self.actual.message, r"^WARNING.*incomplete")


class CompileJobSummaryTestCase(unittest.TestCase):
"""Test compiling a job summary."""

def setUp(self):
self.report = WmsRunReport(
wms_id="1.0",
global_wms_id="foo#1.0",
path="/path/to/run",
label="label",
run="run",
project="dev",
campaign="testing",
payload="test",
operator="tester",
run_summary="foo:1",
state=WmsStates.SUCCEEDED,
jobs=[WmsJobReport(wms_id="1.0", name="", label="foo", state=WmsStates.SUCCEEDED)],
total_number_jobs=1,
job_state_counts={state: 1 if state == WmsStates.SUCCEEDED else 0 for state in WmsStates},
job_summary={
"foo": {state: 1 if state == WmsStates.SUCCEEDED else 0 for state in WmsStates},
},
)

def tearDown(self):
pass

def testSummaryExists(self):
result = dataclasses.replace(self.report)
compile_job_summary(result)
self.assertEqual(result, self.report)

def testSummaryMissing(self):
result = dataclasses.replace(self.report)
result.job_summary = None
compile_job_summary(result)
self.assertEqual(result, self.report)

def testCompilationError(self):
self.report.job_summary = None
self.report.jobs = None
with self.assertRaises(ValueError):
compile_job_summary(self.report)


if __name__ == "__main__":
unittest.main()

0 comments on commit 0a9a85a

Please sign in to comment.