def test_execute_with_hidden_standard_error(self):
     process = Command('echo spam', hide_standard_error=True).execute()
     self.assertFalse(process.stdout.closed)
     self.assertFalse(process.stderr.closed)
     self.assertEqual(process.wait(), 0)
     process.stdout.close()
     process.stderr.close()
示例#2
0
def test_from_programoutput_node():
    node = program_output()
    node['command'] = 'echo spam'
    node['use_shell'] = False
    node['hide_standard_error'] = False
    command = Command.from_program_output_node(node)
    assert command.command == 'echo spam'
    assert not command.shell
    assert not command.hide_standard_error
    node['use_shell'] = True
    assert Command.from_program_output_node(node).shell
    assert not Command.from_program_output_node(node).hide_standard_error
    node['hide_standard_error'] = True
    assert Command.from_program_output_node(node).hide_standard_error
示例#3
0
def test_from_programoutput_node():
    node = program_output()
    node['command'] = 'echo spam'
    node['use_shell'] = False
    node['hide_standard_error'] = False
    node['working_directory'] = '/spam/with/eggs'
    command = Command.from_program_output_node(node)
    assert command.command == 'echo spam'
    assert command.working_directory == '/spam/with/eggs'
    assert not command.shell
    assert not command.hide_standard_error
    node['use_shell'] = True
    assert Command.from_program_output_node(node).shell
    assert not Command.from_program_output_node(node).hide_standard_error
    node['hide_standard_error'] = True
    assert Command.from_program_output_node(node).hide_standard_error
def test_cache_pickled(app, doctreedir):
    cmd = Command(['echo', 'spam'])
    result = (0, 'spam')
    assert app.env.programoutput_cache[cmd] == result
    app.build()
    pickled_env = doctreedir.join('environment.pickle').load()
    assert pickled_env.programoutput_cache == {cmd: result}
示例#5
0
 def test_get_output_with_hidden_standard_error(self):
     returncode, output = Command(
         sys.executable + ' -c "import sys; sys.stderr.write(\'spam\')"',
         hide_standard_error=True,
     ).get_output()
     self.assertEqual(returncode, 0)
     self.assertEqual(output, '')
 def test_working_directory_shell(self):
     cache = ProgramOutputCache()
     cwd = os.path.join(self.tmpdir, 'wd')
     os.mkdir(cwd)
     cwd = os.path.realpath(os.path.normpath(str(cwd)))
     cmd = Command('echo $PWD', working_directory=cwd, shell=True)
     self.assert_cache(cache, cmd, cwd)
示例#7
0
 def test_working_directory(self):
     cache = ProgramOutputCache()
     cwd = os.path.join(self.tmpdir, 'wd')
     os.mkdir(cwd)
     cwd = os.path.realpath(os.path.normpath(str(cwd)))
     cmd = ['python', '-c', 'import sys, os; sys.stdout.write(os.getcwd())']
     self.assert_cache(cache, Command(cmd, working_directory=cwd), cwd)
示例#8
0
def test_get_output_with_working_directory(tmpdir):
    cwd = os.path.realpath(str(tmpdir))
    returncode, output = Command(
        'python -c "import sys, os; sys.stdout.write(os.getcwd())"',
        working_directory=cwd).get_output()
    assert returncode == 0
    assert output == cwd
示例#9
0
def test_from_programoutput_node_extraargs():
    node = program_output()
    node['command'] = 'echo spam'
    node['use_shell'] = False
    node['hide_standard_error'] = False
    node['extraargs'] = 'with eggs'
    command = Command.from_program_output_node(node)
    assert command.command == 'echo spam with eggs'
示例#10
0
def assert_cache(cache,
                 cmd,
                 output,
                 use_shell=False,
                 hide_standard_error=False,
                 returncode=0):
    cache_key = Command(cmd, use_shell, hide_standard_error)
    assert cache == {cache_key: (returncode, output)}
示例#11
0
 def test_get_output_with_working_directory(self):
     tmpdir = tempfile.mkdtemp()
     cwd = os.path.realpath(str(tmpdir))
     returncode, output = Command(
         'python -c "import sys, os; sys.stdout.write(os.getcwd())"',
         working_directory=cwd).get_output()
     self.assertEqual(returncode, 0)
     self.assertEqual(output, cwd)
     shutil.rmtree(tmpdir)
示例#12
0
 def test_from_programoutput_node(self):
     node = program_output()
     node['command'] = 'echo spam'
     node['use_shell'] = False
     node['hide_standard_error'] = False
     node['working_directory'] = '/spam/with/eggs'
     command = Command.from_program_output_node(node)
     self.assertEqual(command.command, 'echo spam')
     self.assertEqual(command.working_directory, '/spam/with/eggs')
     self.assertFalse(command.shell)
     self.assertFalse(command.hide_standard_error)
     node['use_shell'] = True
     self.assertTrue(Command.from_program_output_node(node).shell)
     self.assertFalse(
         Command.from_program_output_node(node).hide_standard_error)
     node['hide_standard_error'] = True
     self.assertTrue(
         Command.from_program_output_node(node).hide_standard_error)
示例#13
0
 def test_from_programoutput_node_extraargs(self):
     node = program_output()
     node['command'] = 'echo spam'
     node['use_shell'] = False
     node['hide_standard_error'] = False
     node['extraargs'] = 'with eggs'
     node['working_directory'] = '/'
     command = Command.from_program_output_node(node)
     self.assertEqual(command.command, 'echo spam with eggs')
 def assert_cache(self, app, cmd, output, use_shell=False,
                  hide_standard_error=False, returncode=0,
                  working_directory=None):
     # pylint:disable=too-many-arguments
     cache = app.env.programoutput_cache
     working_directory = working_directory or app.srcdir
     working_directory = os.path.normpath(os.path.realpath(
         working_directory))
     cache_key = Command(cmd, use_shell, hide_standard_error,
                         working_directory)
     self.assertEqual(cache, {cache_key: (returncode, output)})
 def test_cache_pickled(self):
     doctreedir = self.doctreedir
     app = self.app
     cmd = Command(['echo', 'spam'])
     result = (0, 'spam')
     assert app.env.programoutput_cache[cmd] == result
     app.build()
     pickled_env_path = os.path.join(doctreedir, 'environment.pickle')
     with open(pickled_env_path, 'rb') as f:
         pickled_env = pickle.load(f)
     assert pickled_env.programoutput_cache == {cmd: result}
示例#16
0
def assert_cache(app,
                 cmd,
                 output,
                 use_shell=False,
                 hide_standard_error=False,
                 returncode=0,
                 working_directory=None):
    cache = app.env.programoutput_cache
    working_directory = working_directory or app.srcdir
    working_directory = os.path.normpath(os.path.realpath(working_directory))
    cache_key = Command(cmd, use_shell, hide_standard_error, working_directory)
    assert cache == {cache_key: (returncode, output)}
 def test_execute(self, **kwargs):
     process = Command('echo spam', **kwargs).execute()
     self.assertIsNone(process.stderr)
     self.assertFalse(process.stdout.closed)
     self.assertEqual(process.wait(), 0)
     process.stdout.close()
 def test_new_with_list_hashable(self):
     # Test that Command objects are hashable even when passed a non-hashable
     # list.  Important for caching!
     hash(Command(['echo', 'spam']))
 def test_new_with_list(self):
     cmd = Command(['echo', 'spam'])
     self.assertEqual(cmd.command, ('echo', 'spam'))
 def test_new_with_string_command(self):
     cmd = 'echo "spam with eggs"'
     parsed_cmd = ('echo', 'spam with eggs')
     self.assertEqual(Command(cmd).command, parsed_cmd)
     self.assertEqual(Command(cmd, shell=True).command, cmd)
 def test_get_output_non_zero(self):
     returncode, output = Command(
         sys.executable +
         ' -c "import sys; print(\'spam\'); sys.exit(1)"').get_output()
     self.assertEqual(returncode, 1)
     self.assertEqual(output, 'spam')
 def test_get_output(self):
     returncode, output = Command('echo spam').get_output()
     self.assertEqual(returncode, 0)
     self.assertEqual(output, 'spam')
示例#23
0
def test_new_with_list():
    cmd = Command(['echo', 'spam'])
    assert cmd.command == ('echo', 'spam')
示例#24
0
def test_get_output():
    returncode, output = Command('echo spam').get_output()
    assert returncode == 0
    assert output == 'spam'
示例#25
0
def test_execute_with_hidden_standard_error():
    process = Command('echo spam', hide_standard_error=True).execute()
    assert not process.stderr.closed
    assert process.wait() == 0
示例#26
0
def test_get_output_non_zero():
    returncode, output = Command(
        'python -c "import sys; print(\'spam\'); sys.exit(1)"').get_output()
    assert returncode == 1
    assert output == 'spam'
示例#27
0
def test_execute():
    process = Command('echo spam').execute()
    assert process.stderr is None
    assert not process.stdout.closed
    assert process.wait() == 0
示例#28
0
def test_get_output_with_hidden_standard_error():
    returncode, output = Command(
        'python -c "import sys; sys.stderr.write(\'spam\')"',
        hide_standard_error=True).get_output()
    assert returncode == 0
    assert output == ''
示例#29
0
def test_execute_with_shell():
    process = Command('echo spam', shell=True).execute()
    assert process.stderr is None
    assert not process.stdout.closed
    assert process.wait() == 0
示例#30
0
def test_new_with_string_command():
    cmd = 'echo "spam with eggs"'
    assert Command(cmd).command == cmd
    assert Command(cmd, shell=True).command == cmd