def test_empty_sets(self): type_set = RxTypeSet() char_sets = CharSets(type_set) for key in char_sets._char_sets.keys(): char_sets._char_sets[key].add("a") char_sets._char_sets[key].add("b") char_sets._char_sets[key].add("c") self.assertEqual(len(char_sets._char_sets[key]), 3) char_sets.empty_sets() self.assertEqual(len(char_sets._char_sets), len(CHAR_SETS.keys())) for key in char_sets._char_sets.keys(): self.assertEqual(len(char_sets._char_sets[key]), 0)
def __init__(self, printable_subset: Optional[Iterable[str]] = None) -> None: self.omit_types: Set[str] = set() self.omit_wrappers: Set[str] = set() self._rxtypes = RxTypeSet() self._char_sets = CharSets(self._rxtypes) self._rxwrappers = RxWrapperSet(self._char_sets, printable_subset)
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 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)
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 __init__( self, char_sets: CharSets, printable_subset: Optional[Iterable[str]] = None, init_wrappers: bool = True, ) -> None: self._wrappers: Dict[str, RxWrapper] = {} self._char_sets: CharSets = char_sets self._rxtypes: RxTypeSet = char_sets.rxtypes() if init_wrappers: self.init_wrappers(printable_subset)
def test_init(self): type_set = RxTypeSet() char_sets = CharSets(type_set) self.assertEqual(len(char_sets._char_sets), len(CHAR_SETS.keys())) for key in CHAR_SETS.keys(): self.assertIn(key, char_sets._char_sets) self.assertIsInstance(char_sets._char_sets[key], set) self.assertEqual(len(char_sets._char_sets[key]), 0) self.assertEqual(type_set, char_sets._rxtypes)
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])
def setUp(self): self.rxtypes = RxTypeSet() self.char_sets = CharSets(self.rxtypes) self.rxwrappers = RxWrapperSet(self.char_sets)
def test_rxtypes(self): type_set = RxTypeSet() char_sets = CharSets(type_set) result = char_sets.rxtypes() self.assertEqual(result, type_set)
def test_contains_false(self): type_set = RxTypeSet() char_sets = CharSets(type_set) self.assertFalse("INVALID_KEY" in char_sets) self.assertNotIn("INVALID_KEY", char_sets)
def test_contains_true(self): type_set = RxTypeSet() char_sets = CharSets(type_set) for key in CHAR_SETS.keys(): self.assertTrue(key in char_sets) self.assertIn(key, char_sets)
def test_getitem(self): type_set = RxTypeSet() char_sets = CharSets(type_set) for key in CHAR_SETS.keys(): self.assertIsInstance(char_sets[key], set)