Esempio n. 1
0
    def _assert_optimization(self,
                             results_by_directory,
                             directory_to_new_results,
                             baseline_dirname='',
                             host=None):
        host = host or MockHost()
        fs = host.filesystem
        layout_tests_dir = PathFinder(fs).layout_tests_dir()
        baseline_name = 'mock-baseline-expected.txt'
        fs.write_text_file(
            fs.join(layout_tests_dir, 'VirtualTestSuites'),
            '[{"prefix": "gpu", "base": "fast/canvas", "args": ["--foo"]}]')

        for dirname, contents in results_by_directory.items():
            fs.write_binary_file(
                fs.join(layout_tests_dir, dirname, baseline_name), contents)

        baseline_optimizer = BaselineOptimizer(
            host, host.port_factory.get(), host.port_factory.all_port_names())
        self.assertTrue(
            baseline_optimizer.optimize(
                fs.join(baseline_dirname, baseline_name)))

        for dirname, contents in directory_to_new_results.items():
            path = fs.join(layout_tests_dir, dirname, baseline_name)
            if contents is not None:
                self.assertEqual(fs.read_binary_file(path), contents)
    def _assert_optimization(self, results_by_directory, directory_to_new_results, baseline_dirname=''):
        layout_tests_dir = PathFinder(self.fs).layout_tests_dir()
        test_name = 'mock-test.html'
        baseline_name = 'mock-test-expected.txt'
        self.fs.write_text_file(
            self.fs.join(layout_tests_dir, 'VirtualTestSuites'),
            '[{"prefix": "gpu", "base": "fast/canvas", "args": ["--foo"]}]')

        for dirname, contents in results_by_directory.items():
            self.fs.write_binary_file(self.fs.join(layout_tests_dir, dirname, baseline_name), contents)

        baseline_optimizer = BaselineOptimizer(self.host, self.host.port_factory.get(), self.host.port_factory.all_port_names())
        self.assertTrue(baseline_optimizer.optimize(
            self.fs.join(baseline_dirname, test_name), 'txt'))

        for dirname, contents in directory_to_new_results.items():
            path = self.fs.join(layout_tests_dir, dirname, baseline_name)
            if contents is None:
                # Check files that are explicitly marked as absent.
                self.assertFalse(self.fs.exists(path), '%s should not exist after optimization' % path)
            else:
                self.assertEqual(self.fs.read_binary_file(path), contents, 'Content of %s != "%s"' % (path, contents))

        for dirname in results_by_directory:
            path = self.fs.join(layout_tests_dir, dirname, baseline_name)
            if dirname not in directory_to_new_results or directory_to_new_results[dirname] is None:
                self.assertFalse(self.fs.exists(path), '%s should not exist after optimization' % path)