Commits

Mikhail Korobov committed be73761 Merge

Merge pull request #5 from noxan/python3

Python 3 support

  • Participants
  • Parent commits 1af6bd4, a45e246
  • Branches default, master

Comments (0)

Files changed (15)

+*.pyc

File django_coverage/coverage_runner.py

             settings.COVERAGE_PATH_EXCLUDES)
 
         if settings.COVERAGE_USE_STDOUT:
-            coverage.report(modules.values(), show_missing=1)
+            coverage.report(list(modules.values()), show_missing=1)
             if excludes:
                 message = "The following packages or modules were excluded:"
-                print >>sys.stdout
-                print >>sys.stdout, message,
+                print("")
+                print(message)
                 for e in excludes:
-                    print >>sys.stdout, e,
-                print >>sys.stdout
+                    print(e)
+                print("")
             if errors:
                 message = "There were problems with the following packages "
                 message += "or modules:"
-                print >>sys.stdout
-                print >>sys.stderr, message,
+                print("")
+                print(message)
                 for e in errors:
-                    print >>sys.stderr, e,
-                print >>sys.stdout
+                    print(e)
+                print("")
 
         outdir = settings.COVERAGE_REPORT_HTML_OUTPUT_DIR
         if outdir:
             if settings.COVERAGE_CUSTOM_REPORTS:
                 html_report(outdir, modules, excludes, errors)
             else:
-                coverage._the_coverage.html_report(modules.values(), outdir)
-            print >>sys.stdout
-            print >>sys.stdout, "HTML reports were output to '%s'" %outdir
+                coverage._the_coverage.html_report(list(modules.values()), outdir)
+            print("")
+            print("HTML reports were output to '%s'" %outdir)
 
         return results

File django_coverage/utils/coverage_report/__init__.py

 limitations under the License.
 """
 
-from html_report import *
-
+from django_coverage.utils.coverage_report.html_report import *

File django_coverage/utils/coverage_report/data_storage.py

         if percent_covered < 75: severity = 'warning'
         if percent_covered < 50: severity = 'critical'
 
-        for k, v in locals().iteritems():
+        for k, v in locals().items():
             setattr(self, k, v)
 

File django_coverage/utils/coverage_report/html_module_detail.py

 
 import cgi, os
 
-from data_storage import ModuleVars
-from templates import default_module_detail as module_detail
+from django_coverage.utils.coverage_report.data_storage import ModuleVars
+from django_coverage.utils.coverage_report.templates import default_module_detail as module_detail
 
 def html_module_detail(filename, module_name, nav=None):
     """
     m_vars.source_lines = source_lines = list()
     i = 0
     for i, source_line in enumerate(
-        [cgi.escape(l.rstrip()) for l in file(m_vars.source_file, 'rb').readlines()]):
+        [cgi.escape(l.rstrip()) for l in open(m_vars.source_file, 'r').readlines()]):
         line_status = 'ignored'
         if i+1 in m_vars.executed: line_status = 'executed'
         if i+1 in m_vars.excluded: line_status = 'excluded'
         nav_html = module_detail.NAV_NO_PREV %nav
     else:
         nav_html = None
-            
-    fo = file(filename, 'wb+')
-    print >>fo, module_detail.TOP %m_vars.__dict__
+
+    fo = open(filename, 'w+')
+    fo.write(module_detail.TOP %m_vars.__dict__)
     if nav and nav_html:
-        print >>fo, nav_html
-    print >>fo, module_detail.CONTENT_HEADER %m_vars.__dict__
-    print >>fo, module_detail.CONTENT_BODY %m_vars.__dict__
+        fo.write(nav_html)
+    fo.write(module_detail.CONTENT_HEADER %m_vars.__dict__)
+    fo.write(module_detail.CONTENT_BODY %m_vars.__dict__)
     if nav and nav_html:
-        print >>fo, nav_html
-    print >>fo, module_detail.BOTTOM
+        fo.write(nav_html)
+    fo.write(module_detail.BOTTOM)
     fo.close()
-

File django_coverage/utils/coverage_report/html_module_errors.py

 limitations under the License.
 """
 
-from html_module_exceptions import html_module_exceptions
-from templates import default_module_errors as module_errors
+from django_coverage.utils.coverage_report.html_module_exceptions import html_module_exceptions
+from django_coverage.utils.coverage_report.templates import default_module_errors as module_errors
 
 def html_module_errors(filename, errors):
     """

File django_coverage/utils/coverage_report/html_module_exceptions.py

         exception_list.append(template.EXCEPTION_LINE %vars())
     exception_list = os.linesep.join(exception_list)
 
-    fo = file(filename, 'wb+')
-    print >>fo, template.TOP
-    print >>fo, template.CONTENT_HEADER
-    print >>fo, template.CONTENT_BODY %vars()
-    print >>fo, template.BOTTOM
+    fo = open(filename, 'w+')
+    fo.write(template.TOP)
+    fo.write(template.CONTENT_HEADER)
+    fo.write(template.CONTENT_BODY %vars())
+    fo.write(template.BOTTOM)
     fo.close()
-

File django_coverage/utils/coverage_report/html_module_excludes.py

 Changed by Mikhail Korobov.
 """
 
-from html_module_exceptions import html_module_exceptions
-from templates import default_module_excludes as module_excludes
+from django_coverage.utils.coverage_report.html_module_exceptions import html_module_exceptions
+from django_coverage.utils.coverage_report.templates import default_module_excludes as module_excludes
 
 def html_module_excludes(filename, excludes):
     """
     not contain any executable statements:
     """
     html_module_exceptions(filename, excludes, module_excludes, long_desc)
-

File django_coverage/utils/coverage_report/html_report.py

 """
 
 import os, time
-from urllib import pathname2url as p2url
+try:
+    from urllib import pathname2url as p2url
+except ImportError:
+    from urllib.request import pathname2url as p2url
 
-from data_storage import ModuleVars
-from html_module_detail import html_module_detail
-from html_module_errors import html_module_errors
-from html_module_excludes import html_module_excludes
-from templates import default_module_index as module_index
+from django_coverage.utils.coverage_report.data_storage import ModuleVars
+from django_coverage.utils.coverage_report.html_module_detail import html_module_detail
+from django_coverage.utils.coverage_report.html_module_errors import html_module_errors
+from django_coverage.utils.coverage_report.html_module_excludes import html_module_excludes
+from django_coverage.utils.coverage_report.templates import default_module_index as module_index
 from django_coverage import settings
 
 def html_report(outdir, modules, excludes=None, errors=None):
     total_excluded = 0
     total_stmts = 0
     module_stats = list()
-    m_names = modules.keys()
+    m_names = list(modules.keys())
     m_names.sort()
     for n in m_names:
         m_vars = ModuleVars(n, modules[n])
     else:
         overall_covered = 0.0
 
-    m_names = modules.keys()
+    m_names = list(modules.keys())
     m_names.sort()
     i = 0
     for i, n in enumerate(m_names):
         html_module_detail(
             os.path.join(m_dir, m_vars.module_name + '.html'), n, nav)
 
-    fo = file(os.path.join(outdir, 'index.html'), 'wb+')
-    print >>fo, module_index.TOP
-    print >>fo, module_index.CONTENT_HEADER %vars()
-    print >>fo, module_index.CONTENT_BODY %vars()
+    fo = open(os.path.join(outdir, 'index.html'), 'w+')
+    fo.write(module_index.TOP)
+    fo.write(module_index.CONTENT_HEADER %vars())
+    fo.write(module_index.CONTENT_BODY %vars())
     if excludes:
         _file = 'excludes.html'
         exceptions_link = _file
         exception_desc = "Excluded packages and modules"
-        print >>fo, module_index.EXCEPTIONS_LINK %vars()
+        fo.write(module_index.EXCEPTIONS_LINK %vars())
         html_module_excludes(os.path.join(outdir, _file), excludes)
     if errors:
         _file = 'errors.html'
         exceptions_link = _file
         exception_desc = "Error packages and modules"
-        print >>fo, module_index.EXCEPTIONS_LINK %vars()
+        fo.write(module_index.EXCEPTIONS_LINK %vars())
         html_module_errors(os.path.join(outdir, _file), errors)
-    print >>fo, module_index.BOTTOM
+    fo.write(module_index.BOTTOM)
     fo.close()
-    
+
     if settings.COVERAGE_BADGE_TYPE:
         badge = open(os.path.join(
             os.path.dirname(__file__),
             'badges',
             settings.COVERAGE_BADGE_TYPE,
             '%s.png' % int(overall_covered)
-        )).read()
+        ), 'rb').read()
         open(os.path.join(outdir, 'coverage_status.png'), 'wb').write(badge)
-

File django_coverage/utils/coverage_report/templates/default_module_errors.py

 limitations under the License.
 """
 
-from default_module_exceptions import *
+from django_coverage.utils.coverage_report.templates.default_module_exceptions import *
 
 title = "error packages and modules"
 
 TOP = TOP %vars()
 CONTENT_HEADER = CONTENT_HEADER %vars()
-

File django_coverage/utils/coverage_report/templates/default_module_excludes.py

 limitations under the License.
 """
 
-from default_module_exceptions import *
+from django_coverage.utils.coverage_report.templates.default_module_exceptions import *
 
 title = "excluded packages and modules"
 
 TOP = TOP %vars()
 CONTENT_HEADER = CONTENT_HEADER %vars()
-

File django_coverage/utils/module_tools/__init__.py

 limitations under the License.
 """
 
-from module_loader import *
-from module_walker import *
-
+from django_coverage.utils.module_tools.module_loader import *
+from django_coverage.utils.module_tools.module_walker import *

File django_coverage/utils/module_tools/data_storage.py

 
 __all__ = ('Packages', 'Modules', 'Excluded', 'Errors')
 
+
 class SingletonType(type):
     def __call__(cls, *args, **kwargs):
         if getattr(cls, '__instance__', None) is None:
             cls.__instance__ = instance
         return cls.__instance__
 
-class Packages(object):
-    __metaclass__ = SingletonType
+
+Singleton = SingletonType('SingletonMetaClass', (object,), {})
+
+
+class Packages(Singleton):
     packages = {}
 
-class Modules(object):
-    __metaclass__ = SingletonType
+
+class Modules(Singleton):
     modules = {}
 
-class Excluded(object):
-    __metaclass__ = SingletonType
+
+class Excluded(Singleton):
     excluded = []
 
-class Errors(object):
-    __metaclass__ = SingletonType
+
+class Errors(Singleton):
     errors = []
-

File django_coverage/utils/module_tools/module_loader.py

 __all__ = ('find_or_load_module',)
 
 def _brute_force_find_module(module_name, module_path, module_type):
-    for m in [m for n, m in sys.modules.iteritems() if type(m) == types.ModuleType]:
+    for m in [m for n, m in sys.modules.items() if type(m) == types.ModuleType]:
         m_path = []
         try:
             if module_type in (imp.PY_COMPILED, imp.PY_SOURCE):

File django_coverage/utils/module_tools/module_walker.py

 limitations under the License.
 """
 
-import os, re, sys
+import os, re
 from glob import glob
 
-from data_storage import *
-from module_loader import find_or_load_module
+from django_coverage.utils.module_tools.data_storage import *
+from django_coverage.utils.module_tools.module_loader import find_or_load_module
 
 try:
     set
 
     whitelist = _prune_whitelist(whitelist, blacklist or [])
     _parse_module_list(whitelist)
-    for pkg_name, pkg in packages.copy().iteritems():
+    for pkg_name, pkg in packages.copy().items():
         _get_all_packages(pkg_name, pkg, blacklist, exclude_dirs)
-    for pkg_name, pkg in packages.copy().iteritems():
+    for pkg_name, pkg in packages.copy().items():
         _get_all_modules(pkg_name, pkg, blacklist)
     return packages, modules, list(set(excluded)), list(set(errors))
-