Example #1
0
    def _generate_module_report(self, module_name):
        out = []
        module_data = self._import_data.get(module_name)
        if not module_data:
            msg = "No data found for module '{0}'".format(module_name)
            out.append(msg)
            return out

        required = None
        if self._required_packages:
            if module_name in self._required_packages:
                required = '\nIn Required: Yes'
            else:
                required = '\nIn Required: No'
        else:
            required = ''

        msg = "Module Name: '{0}'{1}".format(module_name, required)
        out.append(formatter.format_header(msg=msg, width=self._width))

        for file_path in sorted(module_data.keys()):
            import_data = module_data[file_path]
            out.append('"{0}"'.format(file_path))
            for (lineno, line) in import_data:
                msg = "line {0}:\n{1}".format(lineno, line)
                out.append(msg)

        return out
Example #2
0
    def _get_module_report(self, module_name, has_header=False):
        out = []
        import_data = {}
        for file_name, imports in self.import_map.iteritems():
            for index, import_name in enumerate(imports):
                if import_name == module_name:
                    import_data.setdefault(
                        self.file_paths.get(file_name), []).append(index + 1)

        if not has_header:
            report_header = ("\nImport Report for '{0}'").format(module_name)
            out.append(report_header)

        required = None
        if self.required_packages:
            if module_name in self._required_packages:
                required = '\nIn Required: Yes'
            else:
                required = '\nIn Required: No'
        else:
            required = ''
        msg = "Module Name: '{0}'{1}".format(module_name, required)
        out.append(formatter.format_header(msg=msg, width=self.width))

        for file_path in sorted(import_data.keys()):
            out.append('"{0}"'.format(file_path))
            for lineno in import_data[file_path]:
                line = 'import {0}\n'.format(module_name)
                msg = "line {0}:\n{1}".format(lineno, line)
                out.append(msg)

        return out
Example #3
0
 def test_format_header_05(self):
     self.assertEquals(
         formatter.format_header(self.msg,
                                 top=False,
                                 bottom=False,
                                 width=self.width02),
         self.msg,
     )
Example #4
0
 def test_format_header_04(self):
     self.assertEquals(
         formatter.format_header(
             self.msg,
             bottom=False,
             width=self.width01,
         ),
         self.expected_string_04,
     )
Example #5
0
 def test_format_header_02(self):
     self.assertEquals(
         formatter.format_header(
             self.msg,
             format_char="*",
             width=self.width01,
         ),
         self.expected_string_02,
     )
Example #6
0
    def _get_report(self):
        out = []
        report_header = '\nImport Report'
        out.append(report_header)
        for module_name in sorted(self._import_data.keys()):
            out += self._get_module_report(module_name, has_header=True)

        if not self._required_packages:
            return formatter.format_output(out, width=self._width)

        required_extras = sorted(
            set(self._required_packages).difference(self._import_data.keys()))
        if required_extras:
            msg = 'Following packages are required but never imported:'
            out.append(formatter.format_header(msg=msg, width=self._width))
            out.append(formatter.format_iterable(required_extras))
        return formatter.format_output(out, width=self._width)
Example #7
0
 def test_format_header_03(self):
     self.assertEquals(
         formatter.format_header(self.msg, top=False, width=self.width01),
         self.expected_string_03,
     )
Example #8
0
 def test_format_header_01(self):
     self.assertEquals(
         formatter.format_header(self.msg, auto_length=True),
         self.expected_string_01,
     )