def test_context_and_deserialisation(self): store_file = mktemp() for name, value in self.TEST_DATA: if isinstance(value, tuple): value = list(value) with JsonStore(store_file) as store: store[name] = value with JsonStore(store_file) as store: self.assertEqual(getattr(store, name), value)
def test_new_store(self): store_file = mktemp() JsonStore(store_file, auto_commit=True) with open(self._store_file) as handle: self.assertEqual(handle.read(), '{}') os.remove(store_file) JsonStore(store_file, auto_commit=False) with open(self._store_file) as handle: self.assertEqual(handle.read(), '{}') os.remove(store_file)
def test_no_auto_commit(self): store_file = mktemp() store = JsonStore(store_file, indent=None, auto_commit=False) store.value1 = 1 store['value2'] = 2 with open(store_file) as handle: self.assertEqual({}, json.load(handle))
def __init__(self): self._driver = Scraper.get_reusable_driver() self._store = JsonStore('store.json') if not 'not_notified' in self._store: self._store['not_notified'] = [] if not 'notified' in self._store: self._store['notified'] = []
def test_auto_commit(self): store_file = mktemp() store = JsonStore(store_file, indent=None, auto_commit=True) store.value1 = 1 with open(store_file) as handle: self.assertEqual({"value1": 1}, json.load(handle)) store["value2"] = 2 with open(store_file) as handle: self.assertEqual({"value1": 1, "value2": 2}, json.load(handle))
def setUp(self): self._store_file = mktemp() self.store = JsonStore(self._store_file, indent=None, auto_commit=True)
def __init__(self): self.store = JsonStore('forms.json')
def test_empty_store(self): store_file = mktemp() with open(store_file, "wb") as f: f.write(b"") self.assertTrue(JsonStore(f.name))
def add(server_id, key, value): store = JsonStore(str(server_id) + ".json") store[key] = value
def remove(server_id, key): store = JsonStore(str(server_id) + ".json") del store[key] store._save()
def remove_from_dict(server_id, list_key, key): store = JsonStore(str(server_id) + ".json") del store["{}.{}".format(list_key, key)] store._save()
def add_to_dict(server_id, list_key, key, value): store = JsonStore(str(server_id) + ".json") store["{}.{}".format(list_key, key)] = value
def initialize_dict(server_id, list_key): store = JsonStore(str(server_id) + ".json") exec("store.{} = {}").format(list_key, {})
def get(server_id, key): store = JsonStore(str(server_id) + ".json") return store[key]
def __init__(self): self._lock = threading.Lock() self.store = JsonStore(config.config_path, indent=2, auto_commit=True) self.init_store()