def test_composed_key_return_list_iteritems_test(self): config.session.execute("DROP TABLE IF EXISTS my_app.tab13") tablename = "tab13" pd = StorageDict(tablename, [('pid', 'int'), ('time', 'double')], [('value', 'text'), ('x', 'double'), ('y', 'double'), ('z', 'double')]) what_should_be = {} for i in range(100): pd[i, i + 100.0] = ('ciao' + str(i), i * 0.1, i * 0.2, i * 0.3) what_should_be[i, i + 100.0] = ('ciao' + str(i), i * 0.1, i * 0.2, i * 0.3) del pd count, = config.session.execute('SELECT count(*) FROM my_app.tab13')[0] self.assertEqual(count, 100) pd = StorageDict(tablename, [('pid', 'int')], [('time', 'double'), ('value', 'text'), ('x', 'double'), ('y', 'double'), ('z', 'double')]) count = 0 res = {} for key, val in pd.iteritems(): self.assertTrue(isinstance(key, int)) self.assertTrue(isinstance(val[0], float)) res[key] = val count += 1 self.assertEqual(count, 100) # casting to avoid 1.0000001 float python problem data = set([(key, int(val.time), val.value, int(val.x), int(val.y), int(val.z)) for key, val in pd.iteritems()]) data2 = set([(key[0], int(key[1]), val[0], int(val[1]), int(val[2]), int(val[3])) for key, val in what_should_be.iteritems()]) self.assertEqual(data, data2)
def test_update(self): tablename = "test_update1" pd = StorageDict(tablename, [('position', 'int')], [('value', 'text')]) pd[0] = 'prev_a' pd[1] = 'prev_b' self.assertEquals(pd[0], 'prev_a') self.assertEquals(pd[1], 'prev_b') pd.update({0: 'a', 1: 'b'}) time.sleep(1) self.assertEquals(pd[0], 'a') self.assertEquals(pd[1], 'b') pd.update({2: 'c', 3: 'd'}) time.sleep(1) self.assertEquals(pd[0], 'a') self.assertEquals(pd[1], 'b') self.assertEquals(pd[2], 'c') self.assertEquals(pd[3], 'd') tablename = "test_update2" pd2 = StorageDict(tablename, [('position', 'int')], [('value', 'text')]) pd2[0] = 'final_a' pd2[4] = 'final_4' pd.update(pd2) time.sleep(1) self.assertEquals(pd[0], 'final_a') self.assertEquals(pd[4], 'final_4') pd.delete_persistent() pd2.delete_persistent()
def test_get_strs(self): tablename = "test_get_strs" pd = StorageDict(tablename, [('position', 'int')], [('value', 'text')]) pd[0] = 'str1' self.assertEquals(pd[0], 'str1') pd.delete_persistent()