Exemplo n.º 1
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")
Exemplo n.º 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")
Exemplo n.º 3
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()
     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)
Exemplo n.º 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")
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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())
Exemplo n.º 9
0
    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')
Exemplo n.º 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')
Exemplo n.º 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)
Exemplo n.º 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])
Exemplo n.º 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)
Exemplo n.º 15
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_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')
Exemplo n.º 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)
Exemplo n.º 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")
Exemplo n.º 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')
Exemplo n.º 20
0
 def test_output(self):
     """Test output command."""
     cmd = BuildCommand(['/bin/bash', '-c', 'echo -n FOOBAR'])
     cmd.run()
     self.assertEqual(cmd.output, 'FOOBAR')
Exemplo n.º 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')
Exemplo n.º 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")
Exemplo n.º 25
0
 def test_output(self):
     '''Test output command'''
     cmd = BuildCommand(['/bin/bash',
                         '-c', 'echo -n FOOBAR'])
     cmd.run()
     self.assertEqual(cmd.output, "FOOBAR")
Exemplo n.º 26
0
 def test_input(self):
     '''Test input to command'''
     cmd = BuildCommand('/bin/cat', input_data='FOOBAR')
     cmd.run()
     self.assertEqual(cmd.output, 'FOOBAR')
Exemplo n.º 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")
Exemplo n.º 28
0
 def test_output(self):
     """Test output command."""
     cmd = BuildCommand(['/bin/bash', '-c', 'echo -n FOOBAR'])
     cmd.run()
     self.assertEqual(cmd.output, 'FOOBAR')
Exemplo n.º 29
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")
Exemplo n.º 30
0
 def test_input(self):
     """Test input to command"""
     cmd = BuildCommand("/bin/cat", input_data="FOOBAR")
     cmd.run()
     self.assertEqual(cmd.output, "FOOBAR")
Exemplo n.º 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)
Exemplo n.º 32
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")