示例#1
0
 def set_up_using_raw_expectations(self, content):
     self._general_exp_filename = 'TestExpectations'
     self._port.host.filesystem.write_text_file(self._general_exp_filename,
                                                content)
     expectations_dict = {self._general_exp_filename: content}
     test_expectations = TestExpectations(self._port, expectations_dict)
     self._system_config_remover = SystemConfigurationRemover(
         test_expectations)
示例#2
0
    def _update_expectations_files(self, lines_to_remove):
        tests = lines_to_remove.keys()
        to_remove = defaultdict(set)
        all_versions = frozenset([config.version.lower() for config in
                                  self._tool.port_factory.get().all_test_configurations()])
        # This is so we remove lines for builders that skip this test.
        # For example, Android skips most tests and we don't want to leave
        # stray [ Android ] lines in TestExpectations.
        # This is only necessary for "blink_tool.py rebaseline".
        for port_name in self._tool.port_factory.all_port_names():
            port = self._tool.port_factory.get(port_name)
            for test in tests:
                if port.test_configuration().version.lower() in all_versions and port.skips_test(test):
                    to_remove[test].add(port.test_configuration().version.lower())

        # Get configurations to remove based on builders for each test
        for test, port_names in lines_to_remove.items():
            for port_name in port_names:
                port = self._tool.port_factory.get(port_name)
                if port.test_configuration().version.lower() in all_versions:
                    to_remove[test].add(port.test_configuration().version.lower())
        port = self._tool.port_factory.get()
        path = port.path_to_generic_test_expectations_file()
        test_expectations = TestExpectations(
            port, expectations_dict={path: self._tool.filesystem.read_text_file(path)})
        system_remover = SystemConfigurationRemover(test_expectations)
        for test, versions in to_remove.items():
            system_remover.remove_os_versions(test, versions)
        system_remover.update_expectations()
class SystemConfigurationRemoverTests(Base):
    def __init__(self, testFunc):
        super(SystemConfigurationRemoverTests, self).__init__(testFunc)
        self._port.configuration_specifier_macros_dict = {
            'mac': ['mac10.10', 'mac10.11', 'mac10.12'],
            'win': ['win7', 'win10'],
            'linux': ['precise', 'trusty']
        }

    def set_up_using_raw_expectations(self, content):
        self._general_exp_filename = self._port.host.filesystem.join(
            self._port.web_tests_dir(), 'TestExpectations')
        self._port.host.filesystem.write_text_file(self._general_exp_filename,
                                                   content)
        expectations_dict = {self._general_exp_filename: content}
        test_expectations = TestExpectations(self._port, expectations_dict)
        self._system_config_remover = SystemConfigurationRemover(
            test_expectations)

    def test_remove_mac_version_from_mac_expectation(self):
        raw_expectations = (
            '# tags: [ Mac10.10 Mac10.11 Mac10.12 Mac ]\n'
            '# results: [ Failure ]\n'
            '# Below Expectation should be split\n'
            '[ Mac ] failures/expected/text.html?\* [ Failure ]\n')
        self.set_up_using_raw_expectations(raw_expectations)
        self._system_config_remover.remove_os_versions(
            'failures/expected/text.html?*', set(['Mac10.10']))
        self._system_config_remover.update_expectations()
        updated_exps = self._port.host.filesystem.read_text_file(
            self._general_exp_filename)
        self.assertEqual(
            updated_exps,
            ('# tags: [ Mac10.10 Mac10.11 Mac10.12 Mac ]\n'
             '# results: [ Failure ]\n'
             '# Below Expectation should be split\n'
             '[ Mac10.11 ] failures/expected/text.html?\* [ Failure ]\n'
             '[ Mac10.12 ] failures/expected/text.html?\* [ Failure ]\n'))

    def test_remove_mac_version_from_linux_expectation(self):
        raw_expectations = (
            '# tags: [ Mac10.10 Mac10.11 Linux ]\n'
            '# results: [ Failure ]\n'
            '# Below Expectation should be unaffected\n'
            '[ Linux ] failures/expected/text.html [ Failure ]\n')
        self.set_up_using_raw_expectations(raw_expectations)
        self._system_config_remover.remove_os_versions(
            'failures/expected/text.html', set(['Mac10.10']))
        self._system_config_remover.update_expectations()
        updated_exps = self._port.host.filesystem.read_text_file(
            self._general_exp_filename)
        self.assertEqual(updated_exps, raw_expectations)

    def test_remove_mac_version_from_all_config_expectation(self):
        raw_expectations = (
            '# tags: [ Mac10.10 Mac10.11 Mac10.12 Mac Linux Win ]\n'
            '# results: [ Failure ]\n'
            '# Below Expectation should be split\n'
            'failures/expected/text.html [ Failure ]\n')
        self.set_up_using_raw_expectations(raw_expectations)
        self._system_config_remover.remove_os_versions(
            'failures/expected/text.html', set(['Mac10.10']))
        self._system_config_remover.update_expectations()
        updated_exps = self._port.host.filesystem.read_text_file(
            self._general_exp_filename)
        self.assertEqual(
            updated_exps,
            ('# tags: [ Mac10.10 Mac10.11 Mac10.12 Mac Linux Win ]\n'
             '# results: [ Failure ]\n'
             '# Below Expectation should be split\n'
             '[ Linux ] failures/expected/text.html [ Failure ]\n'
             '[ Mac10.11 ] failures/expected/text.html [ Failure ]\n'
             '[ Mac10.12 ] failures/expected/text.html [ Failure ]\n'
             '[ Win ] failures/expected/text.html [ Failure ]\n'))

    def test_remove_all_mac_versions_from_mac_expectation(self):
        raw_expectations = (
            '# tags: [ Mac10.10 Mac10.11 Mac10.12 Mac ]\n'
            '# results: [ Failure ]\n'
            '# The expectation below and this comment block should be deleted\n'
            '[ Mac ] failures/expected/text.html [ Failure ]\n')
        self.set_up_using_raw_expectations(raw_expectations)
        self._system_config_remover.remove_os_versions(
            'failures/expected/text.html',
            {'Mac10.10', 'Mac10.11', 'Mac10.12'})
        self._system_config_remover.update_expectations()
        updated_exps = self._port.host.filesystem.read_text_file(
            self._general_exp_filename)
        self.assertEqual(updated_exps,
                         ('# tags: [ Mac10.10 Mac10.11 Mac10.12 Mac ]\n'
                          '# results: [ Failure ]\n'))

    def test_remove_all_mac_versions_from_all_config_expectation(self):
        raw_expectations = (
            '# tags: [ Mac10.10 Mac10.11 Mac10.12 Mac Linux Win ]\n'
            '# results: [ Failure ]\n'
            '# Below Expectation should be split\n'
            'failures/expected/text.html [ Failure ]\n')
        self.set_up_using_raw_expectations(raw_expectations)
        self._system_config_remover.remove_os_versions(
            'failures/expected/text.html',
            {'Mac10.10', 'Mac10.11', 'Mac10.12'})
        self._system_config_remover.update_expectations()
        updated_exps = self._port.host.filesystem.read_text_file(
            self._general_exp_filename)
        self.assertEqual(
            updated_exps,
            ('# tags: [ Mac10.10 Mac10.11 Mac10.12 Mac Linux Win ]\n'
             '# results: [ Failure ]\n'
             '# Below Expectation should be split\n'
             '[ Linux ] failures/expected/text.html [ Failure ]\n'
             '[ Win ] failures/expected/text.html [ Failure ]\n'))

    def test_remove_all_mac_versions_from_linux_expectation(self):
        raw_expectations = (
            '# tags: [ Mac10.10 Mac10.11 Mac10.12 Mac Linux Win ]\n'
            '# results: [ Failure ]\n'
            '# Below Expectation should be unaffected\n'
            '[ Linux ] failures/expected/text.html [ Failure ]\n')
        self.set_up_using_raw_expectations(raw_expectations)
        self._system_config_remover.remove_os_versions(
            'failures/expected/text.html',
            {'Mac10.10', 'Mac10.11', 'Mac10.12'})
        self._system_config_remover.update_expectations()
        updated_exps = self._port.host.filesystem.read_text_file(
            self._general_exp_filename)
        self.assertEqual(updated_exps, raw_expectations)

    def test_remove_all_configs(self):
        raw_expectations = (
            '# tags: [ Mac10.10 Mac10.11 Mac10.12 Mac Linux Win ]\n'
            '# results: [ Failure ]\n'
            '# Below Expectation and this comment should be deleted\n'
            'failures/expected/text.html [ Failure ]\n')
        self.set_up_using_raw_expectations(raw_expectations)
        all_versions = reduce(
            lambda x, y: x + y,
            self._port.configuration_specifier_macros_dict.values())
        self._system_config_remover.remove_os_versions(
            'failures/expected/text.html', all_versions)
        self._system_config_remover.update_expectations()
        updated_exps = self._port.host.filesystem.read_text_file(
            self._general_exp_filename)
        self.assertEqual(
            updated_exps,
            ('# tags: [ Mac10.10 Mac10.11 Mac10.12 Mac Linux Win ]\n'
             '# results: [ Failure ]\n'))

    def test_remove_all_configs2(self):
        raw_expectations = (
            '# tags: [ Mac10.10 Mac10.11 Mac10.12 Mac Linux Win ]\n'
            '# results: [ Failure ]\n'
            '# Below Expectation and this comment should be deleted\n'
            '[ Mac ] failures/expected/text.html [ Failure ]\n')
        self.set_up_using_raw_expectations(raw_expectations)
        all_versions = reduce(
            lambda x, y: x + y,
            self._port.configuration_specifier_macros_dict.values())
        self._system_config_remover.remove_os_versions(
            'failures/expected/text.html', all_versions)
        self._system_config_remover.update_expectations()
        updated_exps = self._port.host.filesystem.read_text_file(
            self._general_exp_filename)
        self.assertEqual(
            updated_exps,
            ('# tags: [ Mac10.10 Mac10.11 Mac10.12 Mac Linux Win ]\n'
             '# results: [ Failure ]\n'))

    def test_remove_mac_version_from_another_mac_version_expectation(self):
        raw_expectations = (
            '# tags: [ Mac10.10 Mac10.11 Linux ]\n'
            '# results: [ Failure ]\n'
            '# Below Expectation should be unaffected\n'
            '[ Mac10.11 ] failures/expected/text.html [ Failure ]\n')
        self.set_up_using_raw_expectations(raw_expectations)
        self._system_config_remover.remove_os_versions(
            'failures/expected/text.html', set(['Mac10.10']))
        self._system_config_remover.update_expectations()
        updated_exps = self._port.host.filesystem.read_text_file(
            self._general_exp_filename)
        self.assertEqual(updated_exps, raw_expectations)

    def test_remove_mac_version_from_same_mac_version_expectation(self):
        raw_expectations = (
            '# tags: [ Mac10.10 Mac10.11 Linux ]\n'
            '# results: [ Failure ]\n'
            '# Below Expectation as well as this comment should be deleted\n'
            '[ Mac10.10 ] failures/expected/text.html [ Failure ]\n')
        self.set_up_using_raw_expectations(raw_expectations)
        self._system_config_remover.remove_os_versions(
            'failures/expected/text.html', set(['Mac10.10']))
        self._system_config_remover.update_expectations()
        updated_exps = self._port.host.filesystem.read_text_file(
            self._general_exp_filename)
        self.assertEqual(updated_exps, ('# tags: [ Mac10.10 Mac10.11 Linux ]\n'
                                        '# results: [ Failure ]\n'))