def test_to_dict__class_with_extra_function(self): from parsefilelib.models.file_obj import FileObj test_file_path = self.get_test_file_path('class_with_extra_functions.py') file_obj = FileObj(test_file_path) d = file_obj.to_dict() assert len(d['classes']) == 1 assert len(d['functions']) == 1 assert d['parent_file_path'] == test_file_path assert len(d['imports']) == 0 assert d['indent'] == -1 assert d['is_class'] == False assert d['is_function'] == False assert len(d['lines']) == 13 assert d['name'] == 'class_with_extra_functions.py' assert d['obj_type'] == 'file' assert len(d['returns']) == 0 assert len(d['variables']) == 0 assert len(d['classes'][0]['returns']) == 0 assert d['classes'][0]['obj_type'] == 'class' assert d['classes'][0]['is_function'] == False assert d['classes'][0]['is_class'] == True assert d['classes'][0]['name'] == 'Foo' assert len(d['functions'][0]['returns']) == 1 assert len(d['functions'][0]['variables']) == 0 assert d['functions'][0]['obj_type'] == 'function' assert d['functions'][0]['is_function'] == True assert d['functions'][0]['is_class'] == False assert d['functions'][0]['name'] == 'extra'
def test_to_dict__simple_2(self): from parsefilelib.models.file_obj import FileObj test_file_path = self.get_test_file_path('simple_2.py') file_obj = FileObj(test_file_path) d = file_obj.to_dict() assert len(d['classes']) == 0 assert len(d['functions']) == 2 assert d['parent_file_path'] == test_file_path assert len(d['imports']) == 0 assert d['indent'] == -1 assert d['is_class'] == False assert d['is_function'] == False assert len(d['lines']) == 7 assert d['name'] == 'simple_2.py' assert d['obj_type'] == 'file' assert len(d['returns']) == 0 assert len(d['variables']) == 0 assert len(d['functions'][0]['returns']) == 1 assert d['functions'][0]['obj_type'] == 'function' assert d['functions'][0]['is_function'] == True assert d['functions'][0]['is_class'] == False assert d['functions'][0]['name'] == 'first_function' assert len(d['functions'][1]['returns']) == 1 assert len(d['functions'][1]['variables']) == 0 assert d['functions'][1]['obj_type'] == 'function' assert d['functions'][1]['is_function'] == True assert d['functions'][1]['is_class'] == False assert d['functions'][1]['name'] == 'second_function'
def test_to_dict__decorators(self): from parsefilelib.models.file_obj import FileObj test_file_path = self.get_test_file_path('decorators.py') file_obj = FileObj(test_file_path) d = file_obj.to_dict() assert len(d['classes']) == 0 assert len(d['functions']) == 3 assert d['parent_file_path'] == test_file_path assert len(d['imports']) == 0 assert d['indent'] == -1 assert d['is_class'] == False assert d['is_function'] == False assert len(d['lines']) == 15 assert d['name'] == 'decorators.py' assert d['obj_type'] == 'file' assert len(d['returns']) == 0 assert len(d['variables']) == 0 assert len(d['functions'][0]['returns']) == 1 assert len(d['functions'][0]['functions']) == 0 assert len(d['functions'][0]['variables']) == 1 assert len(d['functions'][0]['decorators']) == 0 assert d['functions'][0]['docstring'] == None assert d['functions'][0]['obj_type'] == 'function' assert d['functions'][0]['is_function'] == True assert d['functions'][0]['is_class'] == False assert d['functions'][0]['name'] == 'foo' assert len(d['functions'][1]['returns']) == 1 assert len(d['functions'][1]['functions']) == 0 assert len(d['functions'][1]['variables']) == 1 assert len(d['functions'][1]['decorators']) == 1 assert d['functions'][1]['docstring'] == None assert d['functions'][1]['obj_type'] == 'function' assert d['functions'][1]['is_function'] == True assert d['functions'][1]['is_class'] == False assert d['functions'][1]['name'] == 'bar' assert len(d['functions'][2]['returns']) == 1 assert len(d['functions'][2]['functions']) == 0 assert len(d['functions'][2]['variables']) == 1 assert len(d['functions'][2]['decorators']) == 3 assert d['functions'][2]['docstring'] == None assert d['functions'][2]['obj_type'] == 'function' assert d['functions'][2]['is_function'] == True assert d['functions'][2]['is_class'] == False assert d['functions'][2]['name'] == 'foobar'
def test_to_dict__docstrings(self): from parsefilelib.models.file_obj import FileObj test_file_path = self.get_test_file_path('docstrings.py') file_obj = FileObj(test_file_path) d = file_obj.to_dict() assert len(d['classes']) == 0 assert len(d['functions']) == 8 assert d['parent_file_path'] == test_file_path assert len(d['imports']) == 0 assert d['indent'] == -1 assert d['is_class'] == False assert d['is_function'] == False assert len(d['lines']) == 61 assert d['name'] == 'docstrings.py' assert d['obj_type'] == 'file' assert len(d['returns']) == 0 assert len(d['variables']) == 0 assert len(d['functions'][0]['returns']) == 1 assert d['functions'][0]['obj_type'] == 'function' assert d['functions'][0]['is_function'] == True assert d['functions'][0]['is_class'] == False assert d['functions'][0]['name'] == 'first_docstring_function' assert len(d['functions'][6]['returns']) == 1 assert len(d['functions'][6]['variables']) == 1 assert d['functions'][6]['obj_type'] == 'function' assert d['functions'][6]['is_function'] == True assert d['functions'][6]['is_class'] == False assert d['functions'][6]['name'] == 'seventh_docstring_function' assert d['functions'][6]['docstring'] == 'docstring with def in it' assert len(d['functions'][7]['returns']) == 1 assert len(d['functions'][7]['variables']) == 1 assert d['functions'][7]['obj_type'] == 'function' assert d['functions'][7]['is_function'] == True assert d['functions'][7]['is_class'] == False assert d['functions'][7]['name'] == 'eighth_docstring_function' assert d['functions'][7]['docstring'] == 'docstring that is put all the way to the left'
def test_to_dict__strings(self): from parsefilelib.models.file_obj import FileObj test_file_path = self.get_test_file_path('strings.py') file_obj = FileObj(test_file_path) import pdb;pdb.set_trace() d = file_obj.to_dict() assert len(d['classes']) == 1 assert len(d['functions']) == 0 assert d['parent_file_path'] == test_file_path assert len(d['imports']) == 4 assert d['indent'] == -1 assert d['is_class'] == False assert d['is_function'] == False assert len(d['lines']) == 24 assert d['name'] == 'strings.py' assert d['obj_type'] == 'file' assert len(d['returns']) == 0 assert len(d['variables']) == 0 assert len(d['classes'][0]['returns']) == 0 assert len(d['classes'][0]['functions']) == 2 assert d['classes'][0]['obj_type'] == 'class' assert d['classes'][0]['is_function'] == False assert d['classes'][0]['is_class'] == True assert d['classes'][0]['name'] == 'Foo' assert d['classes'][0]['docstring'] == 'def hello():\n cool\n\ndef nice\n ' assert len(d['classes'][0]['functions'][1]['returns']) == 1 assert len(d['classes'][0]['functions'][1]['variables']) == 0 assert d['classes'][0]['functions'][1]['obj_type'] == 'function' assert d['classes'][0]['functions'][1]['is_function'] == True assert d['classes'][0]['functions'][1]['is_class'] == False assert d['classes'][0]['functions'][1]['name'] == 'bar2' assert d['classes'][0]['functions'][1]['docstring'] == None