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_fails_only(self): """With fails_only flag, only fails and pends should appear in the output""" test_name = 'my.test.name' test_dir = 'my.test.name.testid' test_dir_path = self.create_test_dir(test_dir) self.create_test_status_core_passes(test_dir_path, test_name) fail_phase = self.set_last_core_phase_to_fail(test_dir_path, test_name) pend_phase = self._NON_CORE_PHASE self.set_phase_to_status(test_dir_path, test_name, phase=pend_phase, status=test_status.TEST_PEND_STATUS) cs_status([os.path.join(test_dir_path, 'TestStatus')], fails_only=True, out=self._output) self.assert_status_of_phase(output=self._output.getvalue(), status=test_status.TEST_FAIL_STATUS, phase=fail_phase, test_name=test_name) self.assert_status_of_phase(output=self._output.getvalue(), status=test_status.TEST_PEND_STATUS, phase=pend_phase, test_name=test_name) for phase in test_status.CORE_PHASES: if phase != fail_phase: self.assert_phase_absent(output=self._output.getvalue(), phase=phase, test_name=test_name) six_additions.assertNotRegex(self, self._output.getvalue(), r'Overall:')
def assert_phase_absent(self, output, phase, test_name): """Asserts that 'output' does not contain a status line for the given phase and test_name""" expected = re.compile(r'^.* +' + self._test_name_and_phase_regex(test_name, phase), flags=re.MULTILINE) six_additions.assertNotRegex(self, output, expected)
def assert_phase_absent(self, output, phase, test_name): """Asserts that 'output' does not contain a status line for the given phase and test_name""" expected = re.compile( r'^.* +' + self._test_name_and_phase_regex(test_name, phase), flags=re.MULTILINE) six_additions.assertNotRegex(self, output, expected)