def test_import_from(self, stmt, mod_name): test_globals = {} ConfigExpression(id="", config=stmt, globals=test_globals).evaluate() self.assertTrue(callable(test_globals[mod_name])) self.assertTrue( ConfigExpression.is_import_statement( ConfigExpression(id="", config=stmt).config))
def test_expression(self, id, test_input): configer = ConfigExpression(id=id, config=test_input, globals={"monai": monai, "torch": torch}) var = 100 ret = configer.evaluate(globals={"var": var, "monai": monai}) # `{"monai": monai}` to verify the warning if isinstance(ret, Callable): self.assertTrue(isinstance(ret([torch.tensor(1), torch.tensor(2)]), torch.Tensor)) else: # also test the `locals` for regular expressions ret = configer.evaluate(locals={"var": var}) self.assertEqual(ret, 200)
def test_expression(self, id, test_input): configer = ConfigExpression(id=id, config=test_input, globals={ "monai": monai, "torch": torch }) var = 100 ret = configer.evaluate(locals={"var": var}) self.assertTrue(isinstance(ret, Callable))
def test_is_import_stmt(self, stmt, expected): expr = ConfigExpression(id="", config=stmt) flag = expr.is_import_statement(expr.config) self.assertEqual(flag, expected)
def test_import(self, stmt, mod_name): test_globals = {} ConfigExpression(id="", config=stmt, globals=test_globals).evaluate() self.assertTrue(callable(test_globals[mod_name].dump))