def to_markdown(self): logger.info('Reporting on path: {0}'.format(self.path)) # TODO: Create a nicer formatting and section formatter # import pprint # pprint.pprint(dict(get_sorted_file_directory_structure(report.keys()))) # section_tracker = [-1] processed = '' for file_name, file_report in self._report.items(): depth_of_dir = get_depth_of_file(file_name) # try: # section_tracker[depth_of_dir] += 1 # except IndexError: # original_len = len(section_tracker) # while len(section_tracker) < depth_of_dir: # section_tracker.append(-1) # for item in range(1, original_len): # section_tracker[item] += 1 # processed += '{2} | {1} File: {0}\n\n'.format(file_name, # '#' * (depth_of_dir), # '.'.join(str(index) for index in section_tracker[0:depth_of_dir])) processed += '{1} File: {0}\n\n'.format(file_name, '#' * (depth_of_dir - 1)) for class_name, class_dict in file_report.objects.items(): # Check if we've come to the function key, which specifies functions without a class if class_name == 'function': for function_name, function_report in class_dict.items(): if function_report.description is None: continue name_string = '- {0}'.format(function_name) if function_report.test_info.requires_update: info_string = '- This function requires an update before being processed' else: info_string = '- {0}: {1}'.format(function_report.name, function_report.test_info.test_info) desc_string = '- {0}'.format(function_report.description) processed += indent_string(name_string, 0) processed += indent_string(info_string, 1) processed += indent_string(desc_string, 2) continue # Now we know we have classes or defined functions left processed += indent_string('- ' + class_name, 0) if class_dict.type == 'class': for function_name, function_dict in class_dict.function.items(): if function_dict.description is None: continue if function_dict.test_info.requires_update: info_string = '- This function requires an update before being processed' else: info_string = '- {0}: {1}'.format(function_dict.name, function_dict.test_info.test_info) desc_string = '- {0}'.format(function_dict.description) processed += indent_string(info_string, 1) processed += indent_string(desc_string, 2) elif class_dict.type == 'function': processed += indent_string('- ' + class_dict.name) else: pass processed += '\n' return processed
def test_no_newline(self): assert util.indent_string('no newline') == ' no newline\n'
def to_markdown(self): logger.info('Reporting on path: {0}'.format(self.path)) # TODO: Create a nicer formatting and section formatter # import pprint # pprint.pprint(dict(get_sorted_file_directory_structure(report.keys()))) # section_tracker = [-1] processed = '' for file_name, file_report in self._report.items(): depth_of_dir = get_depth_of_file(file_name) # try: # section_tracker[depth_of_dir] += 1 # except IndexError: # original_len = len(section_tracker) # while len(section_tracker) < depth_of_dir: # section_tracker.append(-1) # for item in range(1, original_len): # section_tracker[item] += 1 # processed += '{2} | {1} File: {0}\n\n'.format(file_name, # '#' * (depth_of_dir), # '.'.join(str(index) for index in section_tracker[0:depth_of_dir])) processed += '{1} File: {0}\n\n'.format(file_name, '#' * (depth_of_dir - 1)) for class_name, class_dict in file_report.objects.items(): # Check if we've come to the function key, which specifies functions without a class if class_name == 'function': for function_name, function_report in class_dict.items(): if function_report.description is None: continue name_string = '- {0}'.format(function_name) if function_report.test_info.requires_update: info_string = '- This function requires an update before being processed' else: info_string = '- {0}: {1}'.format( function_report.name, function_report.test_info.test_info) desc_string = '- {0}'.format( function_report.description) processed += indent_string(name_string, 0) processed += indent_string(info_string, 1) processed += indent_string(desc_string, 2) continue # Now we know we have classes or defined functions left processed += indent_string('- ' + class_name, 0) if class_dict.type == 'class': for function_name, function_dict in class_dict.function.items( ): if function_dict.description is None: continue if function_dict.test_info.requires_update: info_string = '- This function requires an update before being processed' else: info_string = '- {0}: {1}'.format( function_dict.name, function_dict.test_info.test_info) desc_string = '- {0}'.format(function_dict.description) processed += indent_string(info_string, 1) processed += indent_string(desc_string, 2) elif class_dict.type == 'function': processed += indent_string('- ' + class_dict.name) else: pass processed += '\n' return processed
def test_with_other_spacing(self): assert util.indent_string('new spacing', 2, '~~~') == '~~~~~~new spacing\n'
def test_none(self): assert util.indent_string(None) == ''
def test_with_newline(self): assert util.indent_string('with newline\n') == ' with newline\n'
def test_with_newline_and_indent(self): assert util.indent_string('with newline\n', 2) == ' with newline\n'
def test_with_multiple_newlines(self): s = 'wow newlines\n\n\n' assert util.indent_string(s) == ' wow newlines\n'