Exemple #1
0
 def test_subdir_false_ok(self):
     path = testlib.temp_file(create=False)
     _, env = testlib.temp_env(path, subdir=False)
     assert os.path.exists(path)
     assert os.path.isfile(path)
     assert os.path.isfile(path + '-lock')
     assert not env.flags()['subdir']
Exemple #2
0
 def test_subdir_false_junk(self):
     path = testlib.temp_file()
     fp = open(path, 'wb')
     fp.write(B('A' * 8192))
     fp.close()
     self.assertRaises(lmdb.InvalidError,
                       lambda: lmdb.open(path, subdir=False))
Exemple #3
0
 def test_subdir_false_ok(self):
     path = testlib.temp_file(create=False)
     _, env = testlib.temp_env(path, subdir=False)
     assert os.path.exists(path)
     assert os.path.isfile(path)
     assert os.path.isfile(path + '-lock')
     assert not env.flags()['subdir']
Exemple #4
0
 def test_subdir_false_junk(self):
     path = testlib.temp_file()
     fp = open(path, 'wb')
     fp.write(B('A' * 8192))
     fp.close()
     self.assertRaises(lmdb.InvalidError,
         lambda: lmdb.open(path, subdir=False))
Exemple #5
0
    def test_copyfd_compact(self):
        path, env = testlib.temp_env()
        txn = env.begin(write=True)
        txn.put(B('a'), B('b'))
        txn.commit()

        dst_path = testlib.temp_file(create=False)
        fp = open(dst_path, 'wb')
        env.copyfd(fp.fileno())

        dstenv = lmdb.open(dst_path, subdir=False)
        dtxn = dstenv.begin()
        assert dtxn.get(B('a')) == B('b')
        fp.close()

        # Test copy with transaction provided
        dst_path = testlib.temp_file(create=False)
        fp = open(dst_path, 'wb')
        with env.begin(write=True) as txn:
            copy_txn = env.begin()
            txn.put(B('b'), B('b'))
        assert dtxn.get(B('b')) is None

        if have_txn_patch:

            env.copyfd(fp.fileno(), compact=True, txn=copy_txn)

            dstenv = lmdb.open(dst_path, subdir=False)
            dtxn = dstenv.begin()
            assert dtxn.get(B('a')) == B('b')
            # Verify that the write that occurred outside the txn isn't seen in the
            # copy
            assert dtxn.get(B('b')) is None
            dstenv.close()

        else:
            self.assertRaises(
                Exception,
                lambda: env.copyfd(fp.fileno(), compact=True, txn=copy_txn))

        env.close()
        self.assertRaises(Exception, lambda: env.copyfd(fp.fileno()))
        fp.close()
Exemple #6
0
    def test_copyfd_compact(self):
        path, env = testlib.temp_env()
        txn = env.begin(write=True)
        txn.put(B('a'), B('b'))
        txn.commit()

        dst_path = testlib.temp_file(create=False)
        fp = open(dst_path, 'wb')
        env.copyfd(fp.fileno(), compact=True)

        dstenv = lmdb.open(dst_path, subdir=False)
        dtxn = dstenv.begin()
        assert dtxn.get(B('a')) == B('b')

        env.close()
        self.assertRaises(Exception, lambda: env.copyfd(fp.fileno()))
        fp.close()
Exemple #7
0
    def test_copyfd_compact(self):
        path, env = testlib.temp_env()
        txn = env.begin(write=True)
        txn.put(B('a'), B('b'))
        txn.commit()

        dst_path = testlib.temp_file(create=False)
        fp = open(dst_path, 'wb')
        env.copyfd(fp.fileno(), compact=True)

        dstenv = lmdb.open(dst_path, subdir=False)
        dtxn = dstenv.begin()
        assert dtxn.get(B('a')) == B('b')

        env.close()
        self.assertRaises(Exception,
            lambda: env.copyfd(fp.fileno()))
        fp.close()
Exemple #8
0
 def test_bad_paths(self):
     self.assertRaises(Exception, lambda: lmdb.open('/doesnt/exist/at/all'))
     self.assertRaises(Exception, lambda: lmdb.open(testlib.temp_file()))
Exemple #9
0
 def test_bad_paths(self):
     self.assertRaises(Exception,
         lambda: lmdb.open('/doesnt/exist/at/all'))
     self.assertRaises(Exception,
         lambda: lmdb.open(testlib.temp_file()))