def test_reflect_simplest_function(): module_file = reflect_module_file(module_four_path) loaded_module = module_file.load() function = reflect_function(loaded_module.simplest_function) assert not function.has_return_annotation() assert function.invoke() is None
def test_reflect_string_function(): module_file = reflect_module_file(module_four_path) loaded_module = module_file.load() function = reflect_function(loaded_module.string_function) assert function.has_return_annotation() assert function.return_annotation is str assert function.invoke() == "string"
def test_reflect_module_three(): module_file = reflect_module_file(module_three_path) loaded_module = module_file.load() module = reflect_module(loaded_module) assert ("function_three", loaded_module.function_three) in module.functions assert ("ClassOne", loaded_module.ClassOne) in module.classes assert ("value_one", loaded_module.value_one) in module.values
def test_reflect_module_file_three(): import_path = "package_one.module_three" module_file = reflect_module_file(module_three_path) module = module_file.load() assert is_module(module) assert import_path == import_path_from_module(module)
def test_reflect_module_file_one(): import_path = "module_one" module_file = reflect_module_file(module_one_path) module = module_file.load() assert is_module(module) assert import_path == import_path_from_module(module)
def test_reflect_value_one(): module_file = reflect_module_file(module_three_path) loaded_module = module_file.load() module = reflect_module(loaded_module) value = reflect_value(loaded_module.value_one) assert ( "member_function_one", loaded_module.value_one.member_function_one, ) in value.functions
def test_reflect_class_one(): module_file = reflect_module_file(module_three_path) loaded_module = module_file.load() module = reflect_module(loaded_module) reflected_class = reflect_class(loaded_module.ClassOne) assert ( "member_function_one", loaded_module.ClassOne.member_function_one, ) in reflected_class.functions
def test_reflect_identity_function(): module_file = reflect_module_file(module_four_path) loaded_module = module_file.load() function = reflect_function(loaded_module.identity_function) assert not function.has_return_annotation() assert function.invoke("value") == "value" for parameter in function.parameters: assert not parameter.has_default() assert not parameter.has_annotation() assert parameter.kind == ParameterKind.PositionalOrKeyword
def test_reflect_parameter_kind_function(): module_file = reflect_module_file(module_four_path) loaded_module = module_file.load() function = reflect_function(loaded_module.parameter_kind_function) assert not function.has_return_annotation() parameters = function.parameters if version_info.major >= 3 and version_info.minor >= 8: assert parameters[0].kind == ParameterKind.PositionalOnly assert parameters[1].kind == ParameterKind.PositionalOrKeyword assert parameters[2].kind == ParameterKind.VarPositional assert parameters[3].kind == ParameterKind.KeywordOnly assert parameters[4].kind == ParameterKind.VarKeyword else: assert parameters[0].kind == ParameterKind.PositionalOrKeyword assert parameters[1].kind == ParameterKind.VarPositional assert parameters[2].kind == ParameterKind.KeywordOnly assert parameters[3].kind == ParameterKind.VarKeyword # In current versions of python you can only specify positional_or_keyword # parameters using their positional variant in this complex scenario. assert function.invoke( "value1", "value2", "value3", "value4", keyword_only="value5", var_keyword1="value6", var_keyword2="value7", ) == ( "value1", "value2", "value3", "value4", "value5", {"var_keyword1": "value6", "var_keyword2": "value7"}, ) for parameter in parameters: assert not parameter.has_default() assert not parameter.has_annotation()
def test_reflect_module_one(): module_file = reflect_module_file(module_one_path) loaded_module = module_file.load() module = reflect_module(loaded_module) assert ("function_one", loaded_module.function_one) in module.functions