callat-qcd / lattedb

Lattice QCD database interface using EspressoDB as the content manager.
https://ithems.lbl.gov/lattedb
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Unittest for LatteDB #46

Closed ckoerber closed 4 years ago

ckoerber commented 4 years ago

We should add more unittests to LatteDB

ckoerber commented 4 years ago

I have added the ObjectParser class in lattedb.utilities.tests which simplifies the consistency check logic for tables. A example of how it is used is in lattedb.fermionaction.tests:

from django.test import TestCase

from lattedb.utilities.tests import ObjectParser

from lattedb.linksmear.tests import UnsmearedTestCase
from lattedb.fermionaction.models import Hisq as HisqFermionAction

class HisqTestCase(ObjectParser, TestCase):
    """Tests for Hisq fermion action.
    """

    model = HisqFermionAction
    tree = {"linksmear": "Unsmeared"}
    parameters = {
        "quark_mass": "0.01",
        "quark_tag": "light",
        "naik": "1.23",
        "linksmear": UnsmearedTestCase.parameters,
    }
    consistency_check_changes = [{"quark_tag": "not-light"}]

If you now run

pytest -k Hisq

in the repo root, this will run two tests:

  1. It tries to create a HisqFermionAction with the keywords provided in parameters using the get_or_create_from_parameters method
  2. It tries to create the action with parameters updated by entries in consistency_check_changes (a separate test for each entry in the list) and expects that a ConsitencyError is raised.

Note that this allows to also adjust parameters in in the FKs like {"linksmear.flow": 100}.

cchang5 commented 4 years ago

I think we're done with this...