예제 #1
0
 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))
예제 #2
0
 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)
예제 #3
0
 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))
예제 #4
0
 def test_is_import_stmt(self, stmt, expected):
     expr = ConfigExpression(id="", config=stmt)
     flag = expr.is_import_statement(expr.config)
     self.assertEqual(flag, expected)
예제 #5
0
 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))