Esempio n. 1
0
class MockDRTPort(object):
    """MockPort implementation of the Port interface."""
    def __init__(self, host, **kwargs):
        prefix = 'mock-'
        if 'port_name' in kwargs:
            kwargs['port_name'] = kwargs['port_name'][len(prefix):]
        self._host = host
        self.__delegate = PortFactory(host).get(**kwargs)
        self.__real_name = prefix + self.__delegate.name()

    def real_name(self):
        return self.__real_name

    def __getattr__(self, name):
        return getattr(self.__delegate, name)

    def check_build(self, needs_http):
        return True

    def check_sys_deps(self, needs_http):
        return True

    def driver_cmd_line(self):
        driver = self.create_driver(0)
        return driver.cmd_line()

    def _path_to_driver(self):
        return self._host.filesystem.abspath(__file__)

    def create_driver(self, worker_number):
        # We need to create a driver object as the delegate would, but
        # overwrite the path to the driver binary in its command line. We do
        # this by actually overwriting its cmd_line() method with a proxy
        # method that splices in the mock_drt path and command line arguments
        # in place of the actual path to the driver binary.

        def overriding_cmd_line():
            cmd = self.__original_driver_cmd_line()
            index = cmd.index(self.__delegate._path_to_driver())
            # FIXME: Why does this need to use sys.executable (instead of something mockable)?
            cmd[index:index + 1] = [
                sys.executable,
                self._path_to_driver(), '--platform',
                self.name()
            ]
            return cmd

        delegated_driver = self.__delegate.create_driver(worker_number)
        self.__original_driver_cmd_line = delegated_driver.cmd_line
        delegated_driver.cmd_line = overriding_cmd_line
        return delegated_driver

    def start_helper(self):
        pass

    def start_http_server(self):
        pass

    def start_websocket_server(self):
        pass

    def acquire_http_lock(self):
        pass

    def stop_helper(self):
        pass

    def stop_http_server(self):
        pass

    def stop_websocket_server(self):
        pass

    def release_http_lock(self):
        pass
Esempio n. 2
0
class MockDRTPort(object):
    port_name = 'mock'

    @classmethod
    def determine_full_port_name(cls, host, options, port_name):
        return port_name

    def __init__(self, host, port_name, **kwargs):
        self.__delegate = PortFactory(host).get(port_name.replace('mock-', ''), **kwargs)
        self.__delegate_driver_class = self.__delegate._driver_class
        self.__delegate._driver_class = types.MethodType(self._driver_class, self.__delegate)

    def __getattr__(self, name):
        return getattr(self.__delegate, name)

    def check_build(self, needs_http, printer):
        return True

    def check_sys_deps(self, needs_http):
        return True

    def _driver_class(self, delegate):
        return self._mocked_driver_maker

    def _mocked_driver_maker(self, port, worker_number, pixel_tests, no_timeout=False):
        path_to_this_file = self.host.filesystem.abspath(__file__.replace('.pyc', '.py'))
        driver = self.__delegate_driver_class()(self, worker_number, pixel_tests, no_timeout)
        driver.cmd_line = self._overriding_cmd_line(driver.cmd_line,
                                                    self.__delegate._path_to_driver(),
                                                    sys.executable,
                                                    path_to_this_file,
                                                    self.__delegate.name())
        return driver

    @staticmethod
    def _overriding_cmd_line(original_cmd_line, driver_path, python_exe, this_file, port_name):
        def new_cmd_line(pixel_tests, per_test_args):
            cmd_line = original_cmd_line(pixel_tests, per_test_args)
            index = cmd_line.index(driver_path)
            cmd_line[index:index + 1] = [python_exe, this_file, '--platform', port_name]
            return cmd_line

        return new_cmd_line

    def start_helper(self):
        pass

    def start_http_server(self, number_of_servers):
        pass

    def start_websocket_server(self):
        pass

    def acquire_http_lock(self):
        pass

    def stop_helper(self):
        pass

    def stop_http_server(self):
        pass

    def stop_websocket_server(self):
        pass

    def release_http_lock(self):
        pass

    def _make_wdiff_available(self):
        self.__delegate._wdiff_available = True

    def setup_environ_for_server(self, server_name):
        env = self.__delegate.setup_environ_for_server()
        # We need to propagate PATH down so the python code can find the checkout.
        env['PATH'] = os.environ['PATH']
        return env

    def lookup_virtual_test_args(self, test_name):
        suite = self.__delegate.lookup_virtual_suite(test_name)
        return suite.args + ['--virtual-test-suite-name', suite.name, '--virtual-test-suite-base', suite.base]
Esempio n. 3
0
class MockDRTPort(object):
    port_name = 'mock'

    @classmethod
    def determine_full_port_name(cls, host, options, port_name):
        return port_name

    def __init__(self, host, port_name, **kwargs):
        self.__delegate = PortFactory(host).get(port_name.replace('mock-', ''),
                                                **kwargs)
        self.__delegate_driver_class = self.__delegate._driver_class
        self.__delegate._driver_class = types.MethodType(
            self._driver_class, self.__delegate)

    def __getattr__(self, name):
        return getattr(self.__delegate, name)

    def check_build(self, needs_http, printer):
        return test_run_results.OK_EXIT_STATUS

    def check_sys_deps(self, needs_http):
        return test_run_results.OK_EXIT_STATUS

    def _driver_class(self, delegate):
        return self._mocked_driver_maker

    def _mocked_driver_maker(self,
                             port,
                             worker_number,
                             pixel_tests,
                             no_timeout=False):
        path_to_this_file = self.host.filesystem.abspath(
            __file__.replace('.pyc', '.py'))
        driver = self.__delegate_driver_class()(self, worker_number,
                                                pixel_tests, no_timeout)
        driver.cmd_line = self._overriding_cmd_line(
            driver.cmd_line, self.__delegate._path_to_driver(), sys.executable,
            path_to_this_file, self.__delegate.name())
        return driver

    @staticmethod
    def _overriding_cmd_line(original_cmd_line, driver_path, python_exe,
                             this_file, port_name):
        def new_cmd_line(pixel_tests, per_test_args):
            cmd_line = original_cmd_line(pixel_tests, per_test_args)
            index = cmd_line.index(driver_path)
            cmd_line[index:index +
                     1] = [python_exe, this_file, '--platform', port_name]
            return cmd_line

        return new_cmd_line

    def start_helper(self):
        pass

    def start_http_server(self, additional_dirs, number_of_servers):
        pass

    def start_websocket_server(self):
        pass

    def acquire_http_lock(self):
        pass

    def stop_helper(self):
        pass

    def stop_http_server(self):
        pass

    def stop_websocket_server(self):
        pass

    def release_http_lock(self):
        pass

    def _make_wdiff_available(self):
        self.__delegate._wdiff_available = True

    def setup_environ_for_server(self):
        env = self.__delegate.setup_environ_for_server()
        # We need to propagate PATH down so the python code can find the checkout.
        env['PATH'] = os.environ['PATH']
        return env

    def lookup_virtual_test_args(self, test_name):
        suite = self.__delegate.lookup_virtual_suite(test_name)
        return suite.args + [
            '--virtual-test-suite-name', suite.name,
            '--virtual-test-suite-base', suite.base
        ]

    def lookup_virtual_reference_args(self, test_name):
        suite = self.__delegate.lookup_virtual_suite(test_name)
        return suite.reference_args + [
            '--virtual-test-suite-name', suite.name,
            '--virtual-test-suite-base', suite.base
        ]
Esempio n. 4
0
class MockDRTPort(object):
    """MockPort implementation of the Port interface."""

    def __init__(self, host, **kwargs):
        prefix = "mock-"
        if "port_name" in kwargs:
            kwargs["port_name"] = kwargs["port_name"][len(prefix) :]
        self._host = host
        self.__delegate = PortFactory(host).get(**kwargs)
        self.__real_name = prefix + self.__delegate.name()

    def real_name(self):
        return self.__real_name

    def __getattr__(self, name):
        return getattr(self.__delegate, name)

    def check_build(self, needs_http):
        return True

    def check_sys_deps(self, needs_http):
        return True

    def driver_cmd_line(self):
        driver = self.create_driver(0)
        return driver.cmd_line()

    def _path_to_driver(self):
        return self._host.filesystem.abspath(__file__)

    def create_driver(self, worker_number):
        # We need to create a driver object as the delegate would, but
        # overwrite the path to the driver binary in its command line. We do
        # this by actually overwriting its cmd_line() method with a proxy
        # method that splices in the mock_drt path and command line arguments
        # in place of the actual path to the driver binary.

        def overriding_cmd_line():
            cmd = self.__original_driver_cmd_line()
            index = cmd.index(self.__delegate._path_to_driver())
            # FIXME: Why does this need to use sys.executable (instead of something mockable)?
            cmd[index : index + 1] = [sys.executable, self._path_to_driver(), "--platform", self.name()]
            return cmd

        delegated_driver = self.__delegate.create_driver(worker_number)
        self.__original_driver_cmd_line = delegated_driver.cmd_line
        delegated_driver.cmd_line = overriding_cmd_line
        return delegated_driver

    def start_helper(self):
        pass

    def start_http_server(self):
        pass

    def start_websocket_server(self):
        pass

    def acquire_http_lock(self):
        pass

    def stop_helper(self):
        pass

    def stop_http_server(self):
        pass

    def stop_websocket_server(self):
        pass

    def release_http_lock(self):
        pass
Esempio n. 5
0
class MockDRTPort(object):
    """MockPort implementation of the Port interface."""
    port_name = 'mock'

    @classmethod
    def determine_full_port_name(cls, host, options, port_name):
        """Return a fully-specified port name that can be used to construct objects."""
        # Subclasses will usually override this.
        return port_name

    def __init__(self, host, port_name, **kwargs):
        self.__delegate = PortFactory(host).get(port_name.replace('mock-', ''), **kwargs)
        self.__real_name = port_name
        self._host = host

    def real_name(self):
        return self.__real_name

    def __getattr__(self, name):
        return getattr(self.__delegate, name)

    def check_build(self, needs_http):
        return True

    def check_sys_deps(self, needs_http):
        return True

    def driver_cmd_line(self):
        driver = self.create_driver(0)
        return driver.cmd_line()

    def _path_to_driver(self):
        return self._host.filesystem.abspath(__file__)

    def create_driver(self, worker_number):
        # We need to create a driver object as the delegate would, but
        # overwrite the path to the driver binary in its command line. We do
        # this by actually overwriting its cmd_line() method with a proxy
        # method that splices in the mock_drt path and command line arguments
        # in place of the actual path to the driver binary.

        def overriding_cmd_line():
            cmd = self.__original_driver_cmd_line()
            index = cmd.index(self.__delegate._path_to_driver())
            # FIXME: Why does this need to use sys.executable (instead of something mockable)?
            cmd[index:index + 1] = [sys.executable, self._path_to_driver(), '--platform', self.name()]
            return cmd

        delegated_driver = self.__delegate.create_driver(worker_number)
        self.__original_driver_cmd_line = delegated_driver.cmd_line
        delegated_driver.cmd_line = overriding_cmd_line
        return delegated_driver

    def start_helper(self):
        pass

    def start_http_server(self):
        pass

    def start_websocket_server(self):
        pass

    def acquire_http_lock(self):
        pass

    def stop_helper(self):
        pass

    def stop_http_server(self):
        pass

    def stop_websocket_server(self):
        pass

    def release_http_lock(self):
        pass
Esempio n. 6
0
class MockDRTPort(object):
    """MockPort implementation of the Port interface."""
    port_name = 'mock'

    @classmethod
    def determine_full_port_name(cls, host, options, port_name):
        """Return a fully-specified port name that can be used to construct objects."""
        # Subclasses will usually override this.
        return port_name

    def __init__(self, host, port_name, **kwargs):
        self.__delegate = PortFactory(host).get(port_name.replace('mock-', ''),
                                                **kwargs)
        self.__real_name = port_name
        self._host = host

    def real_name(self):
        return self.__real_name

    def __getattr__(self, name):
        return getattr(self.__delegate, name)

    def check_build(self, needs_http):
        return True

    def check_sys_deps(self, needs_http):
        return True

    def driver_cmd_line(self):
        driver = self.create_driver(0)
        return driver.cmd_line()

    def _path_to_driver(self):
        return self._host.filesystem.abspath(__file__)

    def create_driver(self, worker_number):
        # We need to create a driver object as the delegate would, but
        # overwrite the path to the driver binary in its command line. We do
        # this by actually overwriting its cmd_line() method with a proxy
        # method that splices in the mock_drt path and command line arguments
        # in place of the actual path to the driver binary.

        def overriding_cmd_line():
            cmd = self.__original_driver_cmd_line()
            index = cmd.index(self.__delegate._path_to_driver())
            # FIXME: Why does this need to use sys.executable (instead of something mockable)?
            cmd[index:index + 1] = [
                sys.executable,
                self._path_to_driver(), '--platform',
                self.name()
            ]
            return cmd

        delegated_driver = self.__delegate.create_driver(worker_number)
        self.__original_driver_cmd_line = delegated_driver.cmd_line
        delegated_driver.cmd_line = overriding_cmd_line
        return delegated_driver

    def start_helper(self):
        pass

    def start_http_server(self):
        pass

    def start_websocket_server(self):
        pass

    def acquire_http_lock(self):
        pass

    def stop_helper(self):
        pass

    def stop_http_server(self):
        pass

    def stop_websocket_server(self):
        pass

    def release_http_lock(self):
        pass