def test_convert_to_str(self): acts = [['some text', 'some text'], [False, '0'], [True, '1'], [123, '123'], [-123, '-123'], [123.4, '123.4'], [None, 'None'], [0, '0'], ] for a in acts: self.assertEqual(PocketDB.convert_type_to_str(a[0]), a[1])
def test_dump_get_kwargs(self): pdb = PocketDB.PocketsDB('test7_db') kw1 = {u'Ref_Key': u"9747544e-11c8-11e4-589e-0018f3e1b84e", u'IsFolder': False, u'Description': u"Русские буквы", u'Активность': True} kw2 = {u'Ref_Key': u"44747adc-5dd5-11e3-95ac-005056c00008", u'ВалютнаяСуммаBalance': 123.45, u'ExtDimension1': u"Name", u'Активность': True, u'Пассивность': True} kw3 = {u'Ref_Key': u"6b4785a2-5ee9-11e5-6c8d-0018f3e1b84e", u'SomeValue': None, u'Description': 345, u'Активность': True} pct1 = PocketClass.OnePocket(u'Test1', u'руб', 123, **kw1) pct2 = PocketClass.OneCredit(u'Test2', u'руб', u'My contact', 23, **kw2) # третий - для произвольного объекта, например статьи расхода pdb.dump_kwargs(pct1) pdb.dump_kwargs(pct2) pdb.dump_kwargs('Item1', 'in_items', **kw3) return_value = [] con = sqlite3.connect(pdb.db_name) cur = con.cursor() try: cur.execute("SELECT * FROM KWArgs") except sqlite3.OperationalError: raise Exception('KWArgs table is wrong') for row in cur: return_value.append([row[1], row[2], row[3], row[4], row[5]]) con.close() return_value.sort() model = [] for k in pct1.kwargs: model.append([pct1.name, pct1.__name__, k, PocketDB.get_type(pct1.kwargs[k]), PocketDB.convert_type_to_str(pct1.kwargs[k])]) for k in pct2.kwargs: model.append([pct2.name, pct2.__name__, k, PocketDB.get_type(pct2.kwargs[k]), PocketDB.convert_type_to_str(pct2.kwargs[k])]) for k in kw3: model.append([u'Item1', u'in_items', k, PocketDB.get_type(kw3[k]), PocketDB.convert_type_to_str(kw3[k])]) model.sort() kw1_t = pdb.get_kwargs(pct1) kw2_t = pdb.get_kwargs(pct2) kw3_t = pdb.get_kwargs('Item1', 'in_items') pdb._drops() self.assertListEqual(model, return_value) self.assertDictEqual(kw1, kw1_t) self.assertDictEqual(kw2, kw2_t) self.assertDictEqual(kw3, kw3_t)
def test_type_convert(self): acts = [['str', 'some text', 'some text'], ['str', False, 'False'], ['str', 123, '123'], ['int', '123', 123], ['int', '-123', -123], ['float', '-123', -123.0], ['float', '123.4', 123.4], ['long', '1234', 1234L], ['NoneType', '1234', None], ['NoneType', None, None], ['NoneType', 0, None], ['bool', 0, False], ['bool', 1, True], ['bool', '0', False], ['bool', '1', True] ] for a in acts: self.assertEqual(PocketDB.convert_to_type(a[1], a[0]), a[2])