Beispiel #1
0
def test_inspect_methods_simple_function():
    meth_doc_dict = dict(netref.inspect_methods(simple_function))
    print("-"*40)
    print("checking presence of __call__ in simple function")
    print(meth_doc_dict.keys())
    assert '__call__' in meth_doc_dict
    
    print("-"*40)
    assert meth_doc_dict['__call__'] == simple_function.__call__.__doc__
Beispiel #2
0
def test_inspect_methods_simple_instance():
    meth_doc_dict = dict(netref.inspect_methods(simple_instance))
    print("-"*40)
    print("checking presence of simple method")
    assert simple_instance.simple_meth.__name__ in meth_doc_dict
    
    print("checking non presence of non callable eg_attr")
    assert "eg_attr" not in meth_doc_dict
    
    print("-"*40)
    print("checking presence of simple method doc")
    assert meth_doc_dict["simple_meth"] == simple_instance.simple_meth.__doc__
Beispiel #3
0
def test_inspect_methods_advanced_instance():
    meth_doc_dict = dict(netref.inspect_methods(advanced_instance))
    print("-"*40)
    print("checking presence of simple method")
    assert advanced_instance.simple_meth.__name__ in meth_doc_dict
    
    print("-"*40)
    print("checking presence of simple method")
    assert advanced_instance.another_meth.__name__ in meth_doc_dict
    
    print("-"*40)
    print("checking presence of correct doc method for method in both simple and advanced class")
    assert meth_doc_dict["__init__"] == advanced_instance.__init__.__doc__ != simple_cls.__init__.__doc__
Beispiel #4
0
def test_inspect_methods_str():
    meth_doc_list_actual = netref.inspect_methods(simple_string)
    meth_doc_list_expected = [(name, inspect.getdoc(attr)) for name, attr in inspect.getmembers(simple_string, inspect.isroutine)]
    
    print("-"*40)
    print("Checking get more than inspect gets, as I going above what is in dir")
    result = (set(meth_doc_list_actual) - set(meth_doc_list_expected))
    print("RESULT=", result, "set=", set(meth_doc_list_actual) - set(meth_doc_list_expected))
    assert result
    
    print("-"*40)
    methods_actual = set(name for name, doc in netref.inspect_methods(simple_string))
    a_few_expected_string_methods = set(['startswith', 'encode', 'format', 'isdigit', 'rfind', 'strip'])
    print("Checking I get a few string methods expected in 3.1")
    assert methods_actual > a_few_expected_string_methods
    
    print("-"*40)
    print("check every attr is actually an attr of simple_string")
    assert all([hasattr(simple_string, meth) for meth in methods_actual])
    
    print("-"*40)
    print("check every attr is actually callable")
    assert all([hasattr(getattr(simple_string, meth), "__call__") for meth in methods_actual])
Beispiel #5
0
def test_inspect_methods_list():
    meth_doc_list_actual = netref.inspect_methods(simple_list)
    meth_doc_list_expected = [(name, inspect.getdoc(attr)) for name, attr in inspect.getmembers(simple_list, inspect.isroutine)]
    
    print("-"*40)
    print("Checking get more than inspect gets, as I going above what is in dir")
    result = (set(meth_doc_list_actual) - set(meth_doc_list_expected))
    print("RESULT=", result, "set=", set(meth_doc_list_actual) - set(meth_doc_list_expected))
    assert result
    
    print("-"*40)
    methods_actual = set(name for name, doc in netref.inspect_methods(simple_list))
    a_few_expected_list_methods = set(['append', 'pop', 'extend', 'sort', '__iter__', 'count'])
    print("Checking I get a few list methods expected in 3.1")
    assert methods_actual > a_few_expected_list_methods
    
    print("-"*40)
    print("check every attr is actually an attr of simple_list")
    assert all([hasattr(simple_list, meth) for meth in methods_actual])
    
    print("-"*40)
    print("check every attr is actually callable")
    assert all([hasattr(getattr(simple_list, meth), "__call__") for meth in methods_actual])
Beispiel #6
0
 def make_proxy_for_testing(self, obj):
     func_cls = type(obj)
     clsname = func_cls.__name__
     modname = func_cls.__module__
     methods = netref.inspect_methods(obj)
     proxy_cls = netref.make_proxy_class(clsname, modname, methods)
     
     new_function_oid = self.obj_id.__next__()
     oid = new_function_oid
     
     self.register_object(obj, oid)
     proxy_obj = proxy_cls(self, oid)
     
     return proxy_obj, proxy_cls
Beispiel #7
0
def test_inspect_methods_dict():
    meth_doc_list_actual = netref.inspect_methods(simple_dict)
    meth_doc_list_expected = [(name, inspect.getdoc(attr)) for name, attr in inspect.getmembers(simple_dict, inspect.isroutine)]
    
    print("-"*40)
    print("Checking get more than inspect gets, as I going above what is in dir")
    result = (set(meth_doc_list_actual) - set(meth_doc_list_expected))
    print("RESULT=", result, "set=", set(meth_doc_list_actual) - set(meth_doc_list_expected))
    assert result
    
    print("-"*40)
    methods_actual = set([name for name, doc in netref.inspect_methods(simple_dict)])
    a_few_expected_dict_methods = set(['popitem', 'pop', 'get', 'keys', 'update', '__iter__', 'setdefault', 'items', 'clear'])
    print("Checking I get a few dict methods expected in 3.1")
    assert methods_actual > a_few_expected_dict_methods
    
    print("-"*40)
    print("check every attr is actually an attr of simple_dict")
    assert all([hasattr(simple_dict, meth) for meth in methods_actual])
    
    print("-"*40)
    print("check every attr is actually callable")
    assert all([hasattr(getattr(simple_dict, meth), "__call__") for meth in methods_actual])
Beispiel #8
0
def test_inspect_methods_mul_tuple():
    meth_doc_list_actual = netref.inspect_methods(simple_mul_tuple)
    meth_doc_list_expected = [(name, inspect.getdoc(attr)) for name, attr in inspect.getmembers(simple_mul_tuple, inspect.isroutine)]
    
    print("-"*40)
    print("Checking get more than inspect gets, as I going above what is in dir")
    result = (set(meth_doc_list_actual) - set(meth_doc_list_expected))
    print("RESULT=", result, "set=", set(meth_doc_list_actual) - set(meth_doc_list_expected))
    assert result
    
    print("-"*40)
    methods_actual = set(name for name, doc in netref.inspect_methods(simple_mul_tuple))
    a_few_expected_mul_tuple_methods = set(['__contains__', '__hash__', '__iter__', '__le__', '__len__', 'index'])
    print("Checking I get a few string methods expected in 3.1")
    assert methods_actual > a_few_expected_mul_tuple_methods
    
    print("-"*40)
    print("check every attr is actually an attr of simple_mul_tuple")
    assert all([hasattr(simple_mul_tuple, meth) for meth in methods_actual])
    
    print("-"*40)
    print("check every attr is actually callable")
    assert all([hasattr(getattr(simple_mul_tuple, meth), "__call__") for meth in methods_actual])
Beispiel #9
0
 def _handle_inspect(self, oid):
     # inspect methods is a weird function doesn't return all methods just some that arn't builtins
     """Used for returning the methods needed to build new proxy classes here"""
     return netref.inspect_methods(self._local_objects[oid])
Beispiel #10
0
def test_inspect_methods_module():
    meth_doc_dict = dict(netref.inspect_methods(inspect))
    print("-"*40)
    print("checking presence of __str__ in simple function")
    assert "__str__" in meth_doc_dict