Esempio n. 1
0
 def test_sort_rules(self):
     sorter = ConfigBasedRuleSetSorter(
         ["CasterRule", "Navigation", "Alphabet"])
     a = Alphabet()
     c = CasterRule()
     n = Navigation()
     rules = [a, c, n]
     sorted_rules = sorter.sort_rules(rules)
     self.assertEqual(0, sorted_rules.index(c))
     self.assertEqual(1, sorted_rules.index(n))
     self.assertEqual(2, sorted_rules.index(a))
Esempio n. 2
0
    def _remerge_ccr_rules(self, enabled_rcns):
        """
        :return: RulesEnabledDiff
        """
        # if the global ccr toggle was off, activating a ccr rule turns it back on
        self._ccr_toggle.set_active(True)

        # handle CCR: get all active ccr rules after de/activating one
        loaded_enabled_rcns = set(self._managed_rules.keys())
        active_rule_class_names = [rcn for rcn in enabled_rcns if rcn in loaded_enabled_rcns]
        active_mrs = [self._managed_rules[rcn] for rcn in active_rule_class_names]
        active_ccr_mrs = [mr for mr in active_mrs if mr.get_details().declared_ccrtype is not None]

        '''
        The merge may result in 1 to n+1 rules where n is the number of ccr app rules
        which are in the active rules list.
        For instance, if you have 1 app rule, you'll end up with two ccr rules. This is because
        the merger has to make the global one, plus an app rule with the app stuff plus all the
        global stuff.
        '''
        sorter = ConfigBasedRuleSetSorter(enabled_rcns)
        merge_result = self._merger.merge_rules(active_ccr_mrs, sorter)
        grammars = []
        for rule_and_context in merge_result.ccr_rules_and_contexts:
            rule = rule_and_context[0]
            context = rule_and_context[1]
            grammar = Grammar(name="ccr-" + GrammarManager._get_next_id(), context=context)
            grammar.add_rule(rule)
            grammars.append(grammar)
        self._grammars_container.set_ccr(grammars)
        for grammar in grammars:
            grammar.load()

        return merge_result.rules_enabled_diff
Esempio n. 3
0
 def setUp(self):
     self._set_setting(["miscellaneous", "max_ccr_repetitions"], "4")
     self.selfmodrule_configurer = Mock()
     self.transformers_config = Mock()
     self.sorter = ConfigBasedRuleSetSorter(["Alphabet", "Navigation", "EclipseCCR", "VSCodeCcrRule"])
     self.transformers_runner = TransformersRunner(self.transformers_config)
     self.merger = Nexus._create_merger(self.selfmodrule_configurer, self.transformers_runner)
Esempio n. 4
0
    def test_merge_two_incompatible(self):
        """
        Merger KOs the earlier incompatible rule and leaves the later one.
        """
        sorter = ConfigBasedRuleSetSorter(["FakeRuleOne", "FakeRuleTwo"])
        self.merger = Nexus._create_merger(self.selfmodrule_configurer, self.transformers_runner)

        java_mr = TestCCRMerger2._create_managed_rule(FakeRuleOne, CCRType.GLOBAL)
        python_mr = TestCCRMerger2._create_managed_rule(FakeRuleTwo, CCRType.GLOBAL)
        result = self.merger.merge_rules([java_mr, python_mr], sorter)

        rule = self._extract_merged_rule_from_repeatrule(result.ccr_rules_and_contexts)
        self.assertIn("two exclusive", rule._mapping)
        self.assertNotIn("one exclusive", rule._mapping)