def test_open_nopath(self): """A database without a path cannot be opened. """ jb = api.Database(path='') with pytest.raises(api.DatabaseError) as ctx: jb.open() assert str(ctx.value) == 'File not found.'
def test_path_setter(self): """An unopend database can change its path. """ jb = api.Database(path='') assert jb.path == '' jb.path = 'wawawa' assert jb.path == 'wawawa'
def test_option_setter(self): """An unopend database can change its options. """ jb = api.Database(options=0) assert jb.options == 0 jb.options = 17 assert jb.options == 17
def test_init_defaultpath(self): """An EJDB constructed with default args does not have a path, and is not opened. """ jb = api.Database() assert not jb.is_open() assert not jb.path assert jb.options == api.READ
def test_option_setter_opened(self): self.jb = api.Database( path=self.path, options=(api.WRITE | api.TRUNCATE), ) assert self.jb.options == (api.WRITE | api.TRUNCATE) with pytest.raises(api.DatabaseError) as ctx: self.jb.options = api.READ assert str(ctx.value) == 'Could not set options to an open database.'
def setup(self): """Create a database for testing. """ self.dirpath = tempfile.mkdtemp() path = os.path.join(self.dirpath, 'yksom') self.jb = api.Database( path=path, options=(api.WRITE | api.TRUNCATE | api.CREATE), )
def test_init_notexist_autocreate(self): """Construction is automatic if we give the `CREATE` flag. """ dirpath = tempfile.mkdtemp() path = os.path.join(dirpath, 'yksom') assert not os.path.exists(path) jb = api.Database(path=path, options=(api.WRITE | api.CREATE)) jb.close() shutil.rmtree(dirpath)
def test_path_setter_opened(self): """An open database cannot change its path. """ self.jb = api.Database(path=self.path) assert isinstance(self.jb.path, six.string_types) assert self.jb.path == self.path with pytest.raises(api.DatabaseError) as ctx: self.jb.path = 'yksom' assert str(ctx.value) == 'Could not set path to an open database.'
def setup(self): self.dirpath = tempfile.mkdtemp() path = os.path.join(self.dirpath, 'yksom') self.jb = api.Database( path=path, options=(api.WRITE | api.TRUNCATE | api.CREATE), ) self.jb.create_collection('yksom') self.jb.create_collection('evolyksom') self.jb.create_collection('yksomevoli')
def test_open_reopen(self): self.jb = api.Database(path=self.path) with pytest.raises(api.DatabaseError) as ctx: self.jb.open() assert str(ctx.value) == 'Database already opened.' self.jb.close() assert not self.jb.is_open() self.jb.open() assert self.jb.is_open()
def setup(self): self.dirpath = tempfile.mkdtemp() path = os.path.join(self.dirpath, 'yksom') self.jb = api.Database( path=path, options=(api.WRITE | api.TRUNCATE | api.CREATE), ) self.jb.create_collection('yksom') self.coll = self.jb['yksom'] self.objs = [ {'order': 4, 'one': 1}, {'order': 5, 'two': 2}, {'order': 3, 'three': 3}, {'order': 0, 'four': 4}, {'order': -1, 'five': 5}, ] oids = self.coll.insert_many(self.objs) for oid, obj in zip(oids, self.objs): obj['_id'] = oid
def test_init_notexist(self): """If a non-existant path is given, constructing raises an error. """ tfile = tempfile.NamedTemporaryFile() with pytest.raises(api.DatabaseError): api.Database(path=tfile.name)
def test_init_nopath(self): """An EJDB with a path evaluated to `False` is not opened. """ jb = api.Database(path='') assert not jb.is_open()
def test_close_reclose(self): self.jb = api.Database(path=self.path) self.jb.close() with pytest.raises(api.DatabaseError) as ctx: self.jb.close() assert str(ctx.value) == 'Database not opened.'
def test_init_bytespath(self): self.jb = api.Database(path=self.path_b) assert self.jb.is_open()
def test_init(self): self.jb = api.Database(path=self.path) assert self.jb.is_open()