def test__command_failure(self): cmd = "echo bla > /dev/stderr; false" with self.assertRaises(command.CommandFailed) as caught: command.execute_assert_success(cmd, shell=True) self.assertEquals(caught.exception.output.rstrip(), "bla".encode('utf-8')) self.assertEquals(caught.exception.returncode, 1) exception_repr = repr(caught.exception) self.assertIn("returncode: 1", exception_repr) self.assertIn(repr(cmd), exception_repr) self.assertIn("output: 'bla", exception_repr)
def test__command_propagate_non_enoent(self): self.forge = Forge() self.forge.replace(command.subprocess, "Popen") self.addCleanup(self.forge.restore_all_replacements) expected_code = 23232 command.subprocess.Popen( Anything(), cwd=Anything(), shell=True, close_fds=True, stdout=Anything(), stderr=command.subprocess.STDOUT, stdin=Anything() ).and_raise(OSError(expected_code, "message")) with self.forge.verified_replay_context(): with self.assertRaises(OSError) as caught: command.execute_assert_success("bla", shell=True) self.assertIsInstance(caught.exception, OSError) self.assertEquals(caught.exception.errno, expected_code)
def test__remote_references(self): command.execute_assert_success("git ls-remote {0}".format(self.url), shell=True).and_return((0, """\ ccd9dc4f0775c442ede15db26c26c02a766cf1a HEAD 4ccd9dc4f0775c442ede15db26c26c02a766cf1a refs/heads/master bee1140b66c0ca1cb788e52697b7fb66ecb650bd some_symlink -> blap bee1140b66c0ca1cb788e52697b7fb66ecb650bd refs/tags/v0.0.1 """)) self.forge.replay() result = git.get_remote_references_dict(self.url) self.assertIsInstance(result, dict) refs = sorted(result) self.assertEquals(len(refs), 2) self.assertIsInstance(refs[0], git.Branch) self.assertEquals(refs[0], 'master') self.assertEquals(result['master'], "4ccd9dc4f0775c442ede15db26c26c02a766cf1a") self.assertEquals(refs[0].to_ref_name(), 'master') self.assertIsInstance(refs[1], git.Tag) self.assertEquals(refs[1], 'v0.0.1') self.assertEquals(refs[1].to_ref_name(), 'tags/v0.0.1') self.assertEquals(result['v0.0.1'], "bee1140b66c0ca1cb788e52697b7fb66ecb650bd")
def test__clone_to(self): command.execute_assert_success("git clone -b {0} {1} {2}".format(self.branch, self.url, self.path), shell=True) with self.forge.verified_replay_context(): git.clone_to(self.url, self.branch, self.path)
def test__update(self): command.execute_assert_success("git fetch {0} {1}".format(self.url, self.branch), cwd=self.path, shell=True) command.execute_assert_success("git reset --hard FETCH_HEAD && git clean -fdx", cwd=self.path, shell=True) with self.forge.verified_replay_context(): git.update(self.url, self.branch, self.path)
def test__command_success(self): result, output = command.execute_assert_success("echo hello", shell=True) self.assertEquals(result, 0) self.assertEquals(output.rstrip().decode('utf-8'), "hello")
def test__command_cwd(self): result, output = command.execute_assert_success("pwd", shell=True, cwd="/") self.assertEquals(output.rstrip(), "/".encode('utf-8')) self.assertEquals(result, 0)
def test__command_no_shell(self): with self.assertRaises(command.CommandFailed): command.execute_assert_success("echo hello", shell=False)