def test_run_fails_on_bad_fetch(self, m_parseArgs, m_chdir, m_join): """ TODO: Add a docstring explaining this test and its purpose. """ side_effect_check_output = [ 'origin /dev/null/target/Trilinos', 'df324ae' ] side_effect_check_call = [] side_effect_check_call.append(None) side_effect_check_call.append(CalledProcessError(-1, 'cmd')) side_effect_check_call.append(CalledProcessError(-2, 'cmd')) side_effect_check_call.append(CalledProcessError(-3, 'cmd')) with mock.patch('subprocess.check_output', side_effect=side_effect_check_output): with mock.patch('subprocess.check_call', side_effect=side_effect_check_call): # I'm not sure if we really needed to mock out stdio, we don't check it # so would it be more useful to provide that to the output if the test # should fail? Otherwise, are we flying blin? with mock.patch('sys.stdout', new_callable=StringIO): self.assertFalse(PRMerge.run()) return
def test_run_fails_on_bad_fetch(self): with mock.patch('subprocess.check_output', side_effect=['origin /dev/null/target/Trilinos', 'df324ae']), \ mock.patch('subprocess.check_call', side_effect=[None, CalledProcessError(-1, 'cmd'), CalledProcessError(-2, 'cmd'), CalledProcessError(-3, 'cmd')]), \ mock.patch('PullRequestLinuxDriverMerge.parseArgs'), \ mock.patch('sys.stdout', new_callable=StringIO), \ mock.patch('os.path.join'), \ mock.patch('os.chdir'): self.assertFalse(PullRequestLinuxDriverMerge.run())
def test_run(self): with mock.patch('PullRequestLinuxDriverMerge.parseArgs') as m_parser, \ mock.patch('os.chdir') as m_chdir, \ mock.patch('PullRequestLinuxDriverMerge.write_header') as m_writeHeader, \ mock.patch('PullRequestLinuxDriverMerge.echoJenkinsVars') as m_echoJenkins, \ mock.patch('PullRequestLinuxDriverMerge.merge_branch') as m_mergeBranch, \ mock.patch('os.path.join') as m_join, \ mock.patch('sys.stdout', new_callable=StringIO) as m_stdout: self.assertTrue(PullRequestLinuxDriverMerge.run()) m_parser.assert_called_once_with() m_chdir.assert_called_once_with( m_join(m_parser().workspaceDir, 'Trilinos')) m_writeHeader.assert_called_once_with() m_echoJenkins.assert_called_once_with(m_parser().workspaceDir) m_mergeBranch.assert_called_once_with(m_parser().sourceRepo, m_parser().sourceBranch, m_parser().targetBranch, m_parser().sourceSHA) self.assertEqual('Set CWD = ' + str(m_join()) + '\n', m_stdout.getvalue())
def test_run(self, m_join, m_mergeBranch, m_echoJenkins, m_writeHeader, m_chdir, m_parser): """ TODO: Add docstring that explains this test's purpose """ with mock.patch('sys.stdout', new_callable=StringIO) as m_stdout: self.assertTrue(PRMerge.run()) m_parser.assert_called_once_with() m_chdir.assert_called_once_with( m_join(m_parser().workspaceDir, 'Trilinos')) m_writeHeader.assert_called_once_with() m_echoJenkins.assert_called_once_with(m_parser().workspaceDir) m_mergeBranch.assert_called_once_with(m_parser().sourceRepo, m_parser().sourceBranch, m_parser().targetBranch, m_parser().sourceSHA) self.assertIn('Set CWD = ' + str(m_join()) + '\n', m_stdout.getvalue()) return
def test_run_fails_on_bad_remote_add(self): expected_string = '''Recieved subprocess.CalledProcessError - returned -1 from command test_cmd output None stdout None stderr None\n''' if sys.version_info.major is not 3: expected_string = '''Recieved subprocess.CalledProcessError - returned -1 from command test_cmd output None\n''' with mock.patch('subprocess.check_output', side_effect=['origin /dev/null/target/Trilinos', 'df324ae']), \ mock.patch('subprocess.check_call', side_effect=CalledProcessError(-1, 'test_cmd')), \ mock.patch('PullRequestLinuxDriverMerge.parseArgs'), \ mock.patch('sys.stdout', new_callable=StringIO) as m_stdout, \ mock.patch('os.path.join'), \ mock.patch('os.chdir'): self.assertFalse(PullRequestLinuxDriverMerge.run()) self.assertTrue(m_stdout.getvalue().endswith(expected_string))
def test_run_fails_on_bad_remote_add(self, m_stdout, m_parseArgs, m_chdir, m_path_join): expected_string = '''Recieved subprocess.CalledProcessError - returned -1 from command test_cmd output None stdout None stderr None\n''' if sys.version_info.major != 3: expected_string = '''Recieved subprocess.CalledProcessError - returned -1 from command test_cmd output None\n''' side_effect_check_output = [ 'origin /dev/null/target/Trilinos', 'df324ae' ] side_effect_check_call = CalledProcessError(-1, 'test_cmd') with mock.patch('subprocess.check_output', side_effect=side_effect_check_output), \ mock.patch('subprocess.check_call', side_effect=side_effect_check_call): self.assertFalse(PRMerge.run()) expected_string_list = [] expected_string_list.append( "Received subprocess.CalledProcessError - returned -1") expected_string_list.append("from command test_cmd") expected_string_list.append("output None") if sys.version_info.major == 3: expected_string_list.append("output None") expected_string_list.append("stdout None") expected_string_list.append("stderr None") for expected_string_i in expected_string_list: self.assertIn(expected_string_i, m_stdout.getvalue()) return
def test_run_fails_on_bad_parse(self): with mock.patch('PullRequestLinuxDriverMerge.parseArgs', side_effect=SystemExit(2)): self.assertFalse(PullRequestLinuxDriverMerge.run())