def test_is_variable(self): var1 = 123 var2 = 'abc' assert validator.is_variable(('var1', var1)) assert validator.is_variable(('var2', var2)) __var = 123 assert not validator.is_variable(('__var', __var)) func = lambda x: x + 1 assert not validator.is_variable(('func', func)) assert not validator.is_variable(('pytest', pytest))
def test_is_variable(self): var1 = 123 var2 = "abc" self.assertTrue(validator.is_variable(("var1", var1))) self.assertTrue(validator.is_variable(("var2", var2))) __var = 123 self.assertFalse(validator.is_variable(("__var", __var))) func = lambda x: x + 1 self.assertFalse(validator.is_variable(("func", func))) self.assertFalse(validator.is_variable(("unittest", unittest)))
def load_python_module(module): """ load python module. Args: module: python module Returns: dict: variables and functions mapping for specified python module { "variables": {}, "functions": {} } """ debugtalk_module = {"variables": {}, "functions": {}} for name, item in vars(module).items(): if validator.is_function((name, item)): debugtalk_module["functions"][name] = item elif validator.is_variable((name, item)): debugtalk_module["variables"][name] = item else: pass return debugtalk_module
def load_python_module(module): ''' load python module. Args: module: python module Returns: dict: variables and functions mapping for specified python module { 'variables':{}, 'functions':{} } ''' python_module = {'variables': {}, 'functions': {}} for name, item in vars(module).items(): if validator.is_function((name, item)): python_module['functions'][name] = item elif validator.is_variable((name, item)): python_module['variables'][name] = item else: pass return python_module
def test_get_module_item_variables(self): from tests import confcustom module_mapping = loader.load_python_module(confcustom) SECRET_KEY = loader.get_module_item(module_mapping, 'variables', 'SECRET_KEY') assert validator.is_variable(('SECRET_KEY', SECRET_KEY)) assert SECRET_KEY == 'MyHttpRunner'
def test_get_module_item_variables(self): from tests import debugtalk module_mapping = loader.load_python_module(debugtalk) SECRET_KEY = loader.get_module_item(module_mapping, "variables", "SECRET_KEY") self.assertTrue(validator.is_variable(("SECRET_KEY", SECRET_KEY))) self.assertEqual(SECRET_KEY, "DebugTalk") with self.assertRaises(exceptions.VariableNotFound): loader.get_module_item(module_mapping, "variables", "SECRET_KEY2")
def test_get_module_item_variables(self): dot_env_path = os.path.join(os.getcwd(), "tests", ".env") loader.load_dot_env_file(dot_env_path) from tests import debugtalk module_mapping = loader.load_python_module(debugtalk) SECRET_KEY = loader.get_module_item(module_mapping, "variables", "SECRET_KEY") self.assertTrue(validator.is_variable(("SECRET_KEY", SECRET_KEY))) self.assertEqual(SECRET_KEY, "DebugTalk") with self.assertRaises(exceptions.VariableNotFound): loader.get_module_item(module_mapping, "variables", "SECRET_KEY2")