def testEnablingChanges(self): cs = ConditionSet(name='condition_set', data=self.table, setop='AND') cc = CategoricalCondition(data=self.table, attr='fake_cat') rc = RangeCondition(data=self.table, attr='Information') rc.set_range(0.5, relative=True) cs.add_condition(cc) cc.add_category('C1') self.assertItemsEqual(cs.reference, self.fake_sets['C1']) cc.disable() print cs.query, cs.reference self.assertItemsEqual(cs.reference, []) cs.add_condition(rc) self.assertItemsEqual(cs.reference, ['CA', 'NY']) rc.enable(False) cc.enable() self.assertItemsEqual(cs.reference, self.fake_sets['C1']) cc.toggle_category(['C1', 'C3']) rc.enable() self.assertItemsEqual(cs.reference, ['NY']) rc.set_range(0, 1, relative=True) self.assertItemsEqual(cs.reference, self.fake_sets['C3'])
def testExcludedItems(self): cc = CategoricalCondition(data=self.table, attr='fake_cat') cc.add_category(['C2', 'C3', 'C4']) self.assertSetEqual(set(cc.excluded_items()), set(['AK', 'CA', 'DE', 'IA', 'KS', 'MD', 'MO', 'ND', 'NM', 'OK', 'SC', 'UT', 'WI'])) cc.add_category('C1') self.assertSetEqual(set(cc.excluded_items()), set([]))
def testToggleItem(self): cc = CategoricalCondition(data=self.table, attr='fake_cat') cc.add_category(['C1', 'C3']) cc.toggle_category('C1') cc.toggle_category('C2') self.assertEqual(set(cc.included_categories()), set(['C3', 'C2'])) cc.toggle_category(['C2','C4']) self.assertEqual(set(cc.included_categories()), set(['C3', 'C4']))
def testRemoveCondition(self): cs = ConditionSet(name='condition_set', data=self.table, setop='AND') cc = CategoricalCondition(data=self.table, attr='fake_cat') cs.add_condition(cc) cc.add_category('C1') self.assertItemsEqual(cs.reference, self.fake_sets['C1']) cs.remove_condition(cc) self.assertEqual(cs.reference, [])
def testAddCondition(self): cs = ConditionSet(name='condition_set', data=self.table, setop='AND') cc = CategoricalCondition(data=self.table, attr='fake_cat') cs.add_condition(cc) cc.add_category('C1') self.assertItemsEqual(cs.reference, self.fake_sets['C1']) cc.add_category(['C1', 'C3']) c1_and_c3 = self.fake_sets['C1'][:] c1_and_c3 += self.fake_sets['C3'] self.assertItemsEqual(cs.reference, c1_and_c3)
def testAddSeveralConditions(self): cs = ConditionSet(name='condition_set', data=self.table, setop='AND') cc = CategoricalCondition(data=self.table, attr='fake_cat') rc = RangeCondition(data=self.table, attr='Information') rc.set_range(0.5, relative=True) cs.add_condition(cc) cc.add_category('C1') self.assertItemsEqual(cs.reference, self.fake_sets['C1']) cs.add_condition(rc) self.assertItemsEqual(cs.reference, ['CA']) cc.toggle_category(['C1', 'C3']) self.assertItemsEqual(cs.reference, ['NY']) rc.set_range(0, 1, relative=True) self.assertItemsEqual(cs.reference, self.fake_sets['C3'])
def testExcludeAll(self): cc = CategoricalCondition(data=self.table, attr='fake_cat') cc.add_category('C1') cc.exclude_all() self.assertEqual(cc.included_categories(),[])
def testRemove(self): cc = CategoricalCondition(data=self.table, attr='fake_cat') cc.add_category(['C1', 'C3']) cc.remove_category('C1') self.assertEqual(set(cc.included_categories()), set(['C3']))