Example #1
0
 def test_run_cmd_rc_only(self):
     self.assertTrue(os.access(dumbo, os.R_OK | os.X_OK))
     command = [dumbo, "STDOUT:Hello", "STDERR:Bye", "--exit-code"]
     exit_code = 69
     rv = util.run_cmd(command + [str(exit_code)], rc_only=True)
     self.assertEqual(exit_code, rv[0])
     rv = util.run_cmd(command + [str(exit_code + 1)], rc_only=True)
     self.assertNotEqual(exit_code, rv[0])
     self.assertEqual('Hello\n', rv[1])
Example #2
0
 def test_run_cmd_setting_workdir(self):
     real_workdir = subprocess.check_output(['pwd', '-P']).strip()
     self.assertEqual(real_workdir, os.getcwd())
     code, output = util.run_cmd(['pwd', '-P'], workdir=os.getcwd())
     self.assertEqual(os.getcwd() + '\n', output)
     tmpdir = tempfile.mkdtemp(prefix=__file__)
     code, output = util.run_cmd(['pwd', '-P'], workdir=tmpdir)
     self.assertEqual(tmpdir + '\n', output)
     os.rmdir(tmpdir)
Example #3
0
 def __init__(self, revision_names=[], data_f='file'):
     object.__init__(self)
     self.revision_names = revision_names
     self.revisions = []
     self.location = loc = make_temp_dir('TempGit')
     run_cmd(['git', 'init'], workdir=loc)
     for r_name in revision_names:
         with open(os.path.join(loc, data_f), 'w+b') as f:
             f.write(str(r_name))
         run_cmd(['git', 'add', data_f], workdir=loc)
         date = datetime.datetime.now(pytz.timezone('US/Pacific')) \
             .replace(microsecond=0)
         env = {
             'GIT_COMMITTER_DATE': date.isoformat(),
             'GIT_AUTHOR_DATE': date.isoformat()
         }
         run_cmd(['git', 'commit', '-m',
                  "%s %s" % (data_f, r_name)],
                 workdir=loc, env=env)
         commit = run_cmd(['git', 'rev-parse', 'HEAD'],
                          workdir=loc)[1].strip()
         run_cmd(['git', 'tag', str(r_name)], workdir=loc)
         self.revisions.append(
             {'name': str(r_name), 'commit': commit,
              'date': date})
Example #4
0
 def test_run_cmd_inc_err(self):
     self.assertTrue(os.access(dumbo, os.R_OK | os.X_OK))
     command_with_stderr = [
         dumbo, "STDOUT:stdout", "STDERR:stderr", "STDOUT:stdout"
     ]
     output = util.run_cmd(command_with_stderr, inc_err=True)
     self.assertEqual(
         'stdout\nstderr\nstdout\n',
         output[1]
     )
     output = util.run_cmd(command_with_stderr, inc_err=False)
     self.assertEqual(
         'stdout\nstdout\n',
         output[1]
     )
Example #5
0
    def __init__(self, revision_names=[], data_f='file'):
        object.__init__(self)
        self.revision_names = revision_names
        self.revisions = []
        self.location = loc = make_temp_dir('TempHg')
        run_cmd(['hg', 'init'], workdir=loc)
        for r_name in revision_names:
            with open(os.path.join(loc, data_f), 'w+b') as f:
                f.write(str(r_name))
            run_cmd(['hg', 'add', data_f], workdir=loc)
            date = datetime.datetime.now(pytz.timezone('US/Pacific'))

            # Dec 6 13:18 -0600
            date_string = date.replace(microsecond=0) \
                .strftime("%b %d %H:%M:%S %z")
            run_cmd(['hg', 'commit', '--date', date_string, '-m',
                     "%s %s" % (data_f, r_name)],
                    workdir=loc)
            # HG Creates a complete commit for tags.  Lolwut?
            #run_cmd(['hg', 'tag', str(r_name)], workdir=loc)
            commit = run_cmd(['hg', 'log', '-l1', '--template', "{node}", "."],
                             workdir=loc)[1].strip()
            self.revisions.append(
                {'name': str(r_name), 'commit': commit,
                 'date': date})
Example #6
0
 def test_default(self):
     self.assertTrue(os.access(dumbo, os.R_OK | os.X_OK))
     expected_output = "I am dumb\n"
     command = [dumbo, 'STDOUT:' + expected_output]
     actual_output = util.run_cmd(command)[1]
     # XXX: Figure out why I need to strip the output!
     self.assertEqual(
         expected_output + '\n',
         actual_output,
         "'%s' != '%s'" % (expected_output, actual_output))
Example #7
0
 def eval(self, history_line):
     log.debug("Running script evaluator with %s", self.script)
     code, output = run_cmd(command=self.script, rc_only=True)
     log.debug("Script evaluator returned %d", code)
     return code == 0
Example #8
0
 def tag_repo(self):
     for i in self.t_repo.revisions:
         run_cmd(['hg', 'tag', str(i['name']), '-r',
                 str(i['commit'])], workdir=self.t_repo.location)