Esempio n. 1
0
 async def test_model(self):
     with tempfile.TemporaryDirectory() as tempdir, patch.object(
             Model, "load", new=model_load):
         config = parse_unknown("--model-directory", tempdir)
         async with self.post("/configure/model/fake/salary",
                              json=config) as r:
             self.assertEqual(await r.json(), OK)
             self.assertIn("salary", self.cli.app["models"])
             self.assertEqual(
                 self.cli.app["models"]["salary"].config,
                 FakeModelConfig(directory=tempdir),
             )
             with self.subTest(context="salaryctx"):
                 # Define the features
                 features = Features(
                     DefFeature("Years", int, 1),
                     DefFeature("Experiance", int, 1),
                 )
                 exported_features = features.export()
                 # Check that we can send shorthand version of feature_def
                 for name, feature_def in exported_features.items():
                     del feature_def["name"]
                 # Create the context
                 async with self.post(
                         "/context/model/salary/salaryctx",
                         json=exported_features,
                 ) as r:
                     self.assertEqual(await r.json(), OK)
                     self.assertIn("salaryctx",
                                   self.cli.app["model_contexts"])
                     self.assertEqual(
                         self.cli.app["model_contexts"]
                         ["salaryctx"].features.export(),
                         features.export(),
                     )
Esempio n. 2
0
 async def test_model_context_model_not_found(self):
     with self.assertRaisesRegex(ServerException,
                                 f"salary model not found"):
         features = Features()
         async with self.post("/context/model/salary/salaryctx",
                              json=features.export()) as r:
             pass  # pramga: no cov