def explore_folder(foldername: str, recursive=True):
    files_to_load = []
    explored = OrderedDict()

    logger.debug('Exploring folder %s from folder %s', foldername, str(os.getcwd()))
    for load, name, is_pkg in pkgutil.walk_packages([foldername]):
        if not recursive and is_pkg:
            continue

        if is_pkg:
            path = load.path + name + os.sep
            logger.debug(path)
            temp_explored = explore_folder(path)
            for key, value in temp_explored.items():
                explored[key] = value
                # explored.move_to_end(key)
        else:
            files_to_load.append(load.path + name + '.py')

    for current_file in files_to_load:
        logger.info('File: %s', str(current_file))
        temp = ExploredFile(current_file)
        temp.explore()
        explored[current_file] = temp

    # TODO: Get the order sorted by files, then directories
    explored = OrderedDict(sorted(explored.items(), key=lambda x: get_depth_of_file(x[0])))

    return explored
    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
Beispiel #3
0
 def test_handles_mixed_slashes(self):
     assert util.get_depth_of_file('this/folder\\mixed.py') == 3
    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
Beispiel #5
0
 def test_ignores_leading_dot_slash(self):
     assert util.get_depth_of_file('.\\folder\\file.py') == 2
Beispiel #6
0
 def test_does_not_ignore_leading_slash(self):
     # TODO: Decide if this is the behavior I want
     assert util.get_depth_of_file('/usr/file.py') == 3
Beispiel #7
0
 def test_no_depth(self):
     assert util.get_depth_of_file('file.py') == 1
Beispiel #8
0
 def test_get_one_depth(self):
     assert util.get_depth_of_file('folder/file.py') == 2
 def test_handles_mixed_slashes(self):
     assert util.get_depth_of_file('this/folder\\mixed.py') == 3
 def test_does_not_ignore_leading_slash(self):
     # TODO: Decide if this is the behavior I want
     assert util.get_depth_of_file('/usr/file.py') == 3
 def test_ignores_leading_dot_slash(self):
     assert util.get_depth_of_file('.\\folder\\file.py') == 2
 def test_get_one_depth(self):
     assert util.get_depth_of_file('folder/file.py') == 2
 def test_no_depth(self):
     assert util.get_depth_of_file('file.py') == 1