我们从Python开源项目中,提取了以下27个代码示例,用于说明如何使用coverage.__version__()。
def __init__(self, cov, config): super(HtmlReporter, self).__init__(cov, config) self.directory = None self.template_globals = { 'escape': escape, 'title': self.config.html_title, '__url__': coverage.__url__, '__version__': coverage.__version__, } self.source_tmpl = Templite( data("pyfile.html"), self.template_globals ) self.coverage = cov self.files = [] self.arcs = self.coverage.data.has_arcs() self.status = HtmlStatus() self.extra_css = None self.totals = Numbers()
def read(self, directory): """Read the last status in `directory`.""" usable = False try: status_file = os.path.join(directory, self.STATUS_FILE) fstatus = open(status_file, "rb") try: status = pickle.load(fstatus) finally: fstatus.close() except (IOError, ValueError): usable = False else: usable = True if status['format'] != self.STATUS_FORMAT: usable = False elif status['version'] != coverage.__version__: usable = False if usable: self.files = status['files'] self.settings = status['settings'] else: self.reset()
def __init__(self, cov, config): super(HtmlReporter, self).__init__(cov, config) self.directory = None title = self.config.html_title if env.PY2: title = title.decode("utf8") self.template_globals = { 'escape': escape, 'pair': pair, 'title': title, '__url__': coverage.__url__, '__version__': coverage.__version__, } self.source_tmpl = Templite( data("pyfile.html"), self.template_globals ) self.coverage = cov self.files = [] self.has_arcs = self.coverage.data.has_arcs() self.status = HtmlStatus() self.extra_css = None self.totals = Numbers() self.time_stamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
def read(self, directory): """Read the last status in `directory`.""" usable = False try: status_file = os.path.join(directory, self.STATUS_FILE) with open(status_file, "r") as fstatus: status = json.load(fstatus) except (IOError, ValueError): usable = False else: usable = True if status['format'] != self.STATUS_FORMAT: usable = False elif status['version'] != coverage.__version__: usable = False if usable: self.files = {} for filename, fileinfo in iitems(status['files']): fileinfo['index']['nums'] = Numbers(*fileinfo['index']['nums']) self.files[filename] = fileinfo self.settings = status['settings'] else: self.reset()
def write(self, directory): """Write the current status to `directory`.""" status_file = os.path.join(directory, self.STATUS_FILE) files = {} for filename, fileinfo in iitems(self.files): fileinfo['index']['nums'] = fileinfo['index']['nums'].init_args() files[filename] = fileinfo status = { 'format': self.STATUS_FORMAT, 'version': coverage.__version__, 'settings': self.settings, 'files': files, } with open(status_file, "w") as fout: json.dump(status, fout) # Older versions of ShiningPanda look for the old name, status.dat. # Accomodate them if we are running under Jenkins. # https://issues.jenkins-ci.org/browse/JENKINS-28428 if "JENKINS_URL" in os.environ: with open(os.path.join(directory, "status.dat"), "w") as dat: dat.write("https://issues.jenkins-ci.org/browse/JENKINS-28428\n")
def write(self, directory): """Write the current status to `directory`.""" status_file = os.path.join(directory, self.STATUS_FILE) status = { 'format': self.STATUS_FORMAT, 'version': coverage.__version__, 'settings': self.settings, 'files': self.files, } fout = open(status_file, "wb") try: pickle.dump(status, fout) finally: fout.close()
def sysinfo(self): """Return a list of (key, value) pairs showing internal information.""" import coverage as covmod import platform, re try: implementation = platform.python_implementation() except AttributeError: implementation = "unknown" info = [ ('version', covmod.__version__), ('coverage', covmod.__file__), ('cover_dir', self.cover_dir), ('pylib_dirs', self.pylib_dirs), ('tracer', self.collector.tracer_name()), ('config_files', self.config.attempted_config_files), ('configs_read', self.config.config_files), ('data_path', self.data.filename), ('python', sys.version.replace('\n', '')), ('platform', platform.platform()), ('implementation', implementation), ('executable', sys.executable), ('cwd', os.getcwd()), ('path', sys.path), ('environment', sorted([ ("%s = %s" % (k, v)) for k, v in iitems(os.environ) if re.search(r"^COV|^PY", k) ])), ('command_line', " ".join(getattr(sys, 'argv', ['???']))), ] if self.source_match: info.append(('source_match', self.source_match.info())) if self.include_match: info.append(('include_match', self.include_match.info())) if self.omit_match: info.append(('omit_match', self.omit_match.info())) if self.cover_match: info.append(('cover_match', self.cover_match.info())) if self.pylib_match: info.append(('pylib_match', self.pylib_match.info())) return info
def covered_main(includes, require_native=None, required_percentage=100.0, disable_coverage=True): """Equivalent of unittest.main(), except that it gathers coverage data, and asserts if the test is not at 100% coverage. Args: includes (list(str) or str) - List of paths to include in coverage report. May also be a single path instead of a list. require_native (str) - If non-None, will require that at least |require_native| version of coverage is installed on the system with CTracer. disable_coverage (bool) - If True, just run unittest.main() without any coverage tracking. Bug: crbug.com/662277 """ if disable_coverage: unittest.main() return try: import coverage if require_native is not None: got_ver = coverage.__version__ if not getattr(coverage.collector, 'CTracer', None): native_error(( "Native python-coverage module required.\n" "Pure-python implementation (version: %s) found: %s" ) % (got_ver, coverage), require_native) if got_ver < distutils.version.LooseVersion(require_native): native_error("Wrong version (%s) found: %s" % (got_ver, coverage), require_native) except ImportError: if require_native is None: sys.path.insert(0, os.path.join(ROOT_PATH, 'third_party')) import coverage else: print ("ERROR: python-coverage (%s) is required to be installed on your " "PYTHONPATH to run this test." % require_native) sys.exit(1) COVERAGE = coverage.coverage(include=includes) COVERAGE.start() retcode = 0 try: unittest.main() except SystemExit as e: retcode = e.code or retcode COVERAGE.stop() if COVERAGE.report() < required_percentage: print 'FATAL: not at required %f%% coverage.' % required_percentage retcode = 2 return retcode
def sys_info(self): """Return a list of (key, value) pairs showing internal information.""" import coverage as covmod self._init() ft_plugins = [] for ft in self.plugins.file_tracers: ft_name = ft._coverage_plugin_name if not ft._coverage_enabled: ft_name += " (disabled)" ft_plugins.append(ft_name) info = [ ('version', covmod.__version__), ('coverage', covmod.__file__), ('cover_dirs', self.cover_dirs), ('pylib_dirs', self.pylib_dirs), ('tracer', self.collector.tracer_name()), ('plugins.file_tracers', ft_plugins), ('config_files', self.config.attempted_config_files), ('configs_read', self.config.config_files), ('data_path', self.data_files.filename), ('python', sys.version.replace('\n', '')), ('platform', platform.platform()), ('implementation', platform.python_implementation()), ('executable', sys.executable), ('cwd', os.getcwd()), ('path', sys.path), ('environment', sorted( ("%s = %s" % (k, v)) for k, v in iitems(os.environ) if k.startswith(("COV", "PY")) )), ('command_line', " ".join(getattr(sys, 'argv', ['???']))), ] matcher_names = [ 'source_match', 'source_pkgs_match', 'include_match', 'omit_match', 'cover_match', 'pylib_match', ] for matcher_name in matcher_names: matcher = getattr(self, matcher_name) if matcher: matcher_info = matcher.info() else: matcher_info = '-none-' info.append((matcher_name, matcher_info)) return info # FileDisposition "methods": FileDisposition is a pure value object, so it can # be implemented in either C or Python. Acting on them is done with these # functions.