Furthered test coverage
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@
|
|||||||
datalite/__pycache__/*
|
datalite/__pycache__/*
|
||||||
*.pyc
|
*.pyc
|
||||||
datalite/*.db
|
datalite/*.db
|
||||||
|
*.db
|
||||||
build/*
|
build/*
|
||||||
datalite.egg-info/*
|
datalite.egg-info/*
|
||||||
dist/*
|
dist/*
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
# Datalite
|
# Datalite
|
||||||
|
|
||||||
[](https://codeclimate.com/github/ambertide/datalite/maintainability)
|
[](https://codeclimate.com/github/ambertide/datalite/maintainability)
|
||||||
|
[](https://codeclimate.com/github/ambertide/datalite/test_coverage)
|
||||||
|
[](https://pypi.python.org/pypi/datalite/)
|
||||||
|
[](https://pypi.python.org/pypi/datalite/)
|
||||||
|
|
||||||
Datalite is a simple Python
|
Datalite is a simple Python
|
||||||
package that binds your dataclasses to a table in a sqlite3 database,
|
package that binds your dataclasses to a table in a sqlite3 database,
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
import unittest
|
import unittest
|
||||||
try:
|
from datalite import datalite, fetch_if, fetch_all, fetch_range, fetch_from
|
||||||
from datalite import datalite
|
|
||||||
except ModuleNotFoundError:
|
|
||||||
import importlib
|
|
||||||
importlib.import_module('datalite', '../datalite/')
|
|
||||||
from sqlite3 import connect
|
from sqlite3 import connect
|
||||||
from dataclasses import dataclass, asdict
|
from dataclasses import dataclass, asdict
|
||||||
from os import remove
|
from os import remove
|
||||||
@@ -21,6 +17,16 @@ class TestClass:
|
|||||||
return asdict(self) == asdict(other)
|
return asdict(self) == asdict(other)
|
||||||
|
|
||||||
|
|
||||||
|
@datalite(db_path='test.db')
|
||||||
|
@dataclass
|
||||||
|
class FetchClass:
|
||||||
|
ordinal: int
|
||||||
|
str_: str
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return asdict(self) == asdict(other)
|
||||||
|
|
||||||
|
|
||||||
def getValFromDB(obj_id = 1):
|
def getValFromDB(obj_id = 1):
|
||||||
with connect('test.db') as db:
|
with connect('test.db') as db:
|
||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
@@ -66,5 +72,30 @@ class DatabaseMain(unittest.TestCase):
|
|||||||
self.assertEqual(len(objects), init_len)
|
self.assertEqual(len(objects), init_len)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class DatabaseFetchCalls(unittest.TestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.objs = [FetchClass(1, 'a'), FetchClass(2, 'b'), FetchClass(3, 'b')]
|
||||||
|
[obj.create_entry() for obj in self.objs]
|
||||||
|
|
||||||
|
def testFetchFrom(self):
|
||||||
|
t_obj = fetch_from(FetchClass, self.objs[0].obj_id)
|
||||||
|
self.assertEqual(self.objs[0], t_obj)
|
||||||
|
|
||||||
|
def testFetchAll(self):
|
||||||
|
t_objs = fetch_all(FetchClass)
|
||||||
|
self.assertEqual(tuple(self.objs), t_objs)
|
||||||
|
|
||||||
|
def testFetchIf(self):
|
||||||
|
t_objs = fetch_if(FetchClass, "str_ = \"b\"")
|
||||||
|
self.assertEqual(tuple(self.objs[1:]), t_objs)
|
||||||
|
|
||||||
|
def testFetchRange(self):
|
||||||
|
t_objs = fetch_range(FetchClass, range(self.objs[0].obj_id, self.objs[2].obj_id))
|
||||||
|
self.assertEqual(tuple(self.objs[0:2]), t_objs)
|
||||||
|
|
||||||
|
def tearDown(self) -> None:
|
||||||
|
[obj.remove_entry() for obj in self.objs]
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user