diff options
-rw-r--r-- | TODO.txt | 2 | ||||
-rw-r--r-- | coverage/cmdline.py | 21 | ||||
-rw-r--r-- | coverage/control.py | 11 | ||||
-rw-r--r-- | coverage/execfile.py | 55 |
4 files changed, 43 insertions, 46 deletions
@@ -20,7 +20,7 @@ Key: + .startswith((,)) + "with" statements - .format() ? - - try/except/finally + + try/except/finally + Remove code only run on <2.6 - Change data file to json diff --git a/coverage/cmdline.py b/coverage/cmdline.py index f2f0c152..9ff29f3a 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -564,17 +564,16 @@ class CoverageScript(object): self.coverage.start() code_ran = True try: - try: - if options.module: - sys.path[0] = '' - self.run_python_module(args[0], args) - else: - filename = args[0] - sys.path[0] = os.path.abspath(os.path.dirname(filename)) - self.run_python_file(filename, args) - except NoSource: - code_ran = False - raise + if options.module: + sys.path[0] = '' + self.run_python_module(args[0], args) + else: + filename = args[0] + sys.path[0] = os.path.abspath(os.path.dirname(filename)) + self.run_python_file(filename, args) + except NoSource: + code_ran = False + raise finally: self.coverage.stop() if code_ran: diff --git a/coverage/control.py b/coverage/control.py index 31fc511e..466f76dd 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -686,12 +686,11 @@ class coverage(object): outfile = open(self.config.xml_output, "w") file_to_close = outfile try: - try: - reporter = XmlReporter(self, self.config) - return reporter.report(morfs, outfile=outfile) - except CoverageException: - delete_file = True - raise + reporter = XmlReporter(self, self.config) + return reporter.report(morfs, outfile=outfile) + except CoverageException: + delete_file = True + raise finally: if file_to_close: file_to_close.close() diff --git a/coverage/execfile.py b/coverage/execfile.py index 71ec9318..aec65343 100644 --- a/coverage/execfile.py +++ b/coverage/execfile.py @@ -31,35 +31,34 @@ def run_python_module(modulename, args): openfile = None glo, loc = globals(), locals() try: - try: - # Search for the module - inside its parent package, if any - using - # standard import mechanics. - if '.' in modulename: - packagename, name = rsplit1(modulename, '.') - package = __import__(packagename, glo, loc, ['__path__']) - searchpath = package.__path__ - else: - packagename, name = None, modulename - searchpath = None # "top-level search" in imp.find_module() + # Search for the module - inside its parent package, if any - using + # standard import mechanics. + if '.' in modulename: + packagename, name = rsplit1(modulename, '.') + package = __import__(packagename, glo, loc, ['__path__']) + searchpath = package.__path__ + else: + packagename, name = None, modulename + searchpath = None # "top-level search" in imp.find_module() + openfile, pathname, _ = imp.find_module(name, searchpath) + + # Complain if this is a magic non-file module. + if openfile is None and pathname is None: + raise NoSource( + "module does not live in a file: %r" % modulename + ) + + # If `modulename` is actually a package, not a mere module, then we + # pretend to be Python 2.7 and try running its __main__.py script. + if openfile is None: + packagename = modulename + name = '__main__' + package = __import__(packagename, glo, loc, ['__path__']) + searchpath = package.__path__ openfile, pathname, _ = imp.find_module(name, searchpath) - - # Complain if this is a magic non-file module. - if openfile is None and pathname is None: - raise NoSource( - "module does not live in a file: %r" % modulename - ) - - # If `modulename` is actually a package, not a mere module, then we - # pretend to be Python 2.7 and try running its __main__.py script. - if openfile is None: - packagename = modulename - name = '__main__' - package = __import__(packagename, glo, loc, ['__path__']) - searchpath = package.__path__ - openfile, pathname, _ = imp.find_module(name, searchpath) - except ImportError: - _, err, _ = sys.exc_info() - raise NoSource(str(err)) + except ImportError: + _, err, _ = sys.exc_info() + raise NoSource(str(err)) finally: if openfile: openfile.close() |