From 429fb84249946fe00a50602a952b49fd97670928 Mon Sep 17 00:00:00 2001 From: hdoupe Date: Mon, 4 May 2020 10:09:15 -0400 Subject: [PATCH] Add ok_meta_param_dict to CoreTestFunctions test class --- README.md | 5 +++++ cs_kit/tests/test_FunctionsTest.py | 13 +++++++++++++ cs_kit/validate.py | 5 ++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 432cb1c..4dbb2c5 100644 --- a/README.md +++ b/README.md @@ -63,11 +63,16 @@ class TestFunctions1(CoreTestFunctions): get_inputs = functions.get_inputs validate_inputs = functions.validate_inputs run_model = functions.run_model + # ok_meta_param_dict is optional. + ok_meta_param_dict = {"full_data": False} ok_adjustment={"matchup": {"pitcher": [{"value": "Max Scherzer"}]}} bad_adjustment={"matchup": {"pitcher": [{"value": "Not a pitcher"}]}} ``` +- If `ok_meta_param_dict` is set, then it will be used in the `run_model` test + along with `ok_adjustment`. + ## Run your cs-config tests ```bash diff --git a/cs_kit/tests/test_FunctionsTest.py b/cs_kit/tests/test_FunctionsTest.py index 36428dc..d7f845e 100644 --- a/cs_kit/tests/test_FunctionsTest.py +++ b/cs_kit/tests/test_FunctionsTest.py @@ -224,3 +224,16 @@ class TestFunctions(TestFunctions1): tf = TestFunctions() with pytest.raises(CSKitError): tf.test_run_model() + + +def test_specify_meta_param_dict(): + def run_model_test_mp(meta_param_dict, adjustment): + assert meta_param_dict == {"hello_world": [{"value": "hello, there!"}]} + return run_model(meta_param_dict, adjustment) + + class TestFunctions(TestFunctions1): + ok_meta_param_dict = {"hello_world": "hello, there!"} + run_model = run_model_test_mp + + tf = TestFunctions() + tf.test_run_model() diff --git a/cs_kit/validate.py b/cs_kit/validate.py index 9499528..e150637 100644 --- a/cs_kit/validate.py +++ b/cs_kit/validate.py @@ -216,7 +216,10 @@ def test_run_model(self): class MetaParams(Parameters): defaults = inputs["meta_parameters"] - mp_spec = MetaParams().specification(serializable=True) + if getattr(self, "ok_meta_param_dict", None) is not None: + mp_spec = MetaParams().adjust(self.ok_meta_param_dict) + else: + mp_spec = MetaParams().specification(serializable=True) result = self.run_model(mp_spec, self.ok_adjustment)