Example #1
0
 def test_create_wrapper_defaults_invalid_char_set(self):
     wrappers = RxWrapperSet(self.char_sets, init_wrappers=False)
     with self.assertRaises(TypeError):
         wrappers.create_wrapper("test",
                                 "re",
                                 display_value="X",
                                 is_char_set=True)
Example #2
0
    def test_create_wrapper_full(self):
        data = {
            "name": "test",
            "rxtype_name": "re",
            "child_types": ["alpha_lower", "digit"],
            "child_count": 3,
            "is_modifiable": False,
            "strip_child_mods": True,
            "uniform_child_types": True,
            "display_function_name": "or",
            "compile_function_name": "or",
        }
        wrappers = RxWrapperSet(self.char_sets, init_wrappers=False)
        wrapper = wrappers.create_wrapper(**data)
        mock_node = MockNode(children=[
            MockNode(_d("f"), _d("f")),
            MockNode(_d("j"), _d("j")),
        ])

        self.assertEqual(wrapper.name, data["name"])
        self.assertEqual(wrapper.rxtype.name, data["rxtype_name"])
        self.assertEqual(wrapper.child_types, data["child_types"])
        self.assertEqual(wrapper.child_count, data["child_count"])
        self.assertFalse(wrapper.is_modifiable)
        self.assertTrue(wrapper.strip_child_mods)
        self.assertTrue(wrapper.uniform_child_types)
        self.assertEqual(wrapper.display_function(mock_node), d_or(mock_node))
        self.assertIn(wrapper.compile_function(mock_node), ["f", "j"])
Example #3
0
    def test_create_wrapper_defaults(self):
        wrappers = RxWrapperSet(self.char_sets, init_wrappers=False)
        wrapper = wrappers.create_wrapper("test", "re", display_value="X")

        self.assertEqual(wrapper.child_types, None)
        self.assertEqual(wrapper.child_count, 0)
        self.assertTrue(wrapper.is_modifiable)
        self.assertFalse(wrapper.strip_child_mods)
        self.assertFalse(wrapper.uniform_child_types)
Example #4
0
 def test_create_wrapper_format_char_set_name_with_value(self):
     wrappers = RxWrapperSet(self.char_sets, init_wrappers=False)
     data = {
         "name": "digit",
         "rxtype_name": "digit",
         "is_char_set": True,
         "char_value": "5",
     }
     wrapper = wrappers.create_wrapper(**data)
     self.assertEqual(wrapper.name, "digit(5)")
Example #5
0
    def test_create_wrapper_compile_function_from_display_value_only(self):
        wrappers = RxWrapperSet(self.char_sets, init_wrappers=False)
        data = {
            "name": "test",
            "display_value": "X",
            "rxtype_name": "re",
        }

        wrapper = wrappers.create_wrapper(**data)
        self.assertEqual(wrapper.compile_function(None), data["display_value"])
Example #6
0
    def test_create_wrapper_defaults_func_name(self):
        wrappers = RxWrapperSet(self.char_sets, init_wrappers=False)
        set_wrapper = wrappers.create_wrapper("set", "re")
        mock_node = MockNode(children=[
            MockNode(_d("a"), _d("a"), rxtype=RxType("test")),
        ], )

        self.assertEqual(set_wrapper.display_function(mock_node),
                         d_set(mock_node))
        self.assertEqual(set_wrapper.compile_function(mock_node),
                         c_set(mock_node))
Example #7
0
    def test_create_wrapper_explicit_compile_function_name(self):
        wrappers = RxWrapperSet(self.char_sets, init_wrappers=False)
        data = {
            "name": "empty!term",
            "display_value": r"\B",
            "rxtype_name": "cset*",
            "compile_function_name": "empty",
        }

        wrapper = wrappers.create_wrapper(**data)
        c_func = rxwrapper_functions["compile"][data["compile_function_name"]]
        self.assertEqual(wrapper.compile_function(None), c_func(None))
Example #8
0
 def test_create_wrapper_defaults_invalid_function(self):
     wrappers = RxWrapperSet(self.char_sets, init_wrappers=False)
     with self.assertRaises(TypeError):
         wrappers.create_wrapper("test", "re")