示例#1
0
    def import_module_items(self, modules, level="testcase"):
        """ import modules and bind all functions within the context
        """
        sys.path.insert(0, os.getcwd())
        for module_name in modules:
            imported_module = utils.get_imported_module(module_name)
            imported_functions_dict = utils.filter_module(imported_module, "function")
            self.__update_context_functions_config(level, imported_functions_dict)

            imported_variables_dict = utils.filter_module(imported_module, "variable")
            self.bind_variables(imported_variables_dict, level)
    def test_filter_module_functions(self):
        imported_module = utils.get_imported_module("ate.utils")
        self.assertIn("PYTHON_VERSION", dir(imported_module))

        functions_dict = utils.filter_module(imported_module, "function")
        self.assertIn("filter_module", functions_dict)
        self.assertNotIn("PYTHON_VERSION", functions_dict)
    def test_get_imported_module_from_file(self):
        imported_module = utils.get_imported_module_from_file(
            "tests/data/debugtalk.py")
        self.assertIn("gen_md5", dir(imported_module))

        functions_dict = utils.filter_module(imported_module, "function")
        self.assertIn("gen_md5", functions_dict)
        self.assertNotIn("PYTHON_VERSION", functions_dict)

        with self.assertRaises(exception.FileNotFoundError):
            utils.get_imported_module_from_file("tests/data/debugtalk2.py")