Ejemplo n.º 1
0
    def test_replace_real_mergerule_spec(self):
        trt = TextReplacerTransformer(mock_TRParser.MockTRParser)
        rule = Navigation()
        mock_TRParser.MOCK_SPECS["clear"] = "bear"
        transformed_rule = trt.get_transformed_rule(rule)

        self.assertTrue("bear [<nnavi50>]" in transformed_rule._mapping)
    def test_replace_mergerule_spec(self):
        parser_fn = _create_mock_parser(specs={"some": "a few"})
        trt = TextReplacerTransformer(parser_fn)
        rule = _TestMergeRule()
        transformed_rule = trt.get_transformed_rule(rule)

        self.assertTrue("a few <text>" in transformed_rule._mapping.keys())
Ejemplo n.º 3
0
    def test_replace_mergerule_spec(self):
        trt = TextReplacerTransformer(mock_TRParser.MockTRParser)
        rule = _TestMergeRule()
        mock_TRParser.MOCK_SPECS["some"] = "a few"
        transformed_rule = trt.get_transformed_rule(rule)

        self.assertTrue("a few <text>" in transformed_rule._mapping.keys())
    def test_replace_real_mergerule_spec(self):
        parser_fn = _create_mock_parser(specs={"cut": "but"})
        trt = TextReplacerTransformer(parser_fn)
        rule = Navigation()
        transformed_rule = trt.get_transformed_rule(rule)

        self.assertTrue("but [<nnavi500>]" in transformed_rule._mapping)
Ejemplo n.º 5
0
    def test_replace_real_mergerule_extra(self):
        trt = TextReplacerTransformer(mock_TRParser.MockTRParser)
        rule = Alphabet()
        mock_TRParser.MOCK_EXTRAS["goof"] = "gas"
        transformed_rule = trt.get_transformed_rule(rule)

        self.assertTrue("gas" in transformed_rule._extras["letter"]._choices)
        self.assertEqual("g",
                         transformed_rule._extras["letter"]._choices["gas"])
    def test_replace_real_mergerule_extra(self):
        parser_fn = _create_mock_parser(extras={"goof": "gas"})
        trt = TextReplacerTransformer(parser_fn)
        rule = Alphabet()
        transformed_rule = trt.get_transformed_rule(rule)

        self.assertTrue("gas" in transformed_rule._extras["letter"]._choices)
        self.assertEqual("g",
                         transformed_rule._extras["letter"]._choices["gas"])
Ejemplo n.º 7
0
    def test_replace_mergerule_extra(self):
        trt = TextReplacerTransformer(mock_TRParser.MockTRParser)
        rule = _TestMergeRule()
        mock_TRParser.MOCK_EXTRAS["element"] = "ornament"
        transformed_rule = trt.get_transformed_rule(rule)

        self.assertTrue(
            "ornament" in transformed_rule._extras["choice"]._choices)
        self.assertEqual(
            "e", transformed_rule._extras["choice"]._choices["ornament"])
    def test_replace_mergerule_extra(self):
        parser_fn = _create_mock_parser(extras={"element": "ornament"})
        trt = TextReplacerTransformer(parser_fn)
        rule = _TestMergeRule()
        transformed_rule = trt.get_transformed_rule(rule)

        self.assertTrue(
            "ornament" in transformed_rule._extras["choice"]._choices)
        self.assertEqual(
            "e", transformed_rule._extras["choice"]._choices["ornament"])
    def test_remove_required_extra(self):
        """
        The user should not be allowed to remove a required extra.
        """
        parser_fn = _create_mock_parser(specs={"some <text>": "just some"})
        trt = TextReplacerTransformer(parser_fn)
        rule = _TestMappingRule()
        transformed_rule = trt.get_transformed_rule(rule)

        self.assertTrue("some <text>" in transformed_rule._mapping.keys())
    def test_remove_optional_extra(self):
        """
        The user should be allowed to remove an optional extra.
        """
        parser_fn = _create_mock_parser(
            specs={"other [<choice>]": "just other"})
        trt = TextReplacerTransformer(parser_fn)
        rule = _TestMappingRule()
        transformed_rule = trt.get_transformed_rule(rule)

        self.assertTrue("just other" in transformed_rule._mapping.keys())
Ejemplo n.º 11
0
    def test_that_transformer_does_not_change_class_name(self):
        trt = TextReplacerTransformer(mock_TRParser.MockTRParser)
        mock_TRParser.MOCK_SPECS["some"] = "any"

        rule1 = _TestMappingRule()
        rule2 = _TestMergeRule()

        transformed_rule1 = trt.get_transformed_rule(rule1)
        self.assertEqual("_TestMappingRule",
                         transformed_rule1.__class__.__name__)
        transformed_rule2 = trt.get_transformed_rule(rule2)
        self.assertEqual("_TestMergeRule",
                         transformed_rule2.__class__.__name__)
    def test_that_transformer_does_not_change_class_name(self):
        parser_fn = _create_mock_parser(specs={"some": "any"})
        trt = TextReplacerTransformer(parser_fn)

        rule1 = _TestMappingRule()
        rule2 = _TestMergeRule()

        transformed_rule1 = trt.get_transformed_rule(rule1)
        self.assertEqual("_TestMappingRule",
                         transformed_rule1.__class__.__name__)
        transformed_rule2 = trt.get_transformed_rule(rule2)
        self.assertEqual("_TestMergeRule",
                         transformed_rule2.__class__.__name__)
Ejemplo n.º 13
0
    def test_words_txt_transformer(self):
        """
        Merger should use TextReplacerTransformer to replace "clear" with "bear" in specs
        and "goof" with "gas" in extras.
        """
        # transformer setup
        self.transformers_config.is_transformer_active.side_effect = [
            True, True
        ]
        trt = TextReplacerTransformer(mock_TRParser.MockTRParser)
        mock_TRParser.MOCK_SPECS["clear"] = "bear"
        mock_TRParser.MOCK_EXTRAS["goof"] = "gas"
        self.transformers_runner._transformers.append(trt)

        # rule setup
        alphabet_mr = TestCCRMerger2._create_managed_rule(
            Alphabet, CCRType.GLOBAL)
        navigation_mr = TestCCRMerger2._create_managed_rule(
            Navigation, CCRType.GLOBAL)
        result = self.merger.merge_rules([alphabet_mr, navigation_mr],
                                         self.sorter)

        self.assertEqual(1, len(result.ccr_rules_and_contexts))

        rule = self._extract_merged_rule_from_repeatrule(
            result.ccr_rules_and_contexts)
        self.assertTrue("bear [<nnavi50>]" in rule._mapping.keys())
        self.assertTrue("gas" in rule._extras["letter"]._choices)
Ejemplo n.º 14
0
    def test_words_txt_transformer(self):
        """
        Merger should use TextReplacerTransformer to replace "cut" with "but" in specs
        and "goof" with "gas" in extras.
        """
        # transformer setup
        self.transformers_config.is_transformer_active.side_effect = [True, True]
        def parser_fn(): return MockTRParser(specs={"cut": "but"}, extras={"goof": "gas"}, defaults={})
        trt = TextReplacerTransformer(parser_fn)
        self.transformers_runner._transformers.append(trt)

        # rule setup
        alphabet_mr = TestCCRMerger2._create_managed_rule(Alphabet, CCRType.GLOBAL)
        navigation_mr = TestCCRMerger2._create_managed_rule(Navigation, CCRType.GLOBAL)
        result = self.merger.merge_rules([alphabet_mr, navigation_mr], self.sorter)

        self.assertEqual(1, len(result.ccr_rules_and_contexts))

        rule = self._extract_merged_rule_from_repeatrule(result.ccr_rules_and_contexts)
        self.assertTrue("but [<nnavi500>]" in rule._mapping.keys())
        self.assertTrue("gas" in rule._extras["letter"]._choices)