def test_number_conversion(self): # hexadecimal self.assertTrue(RowQuery.parse("affected>0x01").match_row(self.row)) # exponential notation self.assertTrue(RowQuery.parse("affected<1.0e+06").match_row(self.row)) # whitespace self.assertTrue(RowQuery.parse("inneed>400").match_row(self.row)) self.assertTrue(RowQuery.parse("inneed<600").match_row(self.row))
def test_dates(self): # = self.assertTrue(RowQuery.parse("date=2015-12-13").match_row(self.row)) self.assertFalse(RowQuery.parse("date=2015-12-12").match_row(self.row)) # <= self.assertTrue(RowQuery.parse("date<=2015-12-13").match_row(self.row)) self.assertFalse(RowQuery.parse("date<=2015-12-12").match_row(self.row)) # < self.assertTrue(RowQuery.parse("date<2015-12-14").match_row(self.row)) self.assertFalse(RowQuery.parse("date<2015-12-13").match_row(self.row)) # >= self.assertTrue(RowQuery.parse("date>=2015-12-13").match_row(self.row)) self.assertFalse(RowQuery.parse("date>=2015-12-14").match_row(self.row)) # > self.assertTrue(RowQuery.parse("date>2015-12-12").match_row(self.row)) self.assertFalse(RowQuery.parse("date>2015-12-13").match_row(self.row))
def test_numbers(self): """Test that we're doing numeric rather than lexical comparison""" # = self.assertTrue(RowQuery.parse("affected=200").match_row(self.row)) self.assertFalse(RowQuery.parse("affected=300").match_row(self.row)) # <= self.assertTrue(RowQuery.parse("affected<=200").match_row(self.row)) self.assertFalse(RowQuery.parse("affected<=199").match_row(self.row)) # < self.assertTrue(RowQuery.parse("affected<1000").match_row(self.row)) self.assertFalse(RowQuery.parse("affected<100").match_row(self.row)) # >= self.assertTrue(RowQuery.parse("affected>=200").match_row(self.row)) self.assertFalse(RowQuery.parse("affected>=201").match_row(self.row)) # > self.assertTrue(RowQuery.parse("affected>9").match_row(self.row)) self.assertFalse(RowQuery.parse("affected>900").match_row(self.row))
def test_is_max(self): source = hxl.data(self.AGGREGATE_DATA).cache() query = RowQuery.parse('#affected is max') self.assertTrue(query.needs_aggregate) query.calc_aggregate(source) self.assertEquals('300', query.value) for row in source: if query.match_row(row): self.assertEqual(300, float(row.get('#affected'))) else: self.assertNotEqual(300, float(row.get('#affected')))
def test_is_max(self): source = hxl.data(self.AGGREGATE_DATA).cache() query = RowQuery.parse('#affected is max') self.assertTrue(query.needs_aggregate) query.calc_aggregate(source) self.assertEqual('300', query.value) for row in source: if query.match_row(row): self.assertEqual(300, float(row.get('#affected'))) else: self.assertNotEqual(300, float(row.get('#affected')))
def test_whitespace(self): self.assertTrue(RowQuery.parse("adm1=coast").match_row(self.row))
def test_string(self): # = self.assertTrue(RowQuery.parse("sector=WASH").match_row(self.row)) self.assertTrue(RowQuery.parse("sector=wash").match_row(self.row)) self.assertFalse(RowQuery.parse("sector=Health").match_row(self.row)) # <= self.assertTrue(RowQuery.parse("sector<=WASH").match_row(self.row)) self.assertTrue(RowQuery.parse("sector<=wash").match_row(self.row)) self.assertFalse(RowQuery.parse("sector<=Health").match_row(self.row)) # < self.assertTrue(RowQuery.parse("sector<ZZZ").match_row(self.row)) self.assertTrue(RowQuery.parse("sector<zzz").match_row(self.row)) self.assertFalse(RowQuery.parse("sector<WASH").match_row(self.row)) self.assertFalse(RowQuery.parse("sector<wash").match_row(self.row)) # >= self.assertTrue(RowQuery.parse("sector>=WASH").match_row(self.row)) self.assertTrue(RowQuery.parse("sector>=wash").match_row(self.row)) self.assertFalse(RowQuery.parse("sector>=ZZZ").match_row(self.row)) self.assertFalse(RowQuery.parse("sector>=zzz").match_row(self.row)) # > self.assertTrue(RowQuery.parse("sector>AAA").match_row(self.row)) self.assertTrue(RowQuery.parse("sector>aaa").match_row(self.row)) self.assertFalse(RowQuery.parse("sector>WASH").match_row(self.row)) self.assertFalse(RowQuery.parse("sector>wash").match_row(self.row)) # ~ self.assertTrue(RowQuery.parse("sector~^W").match_row(self.row)) self.assertTrue(RowQuery.parse("sector~W").match_row(self.row)) self.assertTrue(RowQuery.parse("sector~AS").match_row(self.row)) self.assertTrue(RowQuery.parse("sector~sh$").match_row(self.row)) self.assertFalse(RowQuery.parse("sector~W$").match_row(self.row)) self.assertFalse(RowQuery.parse("sector~AS$").match_row(self.row)) # !~ self.assertTrue(RowQuery.parse("sector!~^A").match_row(self.row)) self.assertTrue(RowQuery.parse("sector!~X").match_row(self.row)) self.assertTrue(RowQuery.parse("sector!~W$").match_row(self.row)) self.assertFalse(RowQuery.parse("sector!~w").match_row(self.row)) self.assertFalse(RowQuery.parse("sector !~ w").match_row(self.row)) # is empty self.assertTrue( RowQuery.parse("sector is not empty").match_row(self.row)) self.assertFalse(RowQuery.parse("sector is empty").match_row(self.row)) # is number self.assertTrue( RowQuery.parse("sector is not number").match_row(self.row)) self.assertFalse( RowQuery.parse("sector is number").match_row(self.row)) # is date self.assertTrue( RowQuery.parse("sector is not date").match_row(self.row)) self.assertFalse(RowQuery.parse("sector is date").match_row(self.row))
def test_numbers(self): """Test that we're doing numeric rather than lexical comparison""" # = self.assertTrue(RowQuery.parse("affected=200").match_row(self.row)) self.assertFalse(RowQuery.parse("affected=300").match_row(self.row)) # <= self.assertTrue(RowQuery.parse("affected<=200").match_row(self.row)) self.assertFalse(RowQuery.parse("affected<=199").match_row(self.row)) # < self.assertTrue(RowQuery.parse("affected<1000").match_row(self.row)) self.assertFalse(RowQuery.parse("affected<100").match_row(self.row)) # >= self.assertTrue(RowQuery.parse("affected>=200").match_row(self.row)) self.assertFalse(RowQuery.parse("affected>=201").match_row(self.row)) # > self.assertTrue(RowQuery.parse("affected>9").match_row(self.row)) self.assertFalse(RowQuery.parse("affected>900").match_row(self.row)) # is (not) number self.assertTrue(RowQuery.parse("affected is number").match_row(self.row)) self.assertFalse(RowQuery.parse("affected is not number").match_row(self.row))
def test_dates(self): # = self.assertTrue(RowQuery.parse("date=2015-12-13").match_row(self.row)) self.assertFalse(RowQuery.parse("date=2015-12-12").match_row(self.row)) # <= self.assertTrue(RowQuery.parse("date<=2015-12-13").match_row(self.row)) self.assertFalse(RowQuery.parse("date<=2015-12-12").match_row(self.row)) # < self.assertTrue(RowQuery.parse("date<2015-12-14").match_row(self.row)) self.assertFalse(RowQuery.parse("date<2015-12-13").match_row(self.row)) # >= self.assertTrue(RowQuery.parse("date>=2015-12-13").match_row(self.row)) self.assertFalse(RowQuery.parse("date>=2015-12-14").match_row(self.row)) # > self.assertTrue(RowQuery.parse("date>2015-12-12").match_row(self.row)) self.assertFalse(RowQuery.parse("date>2015-12-13").match_row(self.row)) # is (not) date self.assertTrue(RowQuery.parse("date is date").match_row(self.row)) self.assertFalse(RowQuery.parse("date is not date").match_row(self.row))
def test_string(self): # = self.assertTrue(RowQuery.parse("sector=WASH").match_row(self.row)) self.assertTrue(RowQuery.parse("sector=wash").match_row(self.row)) self.assertFalse(RowQuery.parse("sector=Health").match_row(self.row)) # <= self.assertTrue(RowQuery.parse("sector<=WASH").match_row(self.row)) self.assertTrue(RowQuery.parse("sector<=wash").match_row(self.row)) self.assertFalse(RowQuery.parse("sector<=Health").match_row(self.row)) # < self.assertTrue(RowQuery.parse("sector<ZZZ").match_row(self.row)) self.assertTrue(RowQuery.parse("sector<zzz").match_row(self.row)) self.assertFalse(RowQuery.parse("sector<WASH").match_row(self.row)) self.assertFalse(RowQuery.parse("sector<wash").match_row(self.row)) # >= self.assertTrue(RowQuery.parse("sector>=WASH").match_row(self.row)) self.assertTrue(RowQuery.parse("sector>=wash").match_row(self.row)) self.assertFalse(RowQuery.parse("sector>=ZZZ").match_row(self.row)) self.assertFalse(RowQuery.parse("sector>=zzz").match_row(self.row)) # > self.assertTrue(RowQuery.parse("sector>AAA").match_row(self.row)) self.assertTrue(RowQuery.parse("sector>aaa").match_row(self.row)) self.assertFalse(RowQuery.parse("sector>WASH").match_row(self.row)) self.assertFalse(RowQuery.parse("sector>wash").match_row(self.row)) # ~ self.assertTrue(RowQuery.parse("sector~^W").match_row(self.row)) self.assertTrue(RowQuery.parse("sector~W").match_row(self.row)) self.assertTrue(RowQuery.parse("sector~AS").match_row(self.row)) self.assertTrue(RowQuery.parse("sector~sh$").match_row(self.row)) self.assertFalse(RowQuery.parse("sector~W$").match_row(self.row)) self.assertFalse(RowQuery.parse("sector~AS$").match_row(self.row)) # !~ self.assertTrue(RowQuery.parse("sector!~^A").match_row(self.row)) self.assertTrue(RowQuery.parse("sector!~X").match_row(self.row)) self.assertTrue(RowQuery.parse("sector!~W$").match_row(self.row)) self.assertFalse(RowQuery.parse("sector!~w").match_row(self.row)) self.assertFalse(RowQuery.parse("sector !~ w").match_row(self.row)) # is empty self.assertTrue(RowQuery.parse("sector is not empty").match_row(self.row)) self.assertFalse(RowQuery.parse("sector is empty").match_row(self.row)) # is number self.assertTrue(RowQuery.parse("sector is not number").match_row(self.row)) self.assertFalse(RowQuery.parse("sector is number").match_row(self.row)) # is date self.assertTrue(RowQuery.parse("sector is not date").match_row(self.row)) self.assertFalse(RowQuery.parse("sector is date").match_row(self.row))