예제 #1
0
파일: test_all.py 프로젝트: brentp/fixle
    def setUp(self):
        #_cleanup()
        self.f = Fixle("./t.fdb", mode='w')
        for i, v in enumerate(self.list):
            self.f[i] = v

        self.f.sync()
예제 #2
0
파일: test_all.py 프로젝트: brentp/fixle
class FixleTest(unittest.TestCase):
    list = ["asdf", "bbbb", "a\0a"]
    def setUp(self):
        #_cleanup()
        self.f = Fixle("./t.fdb", mode='w')
        for i, v in enumerate(self.list):
            self.f[i] = v

        self.f.sync()

    def test_len(self):
        self.assertEquals(len(self.f), 3)

    def test_get(self):
        for i, v in enumerate(self.list):
            self.assertEquals(self.f[i], v)

    def test_read(self):
        self.f.close()
        self.f = Fixle("./t.fdb", mode="r")
        self.assertEquals(self.f[1], self.list[1])

        self.assertRaises(FixleException, self.f.__setitem__, 1, "g")

    def test_range(self):
        self.assertEquals(self.f[1:3], self.list[1:3])
        self.assertEquals(self.f[:3], self.list[:3])
        self.assertEquals(self.f[2:], self.list[2:])

    def test_append(self):
        values = ["g", "h", "i"]
        for v in values:
            self.f.append(v)
        self.f.sync()

        for i, v in zip(range(3, 6), values):
            self.assertEqual(self.f[i], v)

    def test_extend(self):
        n = len(self.f)
        values = ["rrg", "rrh", "rri"]
        self.f.extend(values)
        self.assertEqual(len(self.f), n + 3)
        n = len(self.f)
        for i, v in enumerate(self.f[n - 3:]):
            self.assertEqual(v, values[i])

    def tearDown(self):
        self.f.clear()
        del self.f
        _cleanup()

    def test_index(self):
        self.assertRaises(IndexError, self.f.__getitem__, 10)

    def test_iter(self):
        self.assertEquals(list(self.f), self.list)

    def test_del(self):
        # note delete will act more like a dict than a list.
        f = self.f
        self.assertEquals(len(f), 3)
        del f[1]
        self.assertEquals(len(f), 2)

        olist = self.list[:]
        del olist[1]

        self.assertEquals(list(f), olist)

        self.assertEquals(f.keys(), [0, 2])

    def test_items(self):
        f = self.f
        self.assertEqual(f.items(), list(enumerate(self.list)))

        self.assertEqual(f.items(2), list(enumerate(self.list))[2:])

        self.assertEqual(f.items(1, 2), list(enumerate(self.list))[1:2])

    def test_zero(self):
        f = self.f
        self.assertEqual(f[0], self.list[0])
예제 #3
0
파일: test_all.py 프로젝트: brentp/fixle
    def test_read(self):
        self.f.close()
        self.f = Fixle("./t.fdb", mode="r")
        self.assertEquals(self.f[1], self.list[1])

        self.assertRaises(FixleException, self.f.__setitem__, 1, "g")