def test_env_create(): os.environ['CUPBOARD_BACKEND'] = 'redis' d = Cupboard() os.environ['CUPBOARD_BACKEND'] = 'leveldb' d = Cupboard(name='/tmp/envlvlexists', create_if_missing=True) os.environ['CUPBOARD_BACKEND'] = 'lmdb' d = Cupboard(path='/tmp/envlmexists')
def amount_storage_items(self) -> int: return self.__storage_interface.amount_storage_items() def print_storage_item_list(self): items: List[str] = [ it.name for it in self.__storage_interface.get_items() ] print(items) def __repr__(self): return f"{self.__name} запрятал {self.amount_storage_items()} вещей!" if __name__ == '__main__': car: Car = Car("h134if123", 20) cupboard: Cupboard = Cupboard(40) garage: Garage = Garage("очень далеко д.21", 10) car.push_item(Book("dsfsdf", 200, 0.5)) car.push_item(Box(1, 2, 3)) person: Person = Person("Петр", car) person.save_item(Bottle("Жижа", 29, 0.7)) person.save_item(Bottle("Жижа 2.1", 29, 1.7)) print(person.pop_item()) person.change_interface(garage) print(person.amount_storage_items()) person.save_item(Bottle("Жижа", 29, 0.7)) person.save_item(Bottle("Жижа 2.1", 29, 1.7))
def test_leveldb_no_lock_violation(): d = Cupboard(name='/tmp/lvlexists', backend='leveldb', create_if_missing=True) d._db.close() o = Cupboard(name='/tmp/lvlexists', backend='leveldb')
def test_lmdb_create(): o = Cupboard(path='/tmp/lmexists', backend='lmdb')
def test_leveldb_lock_violation(): with pytest.raises(IOError): d = Cupboard(name='/tmp/lvlexists', backend='leveldb', create_if_missing=True) o = Cupboard(name='/tmp/lvlexists', backend='leveldb')
def test_leveldb_with_create_if_missing(): d = Cupboard(name='/tmp/good', backend='leveldb', create_if_missing=True)
def test_leveldb_no_create_if_missing(): with pytest.raises(Exception): d = Cupboard(name='/tmp/bad', backend='leveldb')
def test_redis_avail(): d = Cupboard(host='localhost', backend='redis')
def test_redis_unavail(): with pytest.raises(ConnectionError): d = Cupboard(host='localhost', port=8000, backend='redis')