Skip to content

Commit

Permalink
Add test for member functions (#600)
Browse files Browse the repository at this point in the history
Added tests for `CDashAnalyzeReportRandomFailuresDriver` member functions in
`CDashAnalyzeReportRandomFailures.py`.
  • Loading branch information
achauphan committed Feb 13, 2024
1 parent c7ae356 commit e757fc9
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
71 changes: 71 additions & 0 deletions test/ci_support/CDashAnalyzeReportRandomFailures_UnitTests.py
Original file line number Diff line number Diff line change
@@ -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()
9 changes: 9 additions & 0 deletions test/ci_support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e757fc9

Please sign in to comment.