Ejemplo n.º 1
0
    def testExcludedItems(self):
        rc = RangeCondition(data=self.table, attr='Information')
        self.assertItemsEqual(rc.excluded_items(), [])

        rc2 = RangeCondition(data=self.table, attr='Information',
                            range=dict(min=250000, max=500000))
        excluded = set(rc.included_items()) - set(['CA', 'NY'])
        self.assertEqual(set(rc2.excluded_items()), excluded)
Ejemplo n.º 2
0
    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'])
Ejemplo n.º 3
0
    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'])
Ejemplo n.º 4
0
    def testCreation(self):
        rc = RangeCondition(data=self.table, attr='Information')
        self.assertEqual(rc.domain['min'], rc.range['min'])
        self.assertEqual(rc.domain['max'], rc.range['max'])
        self.assertEqual(rc.range['relative_max'], 1)
        self.assertEqual(rc.range['relative_min'], 0)
        self.assertEqual(set(rc.included_items()), set(self.table.index_items()))

        rc2 = RangeCondition(data=self.table, attr='Information',
                             range=dict(min=250000, max=500000))
        self.assertEqual(rc2.domain['max'], rc2.range['max'])
        self.assertEqual(250000, rc2.range['min'])
        self.assertEqual(rc2.range['relative_max'], 1)
        self.assertNotEqual(rc2.range['relative_min'], 0)
        self.assertEqual(set(rc2.included_items()), set(['CA', 'NY']))

        rc3 = RangeCondition(data=self.table, attr='Information',
                             domain=dict(min=250000, max=500000))
        self.assertEqual(rc3.domain['min'], rc3.range['min'])
        self.assertEqual(rc3.domain['max'], rc3.range['max'])
        self.assertEqual(rc3.range['relative_max'], 1)
        self.assertEqual(rc3.range['relative_min'], 0)
        self.assertEqual(set(rc3.included_items()), set(['CA', 'NY']))
Ejemplo n.º 5
0
    def testSetRange(self):
        rc = RangeCondition(data=self.table, attr='Information')
        self.assertItemsEqual(rc.included_items(), self.table.index_items())
        rc.set_range(min=250000)
        self.assertEqual(set(rc.included_items()), set(['CA', 'NY']))
        change = rc.set_range(max=250000)
        self.assertItemsEqual(rc.included_items(), [])
        self.assertEqual(change, {'included': [], 'excluded': [u'NY', u'CA']})
        with self.assertRaises(ValueError):
            rc.set_range()

        change = rc.set_range(0,1, relative=True)
        self.assertItemsEqual(rc.included_items(), self.table.index_items())
        self.assertItemsEqual(change['included'], rc.included_items())
        self.assertItemsEqual(change['excluded'], [])

        rc.set_range(0.5, relative=True)
        self.assertEqual(set(rc.included_items()), set(['CA', 'NY']))
        self.assertEqual(rc.range, {'max': 492737.0, 'min': 248347.0,
                                    'relative_max': 1.0, 'relative_min': 0.5})
Ejemplo n.º 6
0
 def testIncludedItems(self):
     rc = RangeCondition(data=self.table, attr='Information')
     self.assertEqual(set(rc.included_items()), set(self.table.index_items()))
Ejemplo n.º 7
0
 def testIncludeAll(self):
     rc = RangeCondition(data=self.table, attr='Information',
                         range=dict(min=250000, max=500000))
     self.assertEqual(set(rc.included_items()), set(['CA', 'NY']))
     rc.include_all()
     self.assertEqual(set(rc.included_items()), set(self.table.index_items()))