コード例 #1
0
ファイル: idtabletest.py プロジェクト: tensor5/conary
    def testIdPairSet(self):
        cx = self.getDB()

        idtable.createIdPairTable(cx, 'test', 'first', 'second', 'val')
        tbl = idtable.IdPairSet(cx, "test", "first", "second", "val")
        tbl.addItem((1, 2), 100)
        tbl.addItem((2, 3), 200)
        a = tbl[(1, 2)]
        assert ([x for x in tbl[(1, 2)]] == [100])
        assert ([x for x in tbl[(2, 3)]] == [200])
        assert ([x for x in tbl.getByFirst(1)] == [100])

        tbl.addItem((1, 2), 101)
        tbl.addItem((2, 3), 201)
        assert ([x for x in tbl[(1, 2)]] == [100, 101])
        assert ([x for x in tbl[(2, 3)]] == [200, 201])
        assert ([x for x in tbl.getByFirst(1)] == [100, 101])

        tbl.delItem((2, 3), 200)
        assert ([x for x in tbl[(2, 3)]] == [201])

        del tbl[(1, 2)]
        self.assertRaises(KeyError, tbl.__getitem__, (1, 2))

        tbl.delItem((2, 3), 201)
        self.assertRaises(KeyError, tbl.__getitem__, (2, 3))
コード例 #2
0
ファイル: idtabletest.py プロジェクト: pombr/conary
    def testIdPairSet(self):
        cx = self.getDB()

        idtable.createIdPairTable(cx, 'test', 'first', 'second', 'val')
        tbl = idtable.IdPairSet(cx, "test", "first", "second", "val")
        tbl.addItem((1,2), 100)
        tbl.addItem((2,3), 200)
        a = tbl[(1,2)]
        assert([x for x in tbl[(1,2)]] == [ 100 ])
        assert([x for x in tbl[(2,3)]] == [ 200 ])
        assert([x for x in tbl.getByFirst(1)] == [ 100 ])

        tbl.addItem((1,2), 101)
        tbl.addItem((2,3), 201)
        assert([x for x in tbl[(1,2)]] == [ 100, 101 ])
        assert([x for x in tbl[(2,3)]] == [ 200, 201 ])
        assert([x for x in tbl.getByFirst(1)] == [ 100, 101 ])

        tbl.delItem((2, 3), 200)
        assert([x for x in tbl[(2,3)]] == [ 201 ])

        del tbl[(1,2)]
        self.assertRaises(KeyError, tbl.__getitem__, (1,2))

        tbl.delItem((2, 3), 201)
        self.assertRaises(KeyError, tbl.__getitem__, (2,3))
コード例 #3
0
ファイル: idtabletest.py プロジェクト: tensor5/conary
    def testIdPairMapping(self):
        cx = self.getDB()

        idtable.createIdPairTable(cx, "test", "first", "second", "val")
        tbl = idtable.IdPairMapping(cx, "test", "first", "second", "val")
        tbl[(1, 2)] = 100
        tbl[(2, 3)] = 101
        assert (tbl[(1, 2)] == 100)
        assert (tbl[(2, 3)] == 101)

        del tbl[(2, 3)]
        self.assertRaises(KeyError, tbl.__getitem__, (2, 3))
        assert (tbl.get((2, 3), "foo") == "foo")
コード例 #4
0
ファイル: idtabletest.py プロジェクト: pombr/conary
    def testIdPairMapping(self):
        cx = self.getDB()

        idtable.createIdPairTable(cx, "test", "first", "second", "val")
        tbl = idtable.IdPairMapping(cx, "test", "first", "second", "val")
        tbl[(1,2)] = 100
        tbl[(2,3)] = 101
        assert(tbl[(1,2)] == 100)
        assert(tbl[(2,3)] == 101)

        del tbl[(2,3)]
        self.assertRaises(KeyError, tbl.__getitem__, (2,3))
        assert(tbl.get((2,3), "foo") == "foo")