def test_run_git_raise(self, run): run.return_value.stdout = b'' run.return_value.stderr = b'test error' run.return_value.returncode = 1 with self.assertRaises(pscp.CalledProcessError) as cm: ppscp._run_git('test') e = cm.exception self.assertEqual(e.returncode, 1) self.assertEqual(e.stdout, b'') self.assertEqual(e.stderr, b'test error')
def test_run_git_return_invalid_characters(self, run): run.return_value.stdout = b'unknown hash 123\xff\xfe\xee\n' run.return_value.stderr = b'' run.return_value.returncode = 0 output = ppscp._run_git('test') self.assertEqual(output, 'unknown hash 123\uFFFD\uFFFD\uFFFD')
def test_run_git_return(self, run): run.return_value.stdout = b'test hash 123\n' run.return_value.stderr = b'' run.return_value.returncode = 0 output = ppscp._run_git('stash', 'create') self.assertEqual(output, 'test hash 123') run.assert_called_once_with( ('git', 'stash', 'create'), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def test_run_git_non_str_raise(self): with self.assertRaises(TypeError): ppscp._run_git('test', None, '123') with self.assertRaises(TypeError): ppscp._run_git('test', b'test', '123')
def test_run_git(self): output = ppscp._run_git('version') self.assertRegex(output, r'(\d+)\.(\d+)\.(\d+)')