Skip to content

Commit

Permalink
Add tests to dry URL
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisSanchez25 committed Jul 31, 2023
1 parent 3d9adc4 commit aa555d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 5 additions & 4 deletions rframe/data_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, schema, datasource, initdb=False):
self.schema = schema
self.storage = datasource


for name in dir(self):

if name.startswith("__"):
Expand All @@ -50,7 +51,7 @@ def __init__(self, schema, datasource, initdb=False):
)
method = makefun.create_function(signature, impl, func_name=name)
setattr(self, name[1:], method)

if initdb:
self.initdb()

Expand Down Expand Up @@ -108,7 +109,7 @@ def _min(self, fields=None, **labels) -> Any:
fields = list(self.schema.__fields__)
elif isinstance(fields, str):
fields = [fields]

labels = {k: v for k, v in labels.items() if v is not None}
query = self.schema.compile_query(self.storage, **labels)

Expand Down Expand Up @@ -162,10 +163,10 @@ def _count(self, **labels):
def insert(self, docs, raise_on_error=True, dry=False):
if not self.initialized:
self.initdb()

if not isinstance(docs, (list, tuple)):
docs = [docs]

res = {
"success": [],
"failed": [],
Expand Down
12 changes: 11 additions & 1 deletion tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def insert_data(

PERMISSIONS["insert"] = True
db.insert(docs)

PERMISSIONS["update"] = False
with tester.assertRaises(UpdateError):
db.insert(docs)
Expand All @@ -90,6 +90,14 @@ def delete_data(
db.delete(docs)
tester.assertEqual(db.count(), 0)

@classmethod
def dry_insert_data(
cls, tester: unittest.TestCase, db, docs: List["BaseTestSchema"]
):
before_insert = db.count()
db.insert(docs, dry=True)
tester.assertEqual(db.count(), before_insert)

@classmethod
def basic_tests(
cls, tester: unittest.TestCase, db, docs: List["BaseTestSchema"]
Expand Down Expand Up @@ -145,6 +153,7 @@ def test(cls, tester: unittest.TestCase, db, docs: List["BaseTestSchema"]):
cls.basic_tests(tester, db, docs)
cls.frame_test(tester, db, docs)
cls.delete_data(tester, db, docs)
cls.dry_insert_data(tester, db, docs)


class SimpleSchema(BaseTestSchema):
Expand Down Expand Up @@ -219,6 +228,7 @@ def basic_tests(cls, tester, db, docs: List["InterpolatingSchema"]):
ratio = doc.value / value
tester.assertAlmostEqual(ratio, 1, delta=1e-2)


@classmethod
def test(cls, tester, db, docs: List["BaseTestSchema"]):
cls.insert_data(tester, db, docs)
Expand Down

0 comments on commit aa555d0

Please sign in to comment.