예제 #1
0
    def test_diff_image(self):
        class TestPort(ChromiumPortTest.TestLinuxPort):
            def _path_to_image_diff(self):
                return "/path/to/image_diff"

        mock_options = mocktool.MockOptions()
        port = ChromiumPortTest.TestLinuxPort(mock_options)

        mock_image_diff = "MOCK Image Diff"

        def mock_run_command(args):
            port._filesystem.write_binary_file(args[4], mock_image_diff)
            return 1

        # Images are different.
        port._executive = executive_mock.MockExecutive2(run_command_fn=mock_run_command)
        self.assertEquals(mock_image_diff, port.diff_image("EXPECTED", "ACTUAL")[0])

        # Images are the same.
        port._executive = executive_mock.MockExecutive2(exit_code=0)
        self.assertEquals(None, port.diff_image("EXPECTED", "ACTUAL")[0])

        # There was some error running image_diff.
        port._executive = executive_mock.MockExecutive2(exit_code=2)
        exception_raised = False
        try:
            port.diff_image("EXPECTED", "ACTUAL")
        except ValueError, e:
            exception_raised = True
예제 #2
0
    def test_determine_architecture_fails(self):
        # Test that we default to 'x86' if the driver doesn't exist.
        port = self.make_port()
        self.assertEqual(port.architecture(), 'x86_64')

        # Test that we default to 'x86' on an unknown architecture.
        host = MockSystemHost()
        host.filesystem.exists = lambda x: True
        host.executive = executive_mock.MockExecutive2('win32')
        port = self.make_port(host=host)
        self.assertEqual(port.architecture(), 'x86_64')

        # Test that we raise errors if something weird happens.
        host.executive = executive_mock.MockExecutive2(exception=AssertionError)
        self.assertRaises(AssertionError, linux.LinuxPort, host, '%s-foo' % self.port_name)
    def assert_architecture(self,
                            port_name=None,
                            file_output=None,
                            expected_architecture=None):
        filesystem = filesystem_mock.MockFileSystem()
        filesystem.exists = lambda x: 'DumpRenderTree' in x
        executive = None
        if file_output:
            executive = executive_mock.MockExecutive2(file_output)

        port = chromium_linux.ChromiumLinuxPort(port_name=port_name,
                                                executive=executive,
                                                filesystem=filesystem)
        self.assertEquals(port.architecture(), expected_architecture)
        if expected_architecture == 'x86':
            self.assertTrue(
                port.baseline_path().endswith('chromium-linux-x86'))
            self.assertTrue(
                port.baseline_search_path()[0].endswith('chromium-linux-x86'))
            self.assertTrue(
                port.baseline_search_path()[1].endswith('chromium-linux'))
        else:
            self.assertTrue(port.baseline_path().endswith('chromium-linux'))
            self.assertTrue(
                port.baseline_search_path()[0].endswith('chromium-linux'))
예제 #4
0
    def test_check_sys_deps(self):
        mock_options = mocktool.MockOptions()
        port = ChromiumPortTest.TestLinuxPort(options=mock_options)

        # Success
        port._executive = executive_mock.MockExecutive2(exit_code=0)
        self.assertTrue(port.check_sys_deps(needs_http=False))

        # Failure
        port._executive = executive_mock.MockExecutive2(exit_code=1,
            output='testing output failure')
        self.assertFalse(port.check_sys_deps(needs_http=False))
        self.assertLog([
            'ERROR: System dependencies check failed.\n',
            'ERROR: To override, invoke with --nocheck-sys-deps\n',
            'ERROR: \n',
            'ERROR: testing output failure\n'])
예제 #5
0
    def test_pretty_patch_script_error(self):
        # FIXME: This is some ugly white-box test hacking ...
        port = self.make_port(executive=executive_mock.MockExecutive2(exception=ScriptError))
        port._pretty_patch_available = True
        self.assertEqual(port.pretty_patch_text("patch.txt"),
                         port._pretty_patch_error_html)

        # This tests repeated calls to make sure we cache the result.
        self.assertEqual(port.pretty_patch_text("patch.txt"),
                         port._pretty_patch_error_html)
예제 #6
0
    def test_pretty_patch_os_error(self):
        port = self.make_port(executive=executive_mock.MockExecutive2(
            exception=OSError))
        with OutputCapture():
            self.assertEqual(port.pretty_patch.pretty_patch_text("patch.txt"),
                             port.pretty_patch.pretty_patch_error_html)

            # This tests repeated calls to make sure we cache the result.
            self.assertEqual(port.pretty_patch.pretty_patch_text("patch.txt"),
                             port.pretty_patch.pretty_patch_error_html)
예제 #7
0
 def assert_version_properties(self, port_name, os_version, expected_name,
                               expected_version,
                               driver_file_output=None):
     host = MockSystemHost(os_name=self.os_name, os_version=(os_version or self.os_version))
     host.filesystem.isfile = lambda x: 'content_shell' in x
     if driver_file_output:
         host.executive = executive_mock.MockExecutive2(driver_file_output)
     port = self.make_port(host=host, port_name=port_name, os_version=os_version)
     self.assertEqual(port.name(), expected_name)
     self.assertEqual(port.version(), expected_version)
예제 #8
0
    def test_pretty_patch_os_error(self):
        port = Port(executive=executive_mock.MockExecutive2(exception=OSError))
        oc = outputcapture.OutputCapture()
        oc.capture_output()
        self.assertEqual(port.pretty_patch_text("patch.txt"),
                         port._pretty_patch_error_html)

        # This tests repeated calls to make sure we cache the result.
        self.assertEqual(port.pretty_patch_text("patch.txt"),
                         port._pretty_patch_error_html)
        oc.restore_output()
예제 #9
0
    def test_determine_architecture_fails(self):
        # Test that we default to 'x86' if the driver doesn't exist.
        filesystem = filesystem_mock.MockFileSystem()
        port = chromium_linux.ChromiumLinuxPort(filesystem=filesystem)
        self.assertEquals(port.architecture(), 'x86')

        # Test that we default to 'x86' on an unknown architecture.
        filesystem = filesystem_mock.MockFileSystem()
        filesystem.exists = lambda x: True
        executive = executive_mock.MockExecutive2('win32')
        port = chromium_linux.ChromiumLinuxPort(filesystem=filesystem,
                                                executive=executive)
        self.assertEquals(port.architecture(), 'x86')

        # Test that we raise errors if something weird happens.
        filesystem = filesystem_mock.MockFileSystem()
        filesystem.exists = lambda x: True
        executive = executive_mock.MockExecutive2(exception=AssertionError)
        self.assertRaises(AssertionError, chromium_linux.ChromiumLinuxPort,
                          filesystem=filesystem, executive=executive)
예제 #10
0
 def make_config(self,
                 output='',
                 files={},
                 exit_code=0,
                 exception=None,
                 run_command_fn=None):
     e = executive_mock.MockExecutive2(output=output,
                                       exit_code=exit_code,
                                       exception=exception,
                                       run_command_fn=run_command_fn)
     fs = filesystem_mock.MockFileSystem(files)
     return config.Config(e, fs)
예제 #11
0
def main(argv=None):
    if not argv:
        argv = sys.argv

    if len(argv) == 3 and argv[1] == '--mock':
        e = executive_mock.MockExecutive2(output='foo\nfoo/%s' % argv[2])
        fs = filesystem_mock.MockFileSystem({'foo/Configuration': argv[2]})
    else:
        e = executive.Executive()
        fs = filesystem.FileSystem()

    c = config.Config(e, fs)
    print(c.default_configuration())
예제 #12
0
    def test_diff_image(self):
        class TestPort(ChromiumPortTest.TestLinuxPort):
            def _path_to_image_diff(self):
                return "/path/to/image_diff"

        mock_options = mocktool.MockOptions()
        port = ChromiumPortTest.TestLinuxPort(mock_options)

        # Images are different.
        port._executive = executive_mock.MockExecutive2(exit_code=0)
        self.assertEquals(False, port.diff_image("EXPECTED", "ACTUAL"))

        # Images are the same.
        port._executive = executive_mock.MockExecutive2(exit_code=1)
        self.assertEquals(True, port.diff_image("EXPECTED", "ACTUAL"))

        # There was some error running image_diff.
        port._executive = executive_mock.MockExecutive2(exit_code=2)
        exception_raised = False
        try:
            port.diff_image("EXPECTED", "ACTUAL")
        except ValueError, e:
            exception_raised = True
예제 #13
0
    def assert_architecture(self, port_name=None, file_output=None, expected_architecture=None):
        host = MockSystemHost()
        host.filesystem.isfile = lambda x: 'content_shell' in x
        if file_output:
            host.executive = executive_mock.MockExecutive2(file_output)

        port = self.make_port(host, port_name=port_name)
        self.assertEqual(port.architecture(), expected_architecture)
        if expected_architecture == 'x86':
            self.assertTrue(port.baseline_path().endswith('linux-x86'))
            self.assertTrue(port.baseline_search_path()[0].endswith('linux-x86'))
            self.assertTrue(port.baseline_search_path()[1].endswith('linux'))
        else:
            self.assertTrue(port.baseline_path().endswith('linux'))
            self.assertTrue(port.baseline_search_path()[0].endswith('linux'))