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"])
def test_init_char_set_empty_subset(self): type_set = RxTypeSet() type_set.init_types() char_sets = CharSets(type_set) type_name = "alphanum" full_type_names = set(type_set.get_full_type_names(type_name)) printable_subset = set() char_set = CHAR_SETS[type_name] char_sets.init_char_set(type_name, printable_subset, char_set) # no characters should be activated from type name character set for char in char_set: for name in full_type_names: if name in char_sets._char_sets: self.assertNotIn(char, char_sets._char_sets[name])
def test_init_char_set_full_subset(self): type_set = RxTypeSet() type_set.init_types() char_sets = CharSets(type_set) type_name = "alphanum" full_type_names = set(type_set.get_full_type_names(type_name)) printable_subset = set(CHAR_SETS.keys()) char_set = CHAR_SETS[type_name] char_sets.init_char_set(type_name, printable_subset, char_set) # all related type names should contain all characters in alphanum char set for char in char_set: for name in full_type_names: # only evaluate those type names that represent actual printable character sets if name in char_sets._char_sets: self.assertIn(char, char_sets._char_sets[name])
def test_init_char_set_partial_subset(self): type_set = RxTypeSet() type_set.init_types() char_sets = CharSets(type_set) type_names = ["digit", "alpha_lower", "alpha_upper"] printable_subset = set(["digit", "alpha_upper"]) # Initialise character sets for type_name in type_names: char_set = CHAR_SETS[type_name] char_sets.init_char_set(type_name, printable_subset, char_set) # Search through all specified type names for type_name in type_names: # Confirm that type name is present in charsets self.assertIn(type_name, char_sets._char_sets) # Get the full list of character set type names that the current type name inherits from (inluding itself) full_type_names = list( filter( lambda name: name in char_sets._char_sets, type_set.get_full_type_names(type_name), )) # For all characters in the character set corresponding to the current type name for char in CHAR_SETS[type_name]: # For all the character set types it inherits from (including itself) for name in full_type_names: # If the current type name is in the printable subset, it should be activated within the charset if type_name in printable_subset: self.assertIn(char, char_sets._char_sets[name]) # If the current type name is not in the printable subset, it should be excluded from the charset else: self.assertNotIn(char, char_sets._char_sets[name])