Esempio n. 1
0
    def test_override_environment(self):
        env = {"PATH": "PATH"}
        status, output, error = execute(
            sys.executable,
            "-c",
            """import os
print(os.environ.get('PATH', ''))
""",
            env=env,
        )
        self.assertEqual(status, 0)
        self.assertRegexpMatches(output.decode("ascii"), "^PATH\s*$")
        self.assertRegexpMatches(error.decode("ascii"), "^$")
        os.environ["FOO"] = "foo"
        status, output, error = execute(
            sys.executable,
            "-c",
            """import os
print(os.environ.get('FOO', ''))
""",
        )
        self.assertEqual(status, 0)
        self.assertRegexpMatches(output.decode("ascii"), "^foo\s*$")
        self.assertRegexpMatches(error.decode("ascii"), "^$")
        status, output, error = execute(
            sys.executable,
            "-c",
            """import os
print(os.environ.get('FOO', ''))
""",
            env={"FOO": "bar"},
        )
        self.assertEqual(status, 0)
        self.assertRegexpMatches(output.decode("ascii"), "^bar\s*$")
        self.assertRegexpMatches(error.decode("ascii"), "^$")
Esempio n. 2
0
def test_execute_with_error():
    status, output, error = execute(
        sys.executable, "-c", "import sys; sys.exit(2)"
    )
    assert status == 2
    assert re.match(r"^$", output.decode("ascii"))
    assert re.match(r"^$", error.decode("ascii"))
Esempio n. 3
0
 def _msbuild(self, config):
     command = [
         config.executables['msbuild'],
         '/p:Configuration=%s'  % config.configuration,
         '/p:Platform=%s'       % config.platform,
         '/p:PlatFormTarget=%s' % config.platform,
         '/p:OutputPath=%s'     % config.output_path,
         '/t:%s' %  os.path.normpath(self.project.id.replace('.', '_')),
         self.sln,
     ]
     return execute(*command, environment=config.environment)
Esempio n. 4
0
def test_override_environment():
    status, output, error = execute(sys.executable,
                                    '-c',
                                    PRINT_VAR.format(var='PATH'),
                                    env={'PATH': 'PATH'})
    assert status == 0
    assert re.match('^PATH\s*$', output.decode('ascii'))
    assert re.match('^$', error.decode('ascii'))
    os.environ['FOO'] = 'foo'
    status, output, error = execute(sys.executable, '-c',
                                    PRINT_VAR.format(var='FOO'))
    assert status == 0
    assert re.match('^foo\s*$', output.decode('ascii'))
    assert re.match('^$', error.decode('ascii'))
    status, output, error = execute(sys.executable,
                                    '-c',
                                    PRINT_VAR.format(var='FOO'),
                                    env={'FOO': 'bar'})
    assert status == 0
    assert re.match('^bar\s*$', output.decode('ascii'))
    assert re.match('^$', error.decode('ascii'))
Esempio n. 5
0
 def _command(self, config):
     status, output, error = (0, '', '')
     for command in self.commands:
         if isinstance(command, basestring):
             command = shell.split(string.Template(command).safe_substitute(**config.environment))
         else:
             command = map(lambda part: string.Template(part).safe_substitute(**config.environment), command)
         s, o, e = execute(*command, environment=config.environment)
         status += 0 if s in self.success else 1
         output += o
         error  += e
         if status != 0:
             break
     return status, output, error
Esempio n. 6
0
def test_override_environment():
    status, output, error = execute(
        sys.executable,
        "-c",
        PRINT_VAR.format(var="PATH"),
        env={"PATH": "PATH"},
    )
    assert status == 0
    assert re.match(r"^PATH\s*$", output.decode("ascii"))
    assert re.match(r"^$", error.decode("ascii"))
    os.environ["FOO"] = "foo"
    status, output, error = execute(
        sys.executable, "-c", PRINT_VAR.format(var="FOO")
    )
    assert status == 0
    assert re.match(r"^foo\s*$", output.decode("ascii"))
    assert re.match(r"^$", error.decode("ascii"))
    status, output, error = execute(
        sys.executable, "-c", PRINT_VAR.format(var="FOO"), env={"FOO": "bar"}
    )
    assert status == 0
    assert re.match(r"^bar\s*$", output.decode("ascii"))
    assert re.match(r"^$", error.decode("ascii"))
Esempio n. 7
0
 def open(self, what, path):
     path = os.path.abspath(path)
     if what == 'cmd':
         if platform.is_a(platform.WINDOWS):
             os.system('start cmd /k cd /d "%s"' % path)
         elif platform.is_a(platform.DARWIN):
             result = os.system('open -a iTerm "%s"' % path)
             if result != 0:
                 os.system('open -a Terminal "%s"' % path)
     elif what == 'fm':
         import webbrowser
         if platform.is_a(platform.DARWIN):
             webbrowser.open('file://' % path)
         else:
             webbrowser.open(path)
     elif what == 'thg':
         executable = self.config.executables[what]
         status, output, _ = execute(executable, '--repository', path)
         if status != 0:
             cprint('Unable to opet tortoiseHg.\n', Color.red)
             cprint('%s' % output)
Esempio n. 8
0
 def open(self, what, path):
     path = os.path.abspath(path)
     if what == 'cmd':
         if platform.is_a(platform.WINDOWS):
             os.system('start cmd /k cd /d "%s"' % path)
         elif platform.is_a(platform.DARWIN):
             result = os.system('open -a iTerm "%s"' % path)
             if result != 0:
                 os.system('open -a Terminal "%s"' % path)
     elif what == 'fm':
         import webbrowser
         if platform.is_a(platform.DARWIN):
             webbrowser.open('file://' % path)
         else:
             webbrowser.open(path)
     elif what == 'thg':
         executable = self.config.executables[what]
         status, output, _ = execute(executable, '--repository', path)
         if status != 0:
             cprint('Unable to opet tortoiseHg.\n', Color.red)
             cprint('%s' % output)
Esempio n. 9
0
File: hg.py Progetto: delicb/tea
 def _hg(self, operation, *args):
     """Execute the hg command substituting variables like repository path,
     remote repository URI, masked URI (masking password for logging)
     """
     data = {
         'path': self.repository.path,
         'uri': self.repository.uri,
         'muri': self.repository.muri,
     }
     pargs = [a % data for a in args]
     largs = [a.replace('%(uri)s', '%(muri)s') % data for a in args]
     logger.info('Execute: hg %s %s' % (operation, ' '.join(largs)))
     status = 1
     output = ''
     error = ''
     try:
         status, output, error = execute('hg', operation, *pargs)
         logger.info('Exit Code %s: hg %s %s',
                     status, operation, ' '.join(largs))
     except:
         logger.exception('hg failed! Exception thrown!')
     return status, output, error
Esempio n. 10
0
def test_not_existing_command():
    pytest.raises(NotFound, lambda: execute("non_existing_command"))
Esempio n. 11
0
def test_execute_with_success():
    status, output, error = execute("echo", "Hello world")
    assert status == 0
    assert re.match(r"^Hello world\s*$", output.decode("ascii"))
    assert re.match(r"^$", error.decode("ascii"))
Esempio n. 12
0
def test_execute_with_error():
    status, output, error = execute(sys.executable, '-c',
                                    'import sys; sys.exit(2)')
    assert status == 2
    assert re.match('^$', output.decode('ascii'))
    assert re.match('^$', error.decode('ascii'))
Esempio n. 13
0
def test_execute_with_success():
    status, output, error = execute('echo', 'Hello world')
    assert status == 0
    assert re.match('^Hello world\s*$', output.decode('ascii'))
    assert re.match('^$', error.decode('ascii'))
Esempio n. 14
0
 def test_not_existing_command(self):
     self.assertRaises(Exception, lambda: execute("non_existing_command", "-e", "something"))
Esempio n. 15
0
 def test_execute_with_success(self):
     status, output, error = execute("echo", "Hello world")
     self.assertEqual(status, 0)
     self.assertRegexpMatches(output.decode("ascii"), "^Hello world\s*$")
     self.assertRegexpMatches(error.decode("ascii"), "^$")
Esempio n. 16
0
 def test_execute_with_error(self):
     status, output, error = execute(sys.executable, "-c", "import sys; sys.exit(2)")
     self.assertEqual(status, 2)
     self.assertRegexpMatches(output.decode("ascii"), "^$")
     self.assertRegexpMatches(error.decode("ascii"), "^$")
Esempio n. 17
0
def test_not_existing_command():
    pytest.raises(NotFound, lambda: execute('non_existing_command'))