def test_transaction(self): a = sqlite_db("test") with a.transaction(): a['key'] = 'value' self.assertEqual(len(a.items()), 1) self.assertEqual(len(self.db.items()), 0) items = self.db.items() self.assertEqual(len(items), 1) k, v = items[0] self.assertEqual('key', k) self.assertEqual('value', v)
def test_transaction(self): a = sqlite_db("test") with a.transaction(): a["key"] = "value" self.assertEqual(len(a.items()), 1) self.assertEqual(len(self.db.items()), 0) items = self.db.items() self.assertEqual(len(items), 1) k, v = items[0] self.assertEqual("key", k) self.assertEqual("value", v)
def test_with(self): with sqlite_db("test") as db: db['a'] = 'test_a' db['b'] = 'test_b' items = db.items() self.assertEqual(len(items), 2) k, v = items[0] self.assertEqual(k, 'a') self.assertEqual(v, 'test_a') k, v = items[1] self.assertEqual(k, 'b') self.assertEqual(v, 'test_b')
def test_with(self): with sqlite_db("test") as db: db["a"] = "test_a" db["b"] = "test_b" items = db.items() self.assertEqual(len(items), 2) k, v = items[0] self.assertEqual(k, "a") self.assertEqual(v, "test_a") k, v = items[1] self.assertEqual(k, "b") self.assertEqual(v, "test_b")
def __init__(self, me, allServers, start): self.id = str(me) self.kvs = dict() # kvs = [k1: KvE1, k2: KvE2, ...] self.server_updates = defaultdict( int) # su = [srv: timestamp, s: t, ...] self.live = 1 self.sock = 0 # configured in self.serve() self.db = sqlite_db(self.id, autocommit=False) self.db.begin() try: self.kvs = {x: KvEntry(*y) for x, y in self.db["kvs"].items()} except KeyError: self.kvs = dict() for port in allServers: try: self.server_updates[str(port)] = float( self.db["servers"][str(port)]) except KeyError: self.server_updates[str(port)] = float(start)
def test_dir(self): workdir = tempfile.mkdtemp() with sqlite_db("test", dir=workdir) as db: db['testing'] = 'dir' with sqlite_db("test", dir=workdir) as db: self.assertEqual(db['testing'], 'dir')
def setUp(self): self.db = sqlite_db('test') self.db.begin()
def test_dir(self): workdir = tempfile.mkdtemp() with sqlite_db("test", dir=workdir) as db: db["testing"] = "dir" with sqlite_db("test", dir=workdir) as db: self.assertEqual(db["testing"], "dir")
def setUp(self): self.db = sqlite_db("test") self.db.begin()
def test_multitable(self): store_file = "test" with sqlite_db(store_file, table="firstboot", autocommit=True) as db: db["state"] = 1 with sqlite_db(store_file, table="thisbox", autocommit=True) as db: db["state"] = 1
def test_multitable(self): store_file = "test" with sqlite_db(store_file, table="firstboot", autocommit=True) as db: db['state'] = 1 with sqlite_db(store_file, table="thisbox", autocommit=True) as db: db['state'] = 1