This commit is contained in:
2018-01-28 04:44:03 -06:00
parent df5ed9c047
commit 95767ae684
14 changed files with 649 additions and 2 deletions

3
tests/__init__.py Normal file
View File

@@ -0,0 +1,3 @@
from logging import getLogger
getLogger('flake8').propagate = False

11
tests/test_import.py Normal file
View File

@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
from jsondict import JsonDict # noqa
# pylint: disable=unused-import,unused-variable
def test_import():
_ = JsonDict() # noqa

40
tests/test_pdd.py Normal file
View File

@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
from jsondict import JsonDict, atomic_write
import json
import unittest
class Testcases(unittest.TestCase):
def test_atomic_write(self):
ts = "this is my test string"
tfn = '/tmp/pad_test.txt'
atomic_write(tfn, ts)
with open(tfn, 'r') as fh:
self.assertEqual(fh.read(), ts)
def test_persistence(self):
tfn = '/tmp/pad_test.json'
mypdd = JsonDict(persistence=tfn)
mypdd['testattr'] = 'loldongs'
with open(tfn, 'r') as fh:
x = json.load(fh)
self.assertEqual(x['testattr'], 'loldongs')
del mypdd['testattr']
self.assertEqual(mypdd['testattr'], None)
def test_read(self):
tfn = '/tmp/pad_test.json'
mypdd = JsonDict(persistence=tfn)
mypdd['testattr'] = 'loldongs'
with open(tfn, 'w') as fh:
json.dump({'testattr': 'notloldongs'}, fh)
self.assertNotEqual(mypdd['testattr'], 'loldongs')
self.assertEqual(mypdd['nonexist'], None)