コード例 #1
0
    def test_mode_subdir_nocreate(self):
        if sys.platform == 'win32':
            # Mode argument is ignored on Windows; see aiolmdb.h
            return

        oldmask = os.umask(0)
        try:
            for mode in 0o777, 0o755, 0o700:
                path = self.create_dir()
                aiolmdb.open(path, subdir=True, create=False, mode=mode)
                fmode = mode & ~0o111
                assert self.path_mode(path + '/data.mdb') == fmode
                assert self.path_mode(path + '/lock.mdb') == fmode
        finally:
            os.umask(oldmask)
コード例 #2
0
 def test_readonly_true_noexist(self):
     path = self.create_dir(create=False)
     # Open readonly missing store should fail.
     self.assertRaises(
         lmdb.Error, lambda: aiolmdb.open(path, readonly=True, create=True))
     # And create=True should not have mkdir'd it.
     assert not os.path.exists(path)
コード例 #3
0
 def test_open_unref_does_not_leak(self):
     temp_dir = self.create_dir()
     env = aiolmdb.open(temp_dir)
     ref = weakref.ref(env)
     env = None
     testlib.debug_collect()
     self.assertIsNone(ref())
コード例 #4
0
 def test_subdir_false_junk(self):
     path = self.create_file()
     fp = open(path, 'wb')
     fp.write(b'A' * 8192)
     fp.close()
     self.assertRaises(lmdb.InvalidError,
                       lambda: aiolmdb.open(path, subdir=False))
コード例 #5
0
    def test_readonly_env_sub_eperm(self):
        # https://github.com/dw/py-aiolmdb/issues/109
        path, env = self.create_env()
        env.close()

        env = aiolmdb.open(path, max_dbs=10, readonly=True)
        self.assertRaises(lmdb.ReadonlyError,
                          lambda: env.open_db(b'node_schedules', create=True))
コード例 #6
0
    def test_readonly_env_sub(self):
        # https://github.com/dw/py-aiolmdb/issues/109
        path, env = self.create_env()
        self.assertIsNotNone(env.open_db(b'node_schedules'))
        env.close()

        env = aiolmdb.open(path, max_dbs=10, readonly=True)
        db = env.open_db(b'node_schedules', create=False)
        self.assertIsNotNone(db)
コード例 #7
0
    def test_readonly_true_exist(self):
        path, env = self.create_env()
        env2 = aiolmdb.open(path, readonly=True)
        assert env2.path() == path
        # Attempting a write txn should fail.

        @asyncio.coroutine
        def txn(txn):
            yield from env2.get_default_db().put(b'a', b'a')

        self.assertAsyncRaises(lmdb.ReadonlyError, txn)
        # Flag should be set.
        assert env2.flags()['readonly']
コード例 #8
0
    def test_weakref_callback_invoked_once(self):
        temp_dir = self.create_dir()
        env = aiolmdb.open(temp_dir)
        env.close()
        count = [0]

        def callback(ref):
            count[0] += 1

        ref = weakref.ref(env, callback)
        env = None
        testlib.debug_collect()
        self.assertIsNone(ref())
        self.assertEqual(count[0], 1)
コード例 #9
0
    def test_copy_compact(self):
        _, env = self.create_env()
        yield from env.get_default_db().put(b'a', b'b')

        dest_dir = self.create_dir()
        yield from env.copy(dest_dir, compact=True)
        assert os.path.exists(dest_dir + '/data.mdb')

        cenv = aiolmdb.open(dest_dir)
        self.assertEqual((yield from cenv.get_default_db().get(b'a')), b'b')

        env.close()

        @asyncio.coroutine
        def txn():
            yield from env.copy(self.create_dir())

        self.assertAsyncRaises(Exception, txn)
コード例 #10
0
    def test_copyfd_compact(self):
        path, env = self.create_env()
        yield from env.get_default_db().put(b'a', b'b')

        dst_path = self.create_file(create=False)
        fp = open(dst_path, 'wb')
        yield from env.copyfd(fp.fileno(), compact=True)

        dstenv = aiolmdb.open(dst_path, subdir=False)
        assert (yield from dstenv.get_default_db().get(b'a')) == b'b'

        env.close()

        @asyncio.coroutine
        def txn():
            yield from env.copyfd(fp.fileno())

        self.assertAsyncRaises(Exception, txn())
        fp.close()
コード例 #11
0
 def test_subdir_true_exist_create(self):
     path, env = self.create_env()
     assert aiolmdb.open(path, subdir=True, create=True).path() == path
コード例 #12
0
    def test_readonly_env_main(self):
        path, env = self.create_env()
        env.close()

        env = aiolmdb.open(path, readonly=True)
        env.open_db(None)
コード例 #13
0
 def test_reopen(self):
     path, env = self.create_env()
     env.open_db(b'subdb1')
     env.close()
     env = aiolmdb.open(path, max_dbs=10)
     env.open_db(b'subdb1')
コード例 #14
0
 def _test_reader_check_child(path):
     """Function to run in child process since we can't use fork() on
     win32."""
     env = aiolmdb.open(path, max_spare_txns=0)
     env.begin()
     os._exit(0)
コード例 #15
0
 def test_bad_paths(self):
     self.assertRaises(Exception,
                       lambda: aiolmdb.open('/doesnt/exist/at/all'))
     self.assertRaises(Exception, lambda: aiolmdb.open(self.create_file()))
コード例 #16
0
ファイル: testlib.py プロジェクト: adepasquale/aiolmdb
 def create_env(self, path=None, max_dbs=10, **kwargs):
     if not path:
         path = self.create_dir()
     env = aiolmdb.open(path, max_dbs=max_dbs, **kwargs)
     self.cleanups.append(env.close)
     return path, env