forked from micropython/micropython-esp32-ulp
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefinesdb.py
60 lines (38 loc) · 966 Bytes
/
definesdb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
importos
fromesp32_ulp.definesdbimportDefinesDB, DBNAME
fromesp32_ulp.utilimportfile_exists
tests= []
deftest(param):
tests.append(param)
@test
deftest_definesdb_clear_removes_all_keys():
db=DefinesDB()
db.open()
db.update({'KEY1': 'VALUE1'})
db.clear()
assert'KEY1'notindb
db.close()
@test
deftest_definesdb_persists_data_across_instantiations():
db=DefinesDB()
db.open()
db.clear()
db.update({'KEY1': 'VALUE1'})
assert'KEY1'indb
db.close()
deldb
db=DefinesDB()
db.open()
assertdb.get('KEY1', None) =='VALUE1'
db.close()
@test
deftest_definesdb_should_not_create_a_db_file_when_only_reading():
db=DefinesDB()
db.clear()
assertnotfile_exists(DBNAME)
assertdb.get('some-key', None) isNone
assertnotfile_exists(DBNAME)
if__name__=='__main__':
# run all methods marked with @test
fortintests:
t()