Пример #1
0
 def test_is_one_of_false_hierarchy(self):
     t_liquid = RxType("liquid")
     t_water = RxType("water", t_liquid)
     t_lake = RxType("lake", t_water)
     type_set = RxTypeSet()
     type_set._types = {"liquid": t_liquid}
     self.assertFalse(type_set.is_one_of("liquid", ["water", "lake"]))
Пример #2
0
 def test_is_of_false_unrelated(self):
     t_liquid = RxType("liquid")
     t_solid = RxType("solid")
     type_set = RxTypeSet()
     type_set._types = {"liquid": t_liquid, "solid": t_solid}
     self.assertFalse(type_set.is_of("solid", "liquid"))
     self.assertFalse(type_set.is_of("liquid", "solid"))
Пример #3
0
    def test_is_of_excluded(self):
        t_liquid = RxType("liquid")
        t_water = RxType("water", t_liquid)
        type_set = RxTypeSet()
        type_set._types = {"liquid": t_liquid}

        with self.assertRaises(KeyError):
            type_set.is_of("water", "liquid")
Пример #4
0
 def test_is_one_of_false_unrelated(self):
     t_liquid = RxType("liquid")
     t_solid = RxType("solid")
     t_gas = RxType("gas")
     t_plasma = RxType("plasma")
     type_set = RxTypeSet()
     type_set._types = {"plasma": t_plasma}
     self.assertFalse(
         type_set.is_one_of("plasma", ["liquid", "solid", "gas"]))
Пример #5
0
 def test_is_one_of_true(self):
     t_liquid = RxType("liquid")
     t_solid = RxType("solid")
     t_gas = RxType("gas")
     t_water = RxType("water", t_liquid)
     type_set = RxTypeSet()
     type_set._types = {"water": t_water}
     self.assertTrue(type_set.is_one_of("water",
                                        ["liquid", "solid", "gas"]))
Пример #6
0
    def test_is_of_true(self):

        t_liquid = RxType("liquid")
        t_water = RxType("water", t_liquid)
        t_lake = RxType("lake", t_water)
        type_set = RxTypeSet()
        type_set._types = {"water": t_water, "lake": t_lake}
        self.assertTrue(type_set.is_of("water", "liquid"))
        self.assertTrue(type_set.is_of("lake", "water"))
Пример #7
0
 def setUp(self):
     self.water_type = RxType("water")
     self.fire_type = RxType("fire")
     self.rxtypes = RxTypeSet()
     self.char_sets = CharSets(self.rxtypes)
     self.river_wrapper = RxWrapper("river", lambda node: "river",
                                    self.water_type)
     self.candle_wrapper = RxWrapper("candle", lambda node: "candle",
                                     self.fire_type)
Пример #8
0
 def test_is_type_true(self):
     t_liquid = RxType("liquid")
     t_water = RxType("water", t_liquid)
     t_lake = RxType("lake", t_water)
     self.assertTrue(t_water.is_type(t_liquid))
     self.assertTrue(t_lake.is_type(t_water))
     self.assertTrue(t_lake.is_type(t_liquid))
Пример #9
0
 def test_is_type_name_strict_true(self):
     t_liquid = RxType("liquid")
     t_water = RxType("water", t_liquid)
     t_lake_actual = RxType("lake", t_water)
     t_lake_painting = RxType("lake")
     self.assertTrue(t_lake_actual.is_type_name("lake", strict=True))
     self.assertTrue(t_lake_painting.is_type_name("lake", strict=True))
Пример #10
0
 def test_is_type_name_false_hierarchy(self):
     t_liquid = RxType("liquid")
     t_water = RxType("water", t_liquid)
     t_lake = RxType("lake", t_water)
     self.assertFalse(t_liquid.is_type_name("water"))
     self.assertFalse(t_liquid.is_type_name("lake"))
     self.assertFalse(t_water.is_type_name("lake"))
Пример #11
0
    def test_get_full_type_names(self):
        t_liquid = RxType("liquid")
        t_water = RxType("water", t_liquid)
        t_lake = RxType("lake", t_water)
        type_set = RxTypeSet()
        type_set._types = {
            "liquid": t_liquid,
            "water": t_water,
            "lake": t_lake
        }

        self.assertEqual(type_set.get_full_type_names("liquid"), ["liquid"])
        self.assertEqual(type_set.get_full_type_names("water"),
                         ["water", "liquid"])
        self.assertEqual(type_set.get_full_type_names("lake"),
                         ["lake", "water", "liquid"])
Пример #12
0
    def test_add(self):

        rxtype = RxType("liquid")
        type_set = RxTypeSet(init_types=False)
        type_set.add(rxtype)
        self.assertEqual(len(type_set._types), 1)
        self.assertEqual(type_set._types["liquid"], rxtype)
Пример #13
0
    def test_init_not_null_defaults(self):
        rxtype = RxType("water")
        river_wrapper = RxWrapper("River", lambda node: "River", rxtype)

        self.assertEqual(river_wrapper.child_count, 0)
        self.assertTrue(river_wrapper.is_modifiable)
        self.assertFalse(river_wrapper.strip_child_mods)
        self.assertFalse(river_wrapper.uniform_child_types)
        self.assertEqual(river_wrapper.display_function,
                         river_wrapper.compile_function)

        sea_wrapper = RxWrapper(
            "Sea",
            lambda node: "Sea",
            rxtype,
            child_types=None,
            child_count=None,
            is_modifiable=None,
            compile_function=None,
            strip_child_mods=None,
            uniform_child_types=None,
        )

        self.assertEqual(sea_wrapper.child_count, 0)
        self.assertTrue(sea_wrapper.is_modifiable)
        self.assertFalse(sea_wrapper.strip_child_mods)
        self.assertFalse(sea_wrapper.uniform_child_types)
        self.assertEqual(sea_wrapper.display_function,
                         sea_wrapper.compile_function)
Пример #14
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))
Пример #15
0
    def test_is_type_strict_false(self):

        t_liquid = RxType("liquid")
        t_solid = RxType("solid")
        t_water = RxType("water", t_liquid)
        t_lake = RxType("lake", t_water)

        self.assertFalse(t_liquid.is_type(t_water, strict=True))
        self.assertFalse(t_water.is_type(t_liquid, strict=True))

        self.assertFalse(t_water.is_type(t_lake, strict=True))
        self.assertFalse(t_lake.is_type(t_water, strict=True))

        self.assertFalse(t_liquid.is_type(t_lake, strict=True))
        self.assertFalse(t_lake.is_type(t_liquid, strict=True))

        self.assertFalse(t_liquid.is_type(t_solid, strict=True))
        self.assertFalse(t_solid.is_type(t_liquid, strict=True))

        self.assertFalse(t_solid.is_type(t_lake, strict=True))
        self.assertFalse(t_lake.is_type(t_solid, strict=True))
Пример #16
0
 def test_expand_set_whitespace(self):
     mock_node = MockNode(name="whitespace",
                          rxtype=RxType("cset"),
                          char_sets=self.char_sets)
     result = expand_set(mock_node)
     self.assertSetEqual(result, set(WHITESPACE_CHARS))
Пример #17
0
 def test_expand_set_digit(self):
     mock_node = MockNode(name="digit",
                          rxtype=RxType("cset"),
                          char_sets=self.char_sets)
     result = expand_set(mock_node)
     self.assertSetEqual(result, set(CHAR_SETS["digit"]))
Пример #18
0
    def test_getitem(self):

        rxtype = RxType("liquid")
        type_set = RxTypeSet()
        type_set._types = {"liquid": rxtype}
        self.assertEqual(type_set["liquid"], rxtype)
Пример #19
0
    def test_is_type_name_false_unrelated(self):
        t_solid = RxType("solid")
        t_liquid = RxType("liquid")
        t_water = RxType("water", t_liquid)
        t_lake = RxType("lake", t_water)

        self.assertFalse(t_liquid.is_type_name("solid"))
        self.assertFalse(t_water.is_type_name("solid"))
        self.assertFalse(t_lake.is_type_name("solid"))

        self.assertFalse(t_solid.is_type_name("liquid"))
        self.assertFalse(t_solid.is_type_name("water"))
        self.assertFalse(t_solid.is_type_name("lake"))