From e757fc9a1e2330542afc3a8024e018432a5b3965 Mon Sep 17 00:00:00 2001 From: Anderson Chauphan Date: Mon, 12 Feb 2024 16:36:30 -0700 Subject: [PATCH] Add test for member functions (#600) Added tests for `CDashAnalyzeReportRandomFailuresDriver` member functions in `CDashAnalyzeReportRandomFailures.py`. --- ...shAnalyzeReportRandomFailures_UnitTests.py | 71 +++++++++++++++++++ test/ci_support/CMakeLists.txt | 9 +++ 2 files changed, 80 insertions(+) create mode 100644 test/ci_support/CDashAnalyzeReportRandomFailures_UnitTests.py diff --git a/test/ci_support/CDashAnalyzeReportRandomFailures_UnitTests.py b/test/ci_support/CDashAnalyzeReportRandomFailures_UnitTests.py new file mode 100644 index 000000000..ab8888673 --- /dev/null +++ b/test/ci_support/CDashAnalyzeReportRandomFailures_UnitTests.py @@ -0,0 +1,71 @@ +import unittest +from unittest.mock import patch +import unittest.mock as mock +import datetime + + +from FindCISupportDir import * +import CDashAnalyzeReportRandomFailures as CDARRF +from example_cdash_analyze_and_report_random_failures import ExampleVersionInfoStrategy, ExampleExtractBuildNameStrategy + + +#################################################################### +# +# Test CDashAnalyzeReportRandomFailuresDriver +# +#################################################################### + +def getDriver(): + return CDARRF.CDashAnalyzeReportRandomFailuresDriver( + ExampleVersionInfoStrategy(), + ExampleExtractBuildNameStrategy()) + +# +# Test getDateRangeTuple member function +# for how it constructs a tuple containing +# the begin and end of a date range. +# +class Test_GetDateRangeTuple(unittest.TestCase): + + def setUp(self): + self.driver = getDriver() + + def test_date_range_tuple(self): + referenceDateTime = datetime.datetime(year=2024, month=2, day=12) + dayTimeDelta = 3 + expected = ('2024-02-10', '2024-02-12') + + sideEffectList = ['2024-02-10', '2024-02-12'] + with mock.patch('cdash_build_testing_date.getDateStrFromDateTime', side_effect=sideEffectList) as m_getDateStrFromDateTime: + result = self.driver.getDateRangeTuple(referenceDateTime, dayTimeDelta) + + self.assertEqual(result, expected) + + +# +# Test getBuildIDFromTest() member function +# to check if it can get correctly get the last value of +# a slash delimited string +# +class Test_GetBuildIdFromTest(unittest.TestCase): + + def setUp(self): + self.driver = getDriver() + + def test_single_slash(self): + testDict = {'buildSummaryLink':'build/somenumber'} + self.assertEqual( + self.driver.getBuildIdFromTest(testDict), 'somenumber') + + def test_multiple_slash(self): + testDict = {'buildSummaryLink':'build/two/somenumber'} + self.assertEqual( + self.driver.getBuildIdFromTest(testDict), 'somenumber') + + def test_no_slash(self): + testDict = {'buildSummaryLink':'somenumber'} + self.assertEqual( + self.driver.getBuildIdFromTest(testDict), 'somenumber') + +if __name__ == '__main__': + unittest.main() diff --git a/test/ci_support/CMakeLists.txt b/test/ci_support/CMakeLists.txt index f0393806f..1c0207b65 100644 --- a/test/ci_support/CMakeLists.txt +++ b/test/ci_support/CMakeLists.txt @@ -398,6 +398,15 @@ tribits_add_advanced_test( cdash_analyze_and_report_UnitTests ALWAYS_FAIL_ON_NONZERO_RETURN ) +tribits_add_advanced_test( CDashAnalyzeReportRandomFailures_UnitTests + OVERALL_WORKING_DIRECTORY TEST_NAME + OVERALL_NUM_MPI_PROCS 1 + TEST_0 CMND ${PYTHON_EXECUTABLE} + ARGS ${CMAKE_CURRENT_SOURCE_DIR}/CDashAnalyzeReportRandomFailures_UnitTests.py -v + PASS_REGULAR_EXPRESSION "OK" + ALWAYS_FAIL_ON_NONZERO_RETURN + ) + tribits_add_advanced_test( cdash_analyze_and_report_random_failures_UnitTests OVERALL_WORKING_DIRECTORY TEST_NAME OVERALL_NUM_MPI_PROCS 1