def test_hasunknowngender(self): """ Test HasUnknownGender rule. """ rule = HasUnknownGender([]) self.assertEqual( self.filter_with_rule(rule), set([ b'OJOKQC83Y1EDBIMLJ6', b'8BHKQCFK9UZFRJYC2Y', b'PGFKQC1TUQMXFAMLMB', b'IHOKQCECRZYQDKW6KF', b'8HKKQCTEJAOBVH410L', b'AGFKQCO358R18LNJYV', b'1ENKQCBPFZTAQJSP4O', b'NUWKQCO7TVAOH0CHLV', b'P5IKQC88STY3FNTFZ3', b'7GXKQCMVFU8WR1LKZL', b'LGXKQCJ5OP6MKF9QLN', b'XNFKQC6DN59LACS9IU', b'7IOKQC1NVGUI1E55CQ', b'57PKQCFAWY7AM3JS4M', b'BNXKQCEBXC1RCOGJNF', b'TFFKQC1RMG8RRADKDH', b'FHKKQC963NGSY18ZDZ', b'WMXKQCDUJ4JKQQYCR7', b'PBHKQCHOAGTECRKT9L', b'OFXKQC8W0N3N6JP6YQ', ]))
def get_filter(self): """ Extracts the text strings from the sidebar, and uses them to build up a new filter. """ # extract text values from the entry widgets name = extract_text(self.filter_name) gid = extract_text(self.filter_id) birth = extract_text(self.filter_birth) death = extract_text(self.filter_death) note = extract_text(self.filter_note) # extract remaining data from the menus etype = self.filter_event.get_type().xml_str() gender = self.filter_gender.get_active() regex = self.filter_regex.get_active() tag = self.tag.get_active() > 0 generic = self.generic.get_active() > 0 # check to see if the filter is empty. If it is empty, then # we don't build a filter empty = not (name or gid or birth or death or etype or note or gender or regex or tag or generic) if empty: generic_filter = None else: # build a GenericFilter generic_filter = GenericFilter() # if the name is not empty, choose either the regular expression # version or the normal text match if name: rule = RegExpName([name], use_regex=regex) generic_filter.add_rule(rule) # if the id is not empty, choose either the regular expression # version or the normal text match if gid: rule = RegExpIdOf([gid], use_regex=regex) generic_filter.add_rule(rule) # check the gender, and select the right rule based on gender if gender > 0: if gender == 1: generic_filter.add_rule(IsMale([])) elif gender == 2: generic_filter.add_rule(IsFemale([])) else: generic_filter.add_rule(HasUnknownGender([])) # Build an event filter if needed if etype: rule = HasEvent([etype, '', '', '', '', True], use_regex=regex) generic_filter.add_rule(rule) # Build birth event filter if needed # Arguments for the HasBirth filter are Date, Place, and Description # Since the value we extracted to the "birth" variable is the # request date, we pass it as the first argument if birth: rule = HasBirth([birth, '', '']) generic_filter.add_rule(rule) # Build death event filter if needed if death: rule = HasDeath([death, '', '']) generic_filter.add_rule(rule) # Build note filter if needed if note: rule = HasNoteRegexp([note], use_regex=regex) generic_filter.add_rule(rule) # check the Tag if tag: model = self.tag.get_model() node = self.tag.get_active_iter() attr = model.get_value(node, 0) rule = HasTag([attr]) generic_filter.add_rule(rule) if self.generic.get_active() != 0: model = self.generic.get_model() node = self.generic.get_active_iter() obj = str(model.get_value(node, 0)) rule = MatchesFilter([obj]) generic_filter.add_rule(rule) return generic_filter