def test_TrilinosPRConfigurationBasePackageEnablesGCC720_ERROR(self): """ Test the call to create_package_enables_file() where there should be an error. """ print("") args = self.dummy_args_gcc_720() pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) # pre-load the property pr_config.get_property_from_config("ENABLE_MAP", args.pullrequest_build_name) with patch('sys.stdout', new=StringIO()) as fake_out: with self.assertRaises( subprocess.CalledProcessError ) as m_err: with patch('subprocess.check_call', side_effect=mock_subprocess_check_call) as m_call: with patch('subprocess.check_output', side_effect=mock_subprocess_raise_CalledProcessError) as m_output: pr_config.create_package_enables_file(dryrun=False) expected_output = "There was an issue generating `packageEnables.cmake`" actual_output = fake_out.getvalue() print("--- BEGIN expected output") print(expected_output) print("--- END expected output") print("--- BEGIN actual output") print(actual_output) print("--- END actual output") print("--- actual output must contain the expected output string") self.assertTrue( expected_output in actual_output)
def test_TrilinosPRConfigurationBaseBuildNameGCC720(self): args = self.dummy_args_gcc_720() pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) build_name = pr_config. pullrequest_build_name print("--- build_name = {}".format(build_name)) expected_build_name = "PR-{}-test-{}-{}".format(args.pullrequest_number, args.genconfig_build_name, args.jenkins_job_number) self.assertEqual(build_name, expected_build_name)
def test_TrilinosPRConfigurationBaseProperty_get_property_from_config_FAIL(self): """ Test the condition that the SECTION is missing from the .ini file. This should return the default value and print out a warning. """ print("") args = self.dummy_args_python3() pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) # Try to load a nonexistent section. print("-----[ TEST 1 ]-----------------------") with patch('sys.stdout', new=StringIO()) as fake_out: package_enables = pr_config.get_property_from_config("NONEXISTENTSECTION", "N/A") print(fake_out.getvalue()) print("--- package_enables = {}".format(package_enables)) print("--- expected_value = {}".format(None)) self.assertEqual(package_enables, None) self.assertIn("WARNING", fake_out.getvalue()) # Try to load nonexistent section but with a different default value print("-----[ TEST 2 ]-----------------------") default_value="OOPS!" with patch('sys.stdout', new=StringIO()) as fake_out: package_enables = pr_config.get_property_from_config("NONEXISTENTSECTION", "N/A", default=default_value) print(fake_out.getvalue()) print("--- package_enables = {}".format(package_enables)) print("--- expected_value = {}".format(default_value)) self.assertEqual(package_enables, default_value) self.assertIn("WARNING", fake_out.getvalue())
def test_TrilinosPRConfigurationBase_prepare_test_FAIL(self): """ Test the prepare_test method where it would fail due to mock_modulehelper_module_failodule loading problems in SetEnvironment() """ print("") args = self.dummy_args() args.max_cores_allowed=-1 pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) # Let's check the expected values for concurrency since this # test sets max_cores_allowed to the max detected. self.assertGreater(pr_config.concurrency_build, 1) self.assertEqual(pr_config.concurrency_test, 16) self.assertEqual(pr_config.max_cores_allowed, 64) # Test the case that with patch('trilinosprhelpers.setenvironment.ModuleHelper.module', side_effect=mock_modulehelper_module_ok): with patch('trilinosprhelpers.setenvironment.SetEnvironment.apply', side_effect=mock_se_apply_fail): with self.assertRaises(Exception): pr_config.prepare_test() # Test the case that the module() command fails down in SetEnvironment.apply() # when we throw an exception on failure. with patch('trilinosprhelpers.setenvironment.ModuleHelper.module', side_effect=mock_modulehelper_module_fail): with self.assertRaises(Exception): pr_config.prepare_test()
def test_TrilinosPRConfigurationBaseProperty_get_multi_property_from_config_FAIL(self): """ Test a failure condition where the section does not exist. """ print("") args = self.dummy_args() args.pullrequest_build_name = "Trilinos-pullrequest-gcc-8.3.0-installation-testing" pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) # Load the ENABLE_MAP job information to test `get_multi_property_from_config`. print("-----[ TEST 1 ]-----------------------") package_enables = pr_config.get_multi_property_from_config("NONEXISTENTSECTION", args.pullrequest_build_name) print("--- package_enables = {}".format(package_enables)) self.assertEqual(package_enables, None) # Change the default print("-----[ TEST 2 ]-----------------------") package_enables = pr_config.get_multi_property_from_config("NONEXISTENTSECTION", args.pullrequest_build_name, default="OOPS!") print("--- package_enables = {}".format(package_enables)) self.assertEqual(package_enables, "OOPS!") # Test SECTION exists, OPTION does not exist print("-----[ TEST 3 ]-----------------------") package_enables = pr_config.get_multi_property_from_config("ENABLE_MAP", "NONEXISTENT_OPTION") print("--- package_enables = {}".format(package_enables)) self.assertEqual(package_enables, None)
def test_TrilinosPRConfigurationBase_prepare_test(self): """ Test the prepare_test method """ print("") args = self.dummy_args() args.max_cores_allowed = -1 pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) # Let's check the expected values for concurrency since this # test sets max_cores_allowed to the max detected. self.assertGreater(pr_config.concurrency_build, 1) self.assertEqual(pr_config.concurrency_test, 16) self.assertEqual(pr_config.max_cores_allowed, 64) with patch('trilinosprhelpers.setenvironment.ModuleHelper.module', side_effect=mock_modulehelper_module_ok): with patch('subprocess.check_call', side_effect=mock_subprocess_check_call) as m_call: with patch( 'subprocess.check_output', side_effect=mock_subprocess_check_output) as m_output: ret = pr_config.prepare_test() self.assertEqual(ret, 0)
def test_TrilinosPRConfigurationBase(self): """ Tests if we can instantiate a TrilinosPRConfiguration object. """ args = self.dummy_args_python3() pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) #with patch('sysinfo.SysInfo.compute_num_usable_cores', return_value=6): # print("pr_config.concurrency_build = {}".format(pr_config.concurrency_build)) print("pr_config.max_cores_allowed = {}".format( pr_config.max_cores_allowed)) print("pr_config.arg_req_mem_per_core = {}".format( pr_config.arg_req_mem_per_core)) print("pr_config.max_test_parallelism = {}".format( pr_config.max_test_parallelism)) print("pr_config.concurrency_build = {}".format( pr_config.concurrency_build)) print("pr_config.concurrency_test = {}".format( pr_config.concurrency_test)) self.assertEqual(pr_config.max_cores_allowed, 12) self.assertAlmostEqual(pr_config.arg_req_mem_per_core, 3.0) self.assertEqual(pr_config.max_test_parallelism, 4) # This will vary b/c it's proven tricky to mock out the system memory for this # test so far. self.assertGreaterEqual(pr_config.concurrency_build, 1) self.assertEqual(pr_config.concurrency_test, 3)
def test_TrilinosPRConfigurationValidateBranchNameMasterFAIL(self): args = self.dummy_args_master_fail() pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.exit', side_effect=mock_early_return) as m: pr_config.validate_branch_constraints() m.assert_called_once() self.assertTrue( "ERROR:" in fake_out.getvalue())
def test_TrilinosPRConfigurationBaseProperty_package_enables_file(self): """ Check property: package_enables_file """ print("") args = self.dummy_args() pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) package_enables_file = pr_config.arg_filename_packageenables print("--- package_enables_file = {}".format(package_enables_file)) self.assertEqual(package_enables_file, "../packageEnables.cmake")
def test_TrilinosPRConfigurationBase_execute_test(self): """ Executes the test. This method should be considered 'virtual' and should be overridden. """ print("") args = self.dummy_args() pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) with self.assertRaises(NotImplementedError): pr_config.execute_test()
def test_TrilinosPRConfigurationBasePackageEnablesGCC720_dryrun(self): """ Test the PackageEnables generator in DryRun mode We can remove this when we take down the SCAFFOLDING from development. """ print("") args = self.dummy_args_gcc_720() pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) # pre-load the property pr_config.get_property_from_config("ENABLE_MAP", args.pullrequest_build_name) pr_config.create_package_enables_file(dryrun=True)
def test_TrilinosPRConfigurationBaseProperty_working_directory_ctest(self): """ Check property: working_directory_ctest """ print("") args = self.dummy_args() pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) working_directory_ctest = pr_config.working_directory_ctest print("--- working_directory: {}".format(pr_config.arg_workspace_dir)) print("--- working_directory_ctest: {}".format(working_directory_ctest)) self.assertIn("TFW_testing_single_configure_prototype", working_directory_ctest)
def test_TrilinosPRConfigurationBaseProperty_get_property_from_config_PASS(self): print("") args = self.dummy_args_python3() pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) # Load the ENABLE_MAP job information to test `get_property_from_config`. package_enables = pr_config.get_property_from_config("ENABLE_MAP", args.pullrequest_build_name) print("--- package_enables = {}".format(package_enables)) print("--- expected_value = TrilinosFrameworkTests") self.assertEqual(package_enables, "TrilinosFrameworkTests")
def test_TrilinosPRConfigurationBaseProperty_subprojects_file(self): """ Check property: filename_subprojects """ print("") args = self.dummy_args() pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) filename_subprojects = pr_config.arg_filename_subprojects print("--- filename_subprojects = {}".format(filename_subprojects)) self.assertEqual(filename_subprojects, "../package_subproject_list.cmake")
def test_TrilinosPRConfigurationBaseProperty_config_script(self): """ Validate that the property config_script loads properly. Since dummy args is loading the configuration for "Trilinos_pullrequest_gcc_7.2.0" the mapped configuration script should be loading "PullRequestLinuxGCC7.2.0TestingSettings.cmake" """ args = self.dummy_args() # Test the gcc 7.2.0 mapping args.pullrequest_build_name = "Trilinos-pullrequest-gcc-7.2.0" pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) self.assertEqual(pr_config.config_script, "generatedPRFragment.cmake")
def test_TrilinosPRConfigurationBasePackageEnablesGCC720(self): print("") args = self.dummy_args_gcc_720() pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) # pre-load the property pr_config.get_property_from_config("ENABLE_MAP", args.pullrequest_build_name) with patch('subprocess.check_call', side_effect=mock_subprocess_check_call) as m_call: with patch('subprocess.check_output', side_effect=mock_subprocess_check_output) as m_output: pr_config.create_package_enables_file(dryrun=False) m_call.assert_called_once() m_output.assert_called_once()
def test_TrilinosPRConfigurationBaseProperty_concurrency_test_err(self): """ Test the condition where an incorrect type is passed into the config_data setter. Mock multiprocessing.cpu_count to return 64 and we use 4 for the num_concurrent_tests parameter. concurrency_test should return 16. """ args = self.dummy_args_num_concurrent_tests(value=4) pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) concurrency_test = pr_config.concurrency_test print("concurrency_test = {}".format(concurrency_test)) self.assertEqual(concurrency_test, 4)
def test_TrilinosPRConfigurationBasePackageEnablesPython3(self): print("") args = self.dummy_args_python3() pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) # pre-load the property pr_config.get_property_from_config("ENABLE_MAP", args.pullrequest_build_name) with patch(mock_str_builtins_open(), new_callable=mock_open()) as m_open: with patch('subprocess.check_output', side_effect=mock_subprocess_check_output) as m_call: pr_config.create_package_enables_file(dryrun=False) calls = [ call('packageEnables.cmake','w'), call('package_subproject_list.cmake','w') ] m_open.assert_has_calls(calls, any_order=True)
def test_TrilinosPRConfigurationBasePackageEnablesPython3_dryrun(self): """ Test the PackageEnables generator in DryRun mode """ print("") args = self.dummy_args_python3() pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) # pre-load the property pr_config.get_property_from_config("ENABLE_MAP", args.pullrequest_build_name) with patch(mock_str_builtins_open(), new_callable=mock_open()) as m_open: pr_config.create_package_enables_file(dryrun=True) calls = [ call('packageEnables.cmake','w'), call('package_subproject_list.cmake','w') ] m_open.assert_has_calls(calls, any_order=True) print(".")
def test_TrilinosPRConfigurationBaseProperty_get_multi_property_from_config_PASS(self): print("") args = self.dummy_args() args.pullrequest_build_name = "Trilinos-pullrequest-gcc-8.3.0-installation-testing" pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) # Load the ENABLE_MAP job information to test `get_multi_property_from_config`. print("-----[ TEST 1 ]-----------------------") package_enables = pr_config.get_multi_property_from_config("ENABLE_MAP", args.pullrequest_build_name) print("--- package_enables = {}".format(package_enables)) print("--- expected_value = Teuchos,Tpetra") self.assertEqual(package_enables, "Teuchos,Tpetra") # Change the delimiter print("-----[ TEST 2 ]-----------------------") package_enables = pr_config.get_multi_property_from_config("ENABLE_MAP", args.pullrequest_build_name, delimeter=" ") print("--- package_enables = {}".format(package_enables)) print("--- expected_value = Teuchos Tpetra") self.assertEqual(package_enables, "Teuchos Tpetra")
def test_TrilinosPRConfigurationValidateBranchNameDevelop(self): args = self.dummy_args() pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) pr_config.validate_branch_constraints()
def test_TrilinosPRConfigurationValidateBranchNameMasterPASS(self): args = self.dummy_args_master_pass() pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) pr_config.validate_branch_constraints()
def test_TrilinosPRConfigurationCDashTrack(self): args = self.dummy_args_python3() pr_config = trilinosprhelpers.TrilinosPRConfigurationBase(args) cdash_track = pr_config.arg_pullrequest_cdash_track print("--- cdash_track = {}".format(cdash_track)) self.assertEqual(cdash_track, "Pull Request")