Example #1
0
    def test_matching(self):
        daff = Daffodil("""
        {
           "MHQ9ProgsWatched - BornSurvivor" = "no"
           "MHQ9ProgsWatched - WheelerDealers" = "no"
           "MHQ9ProgsWatched - FifthGear" = "no"
           "MHQ9ProgsWatched - AuctionHunters" = "no"
           "MHQ9ProgsWatched - MythBusters" = "no"
           "MHQ9ProgsWatched - GoldRush" = "no"
           "MHQ9ProgsWatched - DeadliestCatch" = "no"
           "MHQ9ProgsWatched - FastNLoud" = "no"
           "MHQ9ProgsWatched - SonsOfGuns" = "no"
           "MHQ9ProgsWatched - AmericanChopper" = "no"
        }
        """)
        self.assertTrue(daff.predicate(self.data))

        daff = Daffodil("""{
           "MHQ9ProgsWatched - BornSurvivor" = 'no'
           "MHQ9ProgsWatched - WheelerDealers" = 'no'
           "MHQ9ProgsWatched - FifthGear" = 'no'
           "MHQ9ProgsWatched - AuctionHunters" = 'no'
           "MHQ9ProgsWatched - MythBusters" = 'no'
           "MHQ9ProgsWatched - GoldRush" = 'no'
           "MHQ9ProgsWatched - DeadliestCatch" = 'no'
           "MHQ9ProgsWatched - FastNLoud" = 'no'
           "MHQ9ProgsWatched - SonsOfGuns" = 'no'
           "MHQ9ProgsWatched - AmericanChopper" = 'no'
        }""")
        self.assertTrue(daff.predicate({
           'MHQ9ProgsWatched - PawnStars': 'yes', 'MHQ3Gender': 'Female', 'MHQ9ProgsWatched - FastNLoud': 'no', 'MHQ8ChannelViewing - Discovery Channel': 'OncePerWeek', 'MHQ8ChannelViewing - National Geographic': 'OncePerWeek', '_sample_id': 'frutest3', 'MHQ4TVProvider - YouView': 'no', 'MHQ6Industry - MarketResearch': 'no', 'MHQ6Industry - Entertainment': 'no', 'MHQ5TVViewing': '1-3nights', 'MHQ8ChannelViewing - ITV1': 'OncePerWeek', 'MHQ7PastParticipant': 'No', 'MHQ9ProgsWatched - StorageWars': 'yes', 'MHQ8ChannelViewing - History Channel': 'OncePerWeek', 'MHQ8ChannelViewing - BBC2': 'OncePerWeek', 'MHQ1Confidential': 'Yes', 'MHQ4TVProvider - Freeview': 'no', 'MHQ9ProgsWatched - BornSurvivor': 'no', 'MHQ9ProgsWatched - WheelerDealers': 'no', 'MHQ8ChannelViewing - Channel4': 'OncePerWeek', 'MHQ4TVProvider - IPTV': 'no', 'MHQ9ProgsWatched - AuctionHunters': 'no', 'MHQ9ProgsWatched - AirCrashInvestigation': 'no', 'MHQ8ChannelViewing - Sky Arts': 'OncePerWeek', 'MHQ2Age': '18-34', 'MHQ8ChannelViewing - BBC1': 'OncePerWeek', 'MHQ6Industry - None': 'yes', 'MHQ4TVProvider - None': 'no', 'MHQ6Industry - RadioTV': 'no', 'MHQ6Industry - Advertising': 'no', 'MHQ9ProgsWatched - DeadliestCatch': 'no', 'MHQ9ProgsWatched - FifthGear': 'no', 'MHQ9ProgsWatched - TopGear': 'no', 'MHQ9ProgsWatched - SonsOfGuns': 'no', 'MHQ9ProgsWatched - WickedTuna': 'no', 'MHQ9ProgsWatched - GoldRush': 'no', 'MHQ9ProgsWatched - MythBusters': 'no', 'MHQ6Industry - Press': 'no', 'MHQ4TVProvider - Virgin': 'yes', '_id': '41298', 'MHQ9ProgsWatched - AmericanPickers': 'no', 'MHQ9ProgsWatched - AmericanChopper': 'no', 'MHQ4TVProvider - Sky': 'no'
        }))
Example #2
0
    def test_not_matching(self):
        daff = Daffodil("""
        {
           "MHQ9ProgsWatched - MythBusters" = "yes"
           "MHQ9ProgsWatched - BornSurvivor" = "no"
           "MHQ9ProgsWatched - WheelerDealers" = "no"
           "MHQ9ProgsWatched - FifthGear" = "no"
           "MHQ9ProgsWatched - AuctionHunters" = "no"
           "MHQ9ProgsWatched - GoldRush" = "no"
           "MHQ9ProgsWatched - DeadliestCatch" = "no"
           "MHQ9ProgsWatched - FastNLoud" = "no"
           "MHQ9ProgsWatched - SonsOfGuns" = "no"
           "MHQ9ProgsWatched - AmericanChopper" = "no"
        }
        """)

        self.assertFalse(daff.predicate(self.data))
Example #3
0
 def assert_daffodil_expectations(self,
                                  dafltr,
                                  present=set(),
                                  omitted=set()):
     daff = Daffodil(dafltr, delegate=KeyExpectationDelegate())
     daff_expected_present, daff_expected_omitted = daff.predicate
     self.assertEqual(daff_expected_present, present)
     self.assertEqual(daff_expected_omitted, omitted)
Example #4
0
    def test_not_matching(self):
        daff = Daffodil("""
        {
           "MHQ9ProgsWatched - MythBusters" = "yes"
           "MHQ9ProgsWatched - BornSurvivor" = "no"
           "MHQ9ProgsWatched - WheelerDealers" = "no"
           "MHQ9ProgsWatched - FifthGear" = "no"
           "MHQ9ProgsWatched - AuctionHunters" = "no"
           "MHQ9ProgsWatched - GoldRush" = "no"
           "MHQ9ProgsWatched - DeadliestCatch" = "no"
           "MHQ9ProgsWatched - FastNLoud" = "no"
           "MHQ9ProgsWatched - SonsOfGuns" = "no"
           "MHQ9ProgsWatched - AmericanChopper" = "no"
        }
        """)

        self.assertFalse(daff.predicate(self.data))
Example #5
0
    def test_matching(self):
        daff = Daffodil("""
        {
           "MHQ9ProgsWatched - BornSurvivor" = "no"
           "MHQ9ProgsWatched - WheelerDealers" = "no"
           "MHQ9ProgsWatched - FifthGear" = "no"
           "MHQ9ProgsWatched - AuctionHunters" = "no"
           "MHQ9ProgsWatched - MythBusters" = "no"
           "MHQ9ProgsWatched - GoldRush" = "no"
           "MHQ9ProgsWatched - DeadliestCatch" = "no"
           "MHQ9ProgsWatched - FastNLoud" = "no"
           "MHQ9ProgsWatched - SonsOfGuns" = "no"
           "MHQ9ProgsWatched - AmericanChopper" = "no"
        }
        """)
        self.assertTrue(daff.predicate(self.data))

        daff = Daffodil(u"""{
           "MHQ9ProgsWatched - BornSurvivor" = 'no'
           "MHQ9ProgsWatched - WheelerDealers" = 'no'
           "MHQ9ProgsWatched - FifthGear" = 'no'
           "MHQ9ProgsWatched - AuctionHunters" = 'no'
           "MHQ9ProgsWatched - MythBusters" = 'no'
           "MHQ9ProgsWatched - GoldRush" = 'no'
           "MHQ9ProgsWatched - DeadliestCatch" = 'no'
           "MHQ9ProgsWatched - FastNLoud" = 'no'
           "MHQ9ProgsWatched - SonsOfGuns" = 'no'
           "MHQ9ProgsWatched - AmericanChopper" = 'no'
        }""")
        self.assertTrue(daff.predicate({
           u'MHQ9ProgsWatched - PawnStars': u'yes', u'MHQ3Gender': u'Female', u'MHQ9ProgsWatched - FastNLoud': u'no', u'MHQ8ChannelViewing - Discovery Channel': u'OncePerWeek', u'MHQ8ChannelViewing - National Geographic': u'OncePerWeek', '_sample_id': u'frutest3', u'MHQ4TVProvider - YouView': u'no', u'MHQ6Industry - MarketResearch': u'no', u'MHQ6Industry - Entertainment': u'no', u'MHQ5TVViewing': u'1-3nights', u'MHQ8ChannelViewing - ITV1': u'OncePerWeek', u'MHQ7PastParticipant': u'No', u'MHQ9ProgsWatched - StorageWars': u'yes', u'MHQ8ChannelViewing - History Channel': u'OncePerWeek', u'MHQ8ChannelViewing - BBC2': u'OncePerWeek', u'MHQ1Confidential': u'Yes', u'MHQ4TVProvider - Freeview': u'no', u'MHQ9ProgsWatched - BornSurvivor': u'no', u'MHQ9ProgsWatched - WheelerDealers': u'no', u'MHQ8ChannelViewing - Channel4': u'OncePerWeek', u'MHQ4TVProvider - IPTV': u'no', u'MHQ9ProgsWatched - AuctionHunters': u'no', u'MHQ9ProgsWatched - AirCrashInvestigation': u'no', u'MHQ8ChannelViewing - Sky Arts': u'OncePerWeek', u'MHQ2Age': u'18-34', u'MHQ8ChannelViewing - BBC1': u'OncePerWeek', u'MHQ6Industry - None': u'yes', u'MHQ4TVProvider - None': u'no', u'MHQ6Industry - RadioTV': u'no', u'MHQ6Industry - Advertising': u'no', u'MHQ9ProgsWatched - DeadliestCatch': u'no', u'MHQ9ProgsWatched - FifthGear': u'no', u'MHQ9ProgsWatched - TopGear': u'no', u'MHQ9ProgsWatched - SonsOfGuns': u'no', u'MHQ9ProgsWatched - WickedTuna': u'no', u'MHQ9ProgsWatched - GoldRush': u'no', u'MHQ9ProgsWatched - MythBusters': u'no', u'MHQ6Industry - Press': u'no', u'MHQ4TVProvider - Virgin': u'yes', '_id': '41298', u'MHQ9ProgsWatched - AmericanPickers': u'no', u'MHQ9ProgsWatched - AmericanChopper': u'no', u'MHQ4TVProvider - Sky': u'no'
        }))
Example #6
0
 def test_keys(self):
     daff = Daffodil("""
     {
       "k1" = "no"
       [
         k2 = 1.7
         k3 > 5
       ]
       [
         "k4" ?= true
         "k5" = "words"
       ]
     }
     """)
     self.assertEqual(daff.keys, set(["k1", "k2", "k3", "k4", "k5"]))
Example #7
0
def validate_daffodil_fltr(value):
    try:
        Daffodil(value)
    except ParseError, e:
        raise ValidationError("Invalid Daffodil filter. %s" % str(e))
Example #8
0
 def filter(self, daff_src):
     delegate = HStoreQueryDelegate(hstore_field_name="hsdata")
     daff = Daffodil(daff_src, delegate=delegate)
     return daff(self.d)
Example #9
0
 def pp(self, fltr):
     dense = Daffodil(fltr, delegate=self.delegate_dense)()
     pretty = Daffodil(fltr, delegate=self.delegate_pretty)()
     return dense, pretty
Example #10
0
 def filter(self, daff_src):
     return Daffodil(daff_src)(self.d)
Example #11
0
 def parse(self, daff_src, delegate):
     return Daffodil(daff_src, delegate=delegate)
Example #12
0
 def mk_predicate(self, dafltr):
     return Daffodil(dafltr,
                     delegate=SimulationMatchingDelegate()).predicate