def test_error_output(self):
     '''Test error output from command'''
     cmd = BuildCommand('/bin/bash -c "echo -n FOOBAR 1>&2"')
     with cmd:
         cmd.run()
     self.assertEqual(cmd.output, "")
     self.assertEqual(cmd.error, "FOOBAR")
示例#2
0
 def test_error_output(self):
     '''Test error output from command'''
     cmd = BuildCommand('/bin/bash -c "echo -n FOOBAR 1>&2"')
     with cmd:
         cmd.run()
     self.assertEqual(cmd.output, "")
     self.assertEqual(cmd.error, "FOOBAR")
 def test_missing_command(self):
     '''Test missing command'''
     path = os.path.join('non-existant', str(uuid.uuid4()))
     self.assertFalse(os.path.exists(path))
     cmd = BuildCommand(path)
     cmd.run()
     missing_re = re.compile(r'(?:No such file or directory|not found)')
     self.assertRegexpMatches(cmd.error, missing_re)
 def test_missing_command(self):
     '''Test missing command'''
     path = os.path.join('non-existant', str(uuid.uuid4()))
     self.assertFalse(os.path.exists(path))
     cmd = BuildCommand(path)
     cmd.run()
     missing_re = re.compile(r'(?:No such file or directory|not found)')
     self.assertRegexpMatches(cmd.error, missing_re)
示例#5
0
    def test_unicode_output(self, mock_subprocess):
        """Unicode output from command"""
        mock_process = Mock(**{"communicate.return_value": (b"HérÉ îß sömê ünïçó∂é", "")})
        mock_subprocess.return_value = mock_process

        cmd = BuildCommand(["echo", "test"], cwd="/tmp/foobar")
        cmd.run()
        self.assertEqual(cmd.output, u"H\xe9r\xc9 \xee\xdf s\xf6m\xea \xfcn\xef\xe7\xf3\u2202\xe9")
示例#6
0
 def test_sanitize_output(self):
     cmd = BuildCommand(['/bin/bash', '-c', 'echo'])
     checks = (
         (b'Hola', 'Hola'),
         (b'H\x00i', 'Hi'),
         (b'H\x00i \x00\x00\x00You!\x00', 'Hi You!'),
     )
     for output, sanitized in checks:
         self.assertEqual(cmd.sanitize_output(output), sanitized)
示例#7
0
 def test_missing_command(self):
     """Test missing command."""
     path = os.path.join('non-existant', str(uuid.uuid4()))
     self.assertFalse(os.path.exists(path))
     cmd = BuildCommand(path)
     cmd.run()
     self.assertEqual(cmd.exit_code, -1)
     # There is no stacktrace here.
     self.assertIsNone(cmd.output)
     self.assertIsNone(cmd.error)
示例#8
0
    def test_result(self):
        '''Test result of output using unix true/false commands'''
        cmd = BuildCommand('true')
        with cmd:
            cmd.run()
        self.assertTrue(cmd.successful())

        cmd = BuildCommand('false')
        with cmd:
            cmd.run()
        self.assertTrue(cmd.failed())
    def test_unicode_output(self, mock_subprocess):
        """Unicode output from command."""
        mock_process = Mock(**{
            'communicate.return_value': (SAMPLE_UTF8_BYTES, b''),
        })
        mock_subprocess.return_value = mock_process

        cmd = BuildCommand(['echo', 'test'], cwd='/tmp/foobar')
        cmd.run()
        self.assertEqual(
            cmd.output,
            u'H\xe9r\xc9 \xee\xdf s\xf6m\xea \xfcn\xef\xe7\xf3\u2202\xe9')
示例#10
0
    def test_unicode_output(self, mock_subprocess):
        '''Unicode output from command'''
        mock_process = Mock(**{
            'communicate.return_value': (b'HérÉ îß sömê ünïçó∂é', ''),
        })
        mock_subprocess.return_value = mock_process

        cmd = BuildCommand(['echo', 'test'], cwd='/tmp/foobar')
        cmd.run()
        self.assertEqual(
            cmd.output,
            u'H\xe9r\xc9 \xee\xdf s\xf6m\xea \xfcn\xef\xe7\xf3\u2202\xe9')
    def test_unicode_output(self, mock_subprocess):
        '''Unicode output from command'''
        mock_process = Mock(**{
            'communicate.return_value': (SAMPLE_UTF8_BYTES, b''),
        })
        mock_subprocess.return_value = mock_process

        cmd = BuildCommand(['echo', 'test'], cwd='/tmp/foobar')
        cmd.run()
        self.assertEqual(
            cmd.output,
            u'H\xe9r\xc9 \xee\xdf s\xf6m\xea \xfcn\xef\xe7\xf3\u2202\xe9')
示例#12
0
    def test_output(self):
        """Test output command."""
        cmd = BuildCommand(['/bin/bash', '-c', 'echo -n FOOBAR'])

        # Mock BuildCommand.sanitized_output just to count the amount of calls,
        # but use the original method to behaves as real
        original_sanitized_output = cmd.sanitize_output
        with patch(
                'readthedocs.doc_builder.environments.BuildCommand.sanitize_output'
        ) as sanitize_output:  # noqa
            sanitize_output.side_effect = original_sanitized_output
            cmd.run()
            self.assertEqual(cmd.output, 'FOOBAR')

            # Check that we sanitize the output
            self.assertEqual(sanitize_output.call_count, 2)
示例#13
0
 def test_command_env(self):
     '''Test build command env vars'''
     env = {'FOOBAR': 'foobar',
            'BIN_PATH': 'foobar'}
     cmd = BuildCommand('echo', environment=env)
     for key in env.keys():
         self.assertEqual(cmd.environment[key], env[key])
示例#14
0
    def test_result(self):
        """Test result of output using unix true/false commands."""
        cmd = BuildCommand('true')
        cmd.run()
        self.assertTrue(cmd.successful)

        cmd = BuildCommand('false')
        cmd.run()
        self.assertTrue(cmd.failed)
    def test_result(self):
        '''Test result of output using unix true/false commands'''
        cmd = BuildCommand('true')
        with cmd:
            cmd.run()
        self.assertTrue(cmd.successful())

        cmd = BuildCommand('false')
        with cmd:
            cmd.run()
        self.assertTrue(cmd.failed())
 def test_error_output(self):
     '''Test error output from command'''
     # Test default combined output/error streams
     cmd = BuildCommand(['/bin/bash', '-c', 'echo -n FOOBAR 1>&2'])
     cmd.run()
     self.assertEqual(cmd.output, 'FOOBAR')
     self.assertIsNone(cmd.error)
     # Test non-combined streams
     cmd = BuildCommand(['/bin/bash', '-c', 'echo -n FOOBAR 1>&2'],
                        combine_output=False)
     cmd.run()
     self.assertEqual(cmd.output, '')
     self.assertEqual(cmd.error, 'FOOBAR')
示例#17
0
    def test_result(self):
        """Test result of output using unix true/false commands"""
        cmd = BuildCommand("true")
        cmd.run()
        self.assertTrue(cmd.successful)

        cmd = BuildCommand("false")
        cmd.run()
        self.assertTrue(cmd.failed)
示例#18
0
 def test_error_output(self):
     """Test error output from command"""
     # Test default combined output/error streams
     cmd = BuildCommand(["/bin/bash", "-c", "echo -n FOOBAR 1>&2"])
     cmd.run()
     self.assertEqual(cmd.output, "FOOBAR")
     self.assertIsNone(cmd.error)
     # Test non-combined streams
     cmd = BuildCommand(["/bin/bash", "-c", "echo -n FOOBAR 1>&2"], combine_output=False)
     cmd.run()
     self.assertEqual(cmd.output, "")
     self.assertEqual(cmd.error, "FOOBAR")
示例#19
0
 def test_error_output(self):
     """Test error output from command."""
     # Test default combined output/error streams
     cmd = BuildCommand(['/bin/bash', '-c', 'echo -n FOOBAR 1>&2'])
     cmd.run()
     self.assertEqual(cmd.output, 'FOOBAR')
     self.assertIsNone(cmd.error)
     # Test non-combined streams
     cmd = BuildCommand(['/bin/bash', '-c', 'echo -n FOOBAR 1>&2'],
                        combine_output=False)
     cmd.run()
     self.assertEqual(cmd.output, '')
     self.assertEqual(cmd.error, 'FOOBAR')
示例#20
0
 def test_output(self):
     """Test output command."""
     cmd = BuildCommand(['/bin/bash', '-c', 'echo -n FOOBAR'])
     cmd.run()
     self.assertEqual(cmd.output, 'FOOBAR')
示例#21
0
 def test_output(self):
     """Test output command"""
     cmd = BuildCommand(["/bin/bash", "-c", "echo -n FOOBAR"])
     cmd.run()
     self.assertEqual(cmd.output, "FOOBAR")
 def test_output(self):
     '''Test output command'''
     cmd = BuildCommand(['/bin/bash', '-c', 'echo -n FOOBAR'])
     cmd.run()
     self.assertEqual(cmd.output, "FOOBAR")
 def test_input(self):
     '''Test input to command'''
     cmd = BuildCommand('/bin/cat', input_data='FOOBAR')
     cmd.run()
     self.assertEqual(cmd.output, 'FOOBAR')
示例#24
0
 def test_input(self):
     '''Test input to command'''
     cmd = BuildCommand('/bin/cat')
     with cmd:
         cmd.run(cmd_input="FOOBAR")
     self.assertEqual(cmd.output, "FOOBAR")
示例#25
0
 def test_output(self):
     '''Test output command'''
     cmd = BuildCommand(['/bin/bash',
                         '-c', 'echo -n FOOBAR'])
     cmd.run()
     self.assertEqual(cmd.output, "FOOBAR")
示例#26
0
 def test_input(self):
     '''Test input to command'''
     cmd = BuildCommand('/bin/cat', input_data='FOOBAR')
     cmd.run()
     self.assertEqual(cmd.output, 'FOOBAR')
示例#27
0
 def test_output(self):
     '''Test output command'''
     cmd = BuildCommand('/bin/bash -c "echo -n FOOBAR"')
     with cmd:
         cmd.run()
     self.assertEqual(cmd.output, "FOOBAR")
示例#28
0
 def test_output(self):
     """Test output command."""
     cmd = BuildCommand(['/bin/bash', '-c', 'echo -n FOOBAR'])
     cmd.run()
     self.assertEqual(cmd.output, 'FOOBAR')
 def test_input(self):
     '''Test input to command'''
     cmd = BuildCommand('/bin/cat')
     with cmd:
         cmd.run(cmd_input="FOOBAR")
     self.assertEqual(cmd.output, "FOOBAR")
示例#30
0
 def test_input(self):
     """Test input to command"""
     cmd = BuildCommand("/bin/cat", input_data="FOOBAR")
     cmd.run()
     self.assertEqual(cmd.output, "FOOBAR")
示例#31
0
 def test_error_output(self):
     """Test error output from command."""
     cmd = BuildCommand(['/bin/bash', '-c', 'echo -n FOOBAR 1>&2'])
     cmd.run()
     self.assertEqual(cmd.output, 'FOOBAR')
     self.assertIsNone(cmd.error)
 def test_output(self):
     '''Test output command'''
     cmd = BuildCommand('/bin/bash -c "echo -n FOOBAR"')
     with cmd:
         cmd.run()
     self.assertEqual(cmd.output, "FOOBAR")