def testLeavesFlavor(self):
        repos = self.openRepository()
        # this is a nasty, nasty, nasty test. msw suggested it
        server = self.servers.getServer(0)

        # add permutations of these objects
        tlabel = 'localhost@rpl:linux'
        # the least desirable that would also be the "latest"
        tlast = ('/%s/9.%%d-1-1' % (tlabel,), 'use:flag1,flag2,flag3')
        tlist = [
            ('/%s/1.%%d-1-1' % (tlabel,), 'use:flag1'),
            ('/%s/2.%%d-1-1' % (tlabel,), 'use:flag1,flag2'),
            #('/%s/3.%%d-1-1' % (tlabel,), 'use:flag1,flag2,flag3'),
            tlast,
            ]
        # neither use flags makes us happy
        self.cfg.flavor = [ deps.parseFlavor('~!flag1,~!flag2,~!flag3') ]

        db = server.reposDB.connect()

        def print_db(db, tname = None):
            cu = db.cursor()                  
            args = []
            query = """
            select Items.item, Versions.version,
            Nodes.timestamps as ts, Nodes.finalTimestamp as fts
            from Nodes join Items using (itemid)
            join Versions on Nodes.versionId = Versions.versionId
            """
            if tname:
                query = query + " where Items.item = ? "
                args.append(tname)
            cu.execute(query, args)
            ret = cu.fetchall()
            print "Dataset is: (trove, version, TS, finalTS)"
            for x in ret:
                print x

        # update a node's timestamps
        def set_ts(db, tname, tversion, ts):
            cu = db.cursor()
            updq = """
            update Nodes
                set timestamps = '%s',
                finalTimeStamp = %s
            where
                Nodes.itemId in (
                    select itemId from Items where Items.item = '%s' )
                and Nodes.versionId in (
                    select versionId from Versions where Versions.version = '%s' )
            """ % (str(ts), ts, tname, tversion)
            cu.execute(updq, [] )
            db.commit()
            
        # since we're manually messing with timestamps, we need to update the Latest
        # table as well
        def fix_latest(db):
            cu = db.cursor()
            cu.execute('DELETE FROM LatestCache')
            latest = versionops.LatestTable(db)
            latest.rebuild()
            db.commit()

        # exhaustive search - generate permutations of the above
        def xcombinations(items, n):
            if n==0: yield []
            else:
                for i in xrange(len(items)):
                    for cc in xcombinations(items[:i]+items[i+1:],n-1):
                        yield [items[i]]+cc

        cnt = 0
        req = {}
        for xlist in xcombinations(range(len(tlist)), len(tlist)):            
            cnt = cnt + 1
            # each permutation gets its own trove name
            tname = "test%d:test" % (cnt,)
            for t in xlist:
                # we build increasingly larger sets of versions for the
                # chosen trove name
                for iter in range(1, cnt+1):
                    l = (tname, (iter,) % tlist[t][0], tlist[t][1])
                    self.addQuickTestComponent(*l)
                    set_ts(db, tname, l[1], t*100+iter+1)
            # make sure the "latest" has the highest timestamp
            # XXX: watch out for max number of permutations that could top
            #      the highest chosen timestamp
            set_ts(db, tname, tlast[0] % (cnt,), 200*len(tlist)+1)
            # fix the latest table manualy (we emulate 'triggers')
            fix_latest(db)
            # now see what the repo "thinks" about it
            d = repos.getTroveLeavesByLabel(
                { tname : { versions.Label(tlabel): self.cfg.flavor } },
                bestFlavor=True)
            # we only ask for one element
            assert(len(d) == 1)
            assert(d.has_key(tname))
            ret = d[tname]
            need = {versions.VersionFromString(tlast[0] % (cnt,)): [deps.parseFlavor(tlast[1])]}
            if  ret != need:
                print
                print "NEED:", need
                print "GOT :", ret
                print_db(db, tname)
            assert(ret == need)
dataset/ETHPy150Open sassoftware/conary/conary_test/flavortest.py/FlavorTest.testLeavesFlavor/swapped operands of `%`