def test_init_types(self): type_set = RxTypeSet(init_types=False) type_set.init_types() for settings in RXTYPE_SETTINGS: self.assertIn(settings["name"], type_set._types) rxtype = type_set._types[settings["name"]] self.assertIsInstance(rxtype, RxType) self.assertEqual(rxtype.name, settings["name"])
def test_init_char_set(self): type_set = RxTypeSet() type_set.init_types() char_sets = CharSets(type_set) printable_subset = set(CHAR_SETS.keys()) for settings in RXWRAPPER_SETTINGS: if settings.get("is_char_set"): type_name = settings.get("rxtype_name", settings["name"]) char_set = settings.get("char_set") or CHAR_SETS[type_name] char_sets.init_char_set(type_name, printable_subset, char_set) for type_name in CHAR_SETS.keys(): self.assertIn(type_name, char_sets._char_sets) for char in CHAR_SETS[type_name]: self.assertIn(char, char_sets._char_sets[type_name])
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])