def checkout(self): from aasemble.django.utils import run_cmd run_cmd(['git', 'clone', self.build_record['source']['git_repository'], '--recursive', '-b', self.build_record['source']['git_branch'], self.builddir], logger=self.logger) run_cmd(['git', 'reset', '--hard', self.build_record['sha']], cwd=self.builddir, logger=self.logger)
def test_run_cmd_override_env(self): os.environ['TESTVAR'] = 'foo' stdout = run_cmd(['env']) self.assertIn(b'TESTVAR=foo', stdout) stdout = run_cmd(['env'], override_env={'TESTVAR': 'bar'}) self.assertIn(b'TESTVAR=bar', stdout) stdout = run_cmd(['env'], override_env={'TESTVAR': None}) self.assertNotIn(b'TESTVAR=', stdout)
def test_run_cmd_stdout_can_discard_stderr(self): tmpfile = self._prepare_stdout_stderr_script() try: self.assertNotIn(b'stderr', run_cmd([tmpfile], discard_stderr=True)) finally: os.unlink(tmpfile)
def test_run_cmd_alternate_stdout(self): fd, tmpfile = tempfile.mkstemp() try: with os.fdopen(fd, 'w') as fp: rv = run_cmd(['echo', 'foo'], stdout=fp) self.assertEquals(rv, None) with open(tmpfile, 'r') as fp: self.assertEquals(fp.read(), 'foo\n') finally: os.unlink(tmpfile)
def test_run_cmd_other_cwd(self): self.assertEquals(run_cmd(['pwd'], cwd='/').strip(), b'/')
def test_run_cmd_dead_simple(self): # Should simply return successfully stdout = run_cmd(['true']) self.assertEquals(stdout, b'')
def test_run_cmd_stdout_includes_stderr(self): tmpfile = self._prepare_stdout_stderr_script() try: self.assertIn(b'stderr', run_cmd([tmpfile])) finally: os.unlink(tmpfile)
def test_run_cmd_no_trailing_linefeed(self): logger = mock.MagicMock() stdout = run_cmd(['bash', '-c', 'echo -n foo'], logger=logger) self.assertEquals(stdout, b'foo') logger.log.assert_called_with(20, 'foo')
def key_data(repository): if repository.key_id: return run_cmd(['gpg', '-a', '--export', repository.key_id])