def test_createTestCommands_testsuite(self): """The correct create_test commands should be run with a test suite This tests that multiple create_test commands are run, one with each compiler in the given test suite for the given machine This test also checks the stdout and stderr files used for each command It also ensures that the cs.status.fails and cs.status files are created """ machine = self._make_machine() with mock.patch('ctsm.run_sys_tests.datetime') as mock_date, \ mock.patch('ctsm.run_sys_tests.get_tests_from_xml') as mock_get_tests: mock_date.now.side_effect = self._fake_now mock_get_tests.return_value = [{'compiler': 'intel'}, {'compiler': 'pgi'}, {'compiler': 'intel'}] run_sys_tests(machine=machine, cime_path=self._cime_path(), suite_name='my_suite') all_commands = machine.job_launcher.get_commands() self.assertEqual(len(all_commands), 2) for command in all_commands: six.assertRegex(self, command.cmd, r'--xml-category +{}(\s|$)'.format('my_suite')) six.assertRegex(self, command.cmd, r'--xml-machine +{}(\s|$)'.format(self._MACHINE_NAME)) six.assertRegex(self, all_commands[0].cmd, r'--xml-compiler +intel(\s|$)') six.assertRegex(self, all_commands[1].cmd, r'--xml-compiler +pgi(\s|$)') expected_testid1 = '{}_int'.format(self._expected_testid()) expected_testid2 = '{}_pgi'.format(self._expected_testid()) six.assertRegex(self, all_commands[0].cmd, r'--test-id +{}(\s|$)'.format(expected_testid1)) six.assertRegex(self, all_commands[1].cmd, r'--test-id +{}(\s|$)'.format(expected_testid2)) expected_testroot_path = os.path.join(self._scratch, self._expected_testroot()) self.assertEqual(all_commands[0].out, os.path.join(expected_testroot_path, 'STDOUT.'+expected_testid1)) self.assertEqual(all_commands[0].err, os.path.join(expected_testroot_path, 'STDERR.'+expected_testid1)) self.assertEqual(all_commands[1].out, os.path.join(expected_testroot_path, 'STDOUT.'+expected_testid2)) self.assertEqual(all_commands[1].err, os.path.join(expected_testroot_path, 'STDERR.'+expected_testid2)) expected_cs_status = os.path.join(self._scratch, self._expected_testroot(), 'cs.status') expected_cs_status = os.path.join(self._scratch, self._expected_testroot(), 'cs.status.fails') self.assertTrue(os.path.isfile(expected_cs_status))
def test_createTestCommand_testnames(self): """The correct create_test command should be run when providing a list of test names This test covers three things: (1) The use of a testlist argument (2) The standard arguments to create_test (the path to create_test, the arguments --test-id and --output-root, and the absence of --compare and --generate) (3) That a cs.status.fails file was created """ machine = self._make_machine() with mock.patch('ctsm.run_sys_tests.datetime') as mock_date: mock_date.now.side_effect = self._fake_now run_sys_tests(machine=machine, cime_path=self._cime_path(), testlist=['test1', 'test2']) all_commands = machine.job_launcher.get_commands() self.assertEqual(len(all_commands), 1) command = all_commands[0].cmd expected_create_test = os.path.join(self._cime_path(), 'scripts', 'create_test') six.assertRegex(self, command, r'^ *{}\s'.format(re.escape(expected_create_test))) six.assertRegex(self, command, r'--test-id +{}\s'.format(self._expected_testid())) expected_testroot_path = os.path.join(self._scratch, self._expected_testroot()) six.assertRegex(self, command, r'--output-root +{}\s'.format(expected_testroot_path)) six.assertRegex(self, command, r'test1 +test2(\s|$)') assertNotRegex(self, command, r'--compare\s') assertNotRegex(self, command, r'--generate\s') expected_cs_status = os.path.join(self._scratch, self._expected_testroot(), 'cs.status.fails') self.assertTrue(os.path.isfile(expected_cs_status))
def test_createTestCommands_testsuiteSpecifiedCompilers(self): """The correct commands should be run with a test suite where compilers are specified""" machine = self._make_machine() with mock.patch( 'ctsm.run_sys_tests.get_tests_from_xml') as mock_get_tests: # This value should be ignored; we just set it to make sure it's different # from the passed-in compiler list mock_get_tests.return_value = [{ 'compiler': 'intel' }, { 'compiler': 'pgi' }, { 'compiler': 'gnu' }] run_sys_tests(machine=machine, cime_path=self._cime_path(), suite_name='my_suite', suite_compilers=['comp1a', 'comp2b']) all_commands = machine.job_launcher.get_commands() self.assertEqual(len(all_commands), 2) six.assertRegex(self, all_commands[0].cmd, r'--xml-compiler +comp1a(\s|$)') six.assertRegex(self, all_commands[1].cmd, r'--xml-compiler +comp2b(\s|$)')
def test_pathToCime_standaloneOnlyWithoutCime(self): """Test path_to_cime with standalone_only, where cime is missing""" ctsm_path = os.path.join(self._testdir, 'ctsm') os.makedirs(ctsm_path) with mock.patch('ctsm.path_utils.path_to_ctsm_root', return_value=ctsm_path): with six.assertRaisesRegex(self, RuntimeError, "Cannot find cime"): _ = path_utils.path_to_cime(standalone_only=True)
def test_pathToCime_cimeInCesm(self): """Test path_to_cime, where cime is not in the standalone directory but is present in the CESM directory structure """ ctsm_path, actual_path_to_cime = self._make_cesm_dirs() with mock.patch('ctsm.path_utils.path_to_ctsm_root', return_value=ctsm_path): path_to_cime = path_utils.path_to_cime() self.assertEqual(path_to_cime, actual_path_to_cime)
def test_pathToCime_noCimeInCesm(self): """Test path_to_cime, where we appear to be within a CESM checkout, but there is no cime directory""" ctsm_path = self._ctsm_path_in_cesm() os.makedirs(ctsm_path) with mock.patch('ctsm.path_utils.path_to_ctsm_root', return_value=ctsm_path): with six.assertRaisesRegex(self, RuntimeError, "Cannot find cime.*or within CESM checkout"): _ = path_utils.path_to_cime()
def test_pathToCime_standaloneOnlyWithCimeInCesm(self): """Test path_to_cime with standalone_only, where cime is missing from the standalone structure, but cime is present in the CESM directory structure: should raise an exception rather than finding that cime """ ctsm_path, _ = self._make_cesm_dirs() with mock.patch('ctsm.path_utils.path_to_ctsm_root', return_value=ctsm_path): with six.assertRaisesRegex(self, RuntimeError, "Cannot find cime"): _ = path_utils.path_to_cime(standalone_only=True)
def test_pathToCime_standaloneOnlyWithCime(self): """Test path_to_cime with standalone_only, where cime is in the location it should be with a standalone checkout """ ctsm_path = os.path.join(self._testdir, 'ctsm') actual_path_to_cime = os.path.join(ctsm_path, 'cime') os.makedirs(actual_path_to_cime) with mock.patch('ctsm.path_utils.path_to_ctsm_root', return_value=ctsm_path): path_to_cime = path_utils.path_to_cime(standalone_only=True) self.assertEqual(path_to_cime, actual_path_to_cime)
def test_pathToCime_notInCesmCheckout(self): """Test path_to_cime, where cime is not in the standalone directory, and we don't appear to be in a CESM checkout """ ctsm_path = os.path.join(self._testdir, 'components', 'foo') os.makedirs(ctsm_path) os.makedirs(self._cime_path_in_cesm()) with mock.patch('ctsm.path_utils.path_to_ctsm_root', return_value=ctsm_path): with six.assertRaisesRegex(self, RuntimeError, "Cannot find cime.*don't seem to be within a CESM checkout"): _ = path_utils.path_to_cime()
def test_testroot_setup(self): """Ensure that the appropriate test root directory is created and populated""" machine = self._make_machine() with mock.patch('ctsm.run_sys_tests.datetime') as mock_date: mock_date.now.side_effect = self._fake_now run_sys_tests(machine=machine, cime_path=self._cime_path(), testlist=['foo']) expected_dir = os.path.join(self._scratch, self._expected_testroot()) self.assertTrue(os.path.isdir(expected_dir)) expected_link = os.path.join(self._curdir, self._expected_testroot()) self.assertTrue(os.path.islink(expected_link)) self.assertEqual(os.readlink(expected_link), expected_dir)
def test_pathToCime_cimeInStandaloneAndCesm(self): """Test path_to_cime, where there is a cime directory both in the standalone checkout and in the enclosing CESM checkout. Should give us the cime in the standalone checkout. """ ctsm_path, _ = self._make_cesm_dirs() actual_path_to_cime = os.path.join(ctsm_path, 'cime') os.makedirs(actual_path_to_cime) with mock.patch('ctsm.path_utils.path_to_ctsm_root', return_value=ctsm_path): path_to_cime = path_utils.path_to_cime() self.assertEqual(path_to_cime, actual_path_to_cime)