eric6/DebugClients/Python/coverage/control.py

changeset 7702
f8b97639deb5
parent 7427
362cd1b6f81a
child 7975
7d493839a8fc
equal deleted inserted replaced
7701:25f42e208e08 7702:f8b97639deb5
97 return None 97 return None
98 98
99 def __init__( 99 def __init__(
100 self, data_file=_DEFAULT_DATAFILE, data_suffix=None, cover_pylib=None, 100 self, data_file=_DEFAULT_DATAFILE, data_suffix=None, cover_pylib=None,
101 auto_data=False, timid=None, branch=None, config_file=True, 101 auto_data=False, timid=None, branch=None, config_file=True,
102 source=None, omit=None, include=None, debug=None, 102 source=None, source_pkgs=None, omit=None, include=None, debug=None,
103 concurrency=None, check_preimported=False, context=None, 103 concurrency=None, check_preimported=False, context=None,
104 ): 104 ): # pylint: disable=too-many-arguments
105 """ 105 """
106 Many of these arguments duplicate and override values that can be 106 Many of these arguments duplicate and override values that can be
107 provided in a configuration file. Parameters that are missing here 107 provided in a configuration file. Parameters that are missing here
108 will use values from the config file. 108 will use values from the config file.
109 109
144 144
145 `source` is a list of file paths or package names. Only code located 145 `source` is a list of file paths or package names. Only code located
146 in the trees indicated by the file paths or package names will be 146 in the trees indicated by the file paths or package names will be
147 measured. 147 measured.
148 148
149 `source_pkgs` is a list of package names. It works the same as
150 `source`, but can be used to name packages where the name can also be
151 interpreted as a file path.
152
149 `include` and `omit` are lists of file name patterns. Files that match 153 `include` and `omit` are lists of file name patterns. Files that match
150 `include` will be measured, files that match `omit` will not. Each 154 `include` will be measured, files that match `omit` will not. Each
151 will also accept a single string argument. 155 will also accept a single string argument.
152 156
153 `debug` is a list of strings indicating what debugging information is 157 `debug` is a list of strings indicating what debugging information is
174 The `concurrency` parameter can now be a list of strings. 178 The `concurrency` parameter can now be a list of strings.
175 179
176 .. versionadded:: 5.0 180 .. versionadded:: 5.0
177 The `check_preimported` and `context` parameters. 181 The `check_preimported` and `context` parameters.
178 182
183 .. versionadded:: 5.3
184 The `source_pkgs` parameter.
185
179 """ 186 """
180 # data_file=None means no disk file at all. data_file missing means 187 # data_file=None means no disk file at all. data_file missing means
181 # use the value from the config file. 188 # use the value from the config file.
182 self._no_disk = data_file is None 189 self._no_disk = data_file is None
183 if data_file is _DEFAULT_DATAFILE: 190 if data_file is _DEFAULT_DATAFILE:
186 # Build our configuration from a number of sources. 193 # Build our configuration from a number of sources.
187 self.config = read_coverage_config( 194 self.config = read_coverage_config(
188 config_file=config_file, 195 config_file=config_file,
189 data_file=data_file, cover_pylib=cover_pylib, timid=timid, 196 data_file=data_file, cover_pylib=cover_pylib, timid=timid,
190 branch=branch, parallel=bool_or_none(data_suffix), 197 branch=branch, parallel=bool_or_none(data_suffix),
191 source=source, run_omit=omit, run_include=include, debug=debug, 198 source=source, source_pkgs=source_pkgs, run_omit=omit, run_include=include, debug=debug,
192 report_omit=omit, report_include=include, 199 report_omit=omit, report_include=include,
193 concurrency=concurrency, context=context, 200 concurrency=concurrency, context=context,
194 ) 201 )
195 202
196 # This is injectable by tests. 203 # This is injectable by tests.
210 217
211 # Other instance attributes, set later. 218 # Other instance attributes, set later.
212 self._data = self._collector = None 219 self._data = self._collector = None
213 self._plugins = None 220 self._plugins = None
214 self._inorout = None 221 self._inorout = None
215 self._inorout_class = InOrOut
216 self._data_suffix = self._run_suffix = None 222 self._data_suffix = self._run_suffix = None
217 self._exclude_re = None 223 self._exclude_re = None
218 self._debug = None 224 self._debug = None
219 self._file_mapper = None 225 self._file_mapper = None
220 226
365 371
366 `option_name` is a colon-separated string indicating the section and 372 `option_name` is a colon-separated string indicating the section and
367 option name. For example, the ``branch`` option in the ``[run]`` 373 option name. For example, the ``branch`` option in the ``[run]``
368 section of the config file would be indicated with `"run:branch"`. 374 section of the config file would be indicated with `"run:branch"`.
369 375
370 Returns the value of the option. 376 Returns the value of the option. The type depends on the option
377 selected.
378
379 As a special case, an `option_name` of ``"paths"`` will return an
380 OrderedDict with the entire ``[paths]`` section value.
371 381
372 .. versionadded:: 4.0 382 .. versionadded:: 4.0
373 383
374 """ 384 """
375 return self.config.get_option(option_name) 385 return self.config.get_option(option_name)
391 401
392 has the same effect as this configuration file:: 402 has the same effect as this configuration file::
393 403
394 [run] 404 [run]
395 branch = True 405 branch = True
406
407 As a special case, an `option_name` of ``"paths"`` will replace the
408 entire ``[paths]`` section. The value should be an OrderedDict.
396 409
397 .. versionadded:: 4.0 410 .. versionadded:: 4.0
398 411
399 """ 412 """
400 self.config.set_option(option_name, value) 413 self.config.set_option(option_name, value)
474 ) 487 )
475 for plugin in self._plugins.file_tracers: 488 for plugin in self._plugins.file_tracers:
476 plugin._coverage_enabled = False 489 plugin._coverage_enabled = False
477 490
478 # Create the file classifying substructure. 491 # Create the file classifying substructure.
479 self._inorout = self._inorout_class(warn=self._warn) 492 self._inorout = InOrOut(
493 warn=self._warn,
494 debug=(self._debug if self._debug.should('trace') else None),
495 )
480 self._inorout.configure(self.config) 496 self._inorout.configure(self.config)
481 self._inorout.plugins = self._plugins 497 self._inorout.plugins = self._plugins
482 self._inorout.disp_class = self._collector.file_disposition_class 498 self._inorout.disp_class = self._collector.file_disposition_class
483 499
484 # It's useful to write debug info after initing for start. 500 # It's useful to write debug info after initing for start.
543 self._started = False 559 self._started = False
544 560
545 def _atexit(self): 561 def _atexit(self):
546 """Clean up on process shutdown.""" 562 """Clean up on process shutdown."""
547 if self._debug.should("process"): 563 if self._debug.should("process"):
548 self._debug.write("atexit: {!r}".format(self)) 564 self._debug.write("atexit: pid: {}, instance: {!r}".format(os.getpid(), self))
549 if self._started: 565 if self._started:
550 self.stop() 566 self.stop()
551 if self._auto_save: 567 if self._auto_save:
552 self.save() 568 self.save()
553 569
691 """ 707 """
692 self._init() 708 self._init()
693 self._init_data(suffix=None) 709 self._init_data(suffix=None)
694 self._post_init() 710 self._post_init()
695 711
712 for plugin in self._plugins:
713 if not plugin._coverage_enabled:
714 self._collector.plugin_was_disabled(plugin)
715
696 if self._collector and self._collector.flush_data(): 716 if self._collector and self._collector.flush_data():
697 self._post_save_work() 717 self._post_save_work()
698 718
699 return self._data 719 return self._data
700 720
820 return file_reporters 840 return file_reporters
821 841
822 def report( 842 def report(
823 self, morfs=None, show_missing=None, ignore_errors=None, 843 self, morfs=None, show_missing=None, ignore_errors=None,
824 file=None, omit=None, include=None, skip_covered=None, 844 file=None, omit=None, include=None, skip_covered=None,
825 contexts=None, skip_empty=None, 845 contexts=None, skip_empty=None, precision=None, sort=None
826 ): 846 ):
827 """Write a textual summary report to `file`. 847 """Write a textual summary report to `file`.
828 848
829 Each module in `morfs` is listed, with counts of statements, executed 849 Each module in `morfs` is listed, with counts of statements, executed
830 statements, missing statements, and a list of lines missed. 850 statements, missing statements, and a list of lines missed.
848 `contexts` is a list of regular expressions. Only data from 868 `contexts` is a list of regular expressions. Only data from
849 :ref:`dynamic contexts <dynamic_contexts>` that match one of those 869 :ref:`dynamic contexts <dynamic_contexts>` that match one of those
850 expressions (using :func:`re.search <python:re.search>`) will be 870 expressions (using :func:`re.search <python:re.search>`) will be
851 included in the report. 871 included in the report.
852 872
873 `precision` is the number of digits to display after the decimal
874 point for percentages.
875
853 All of the arguments default to the settings read from the 876 All of the arguments default to the settings read from the
854 :ref:`configuration file <config>`. 877 :ref:`configuration file <config>`.
855 878
856 Returns a float, the total percentage covered. 879 Returns a float, the total percentage covered.
857 880
858 .. versionadded:: 4.0 881 .. versionadded:: 4.0
859 The `skip_covered` parameter. 882 The `skip_covered` parameter.
860 883
861 .. versionadded:: 5.0 884 .. versionadded:: 5.0
862 The `contexts` and `skip_empty` parameters. 885 The `contexts` and `skip_empty` parameters.
886
887 .. versionadded:: 5.2
888 The `precision` parameter.
863 889
864 """ 890 """
865 with override_config( 891 with override_config(
866 self, 892 self,
867 ignore_errors=ignore_errors, report_omit=omit, report_include=include, 893 ignore_errors=ignore_errors, report_omit=omit, report_include=include,
868 show_missing=show_missing, skip_covered=skip_covered, 894 show_missing=show_missing, skip_covered=skip_covered,
869 report_contexts=contexts, skip_empty=skip_empty, 895 report_contexts=contexts, skip_empty=skip_empty, precision=precision,
896 sort=sort
870 ): 897 ):
871 reporter = SummaryReporter(self) 898 reporter = SummaryReporter(self)
872 return reporter.report(morfs, outfile=file) 899 return reporter.report(morfs, outfile=file)
873 900
874 def annotate( 901 def annotate(
890 report_include=include, report_contexts=contexts, 917 report_include=include, report_contexts=contexts,
891 ): 918 ):
892 reporter = AnnotateReporter(self) 919 reporter = AnnotateReporter(self)
893 reporter.report(morfs, directory=directory) 920 reporter.report(morfs, directory=directory)
894 921
895 def html_report(self, morfs=None, directory=None, ignore_errors=None, 922 def html_report(
896 omit=None, include=None, extra_css=None, title=None, 923 self, morfs=None, directory=None, ignore_errors=None,
897 skip_covered=None, show_contexts=None, contexts=None, 924 omit=None, include=None, extra_css=None, title=None,
898 skip_empty=None): 925 skip_covered=None, show_contexts=None, contexts=None,
926 skip_empty=None, precision=None,
927 ):
899 """Generate an HTML report. 928 """Generate an HTML report.
900 929
901 The HTML is written to `directory`. The file "index.html" is the 930 The HTML is written to `directory`. The file "index.html" is the
902 overview starting point, with links to more detailed pages for 931 overview starting point, with links to more detailed pages for
903 individual modules. 932 individual modules.
921 """ 950 """
922 with override_config(self, 951 with override_config(self,
923 ignore_errors=ignore_errors, report_omit=omit, report_include=include, 952 ignore_errors=ignore_errors, report_omit=omit, report_include=include,
924 html_dir=directory, extra_css=extra_css, html_title=title, 953 html_dir=directory, extra_css=extra_css, html_title=title,
925 skip_covered=skip_covered, show_contexts=show_contexts, report_contexts=contexts, 954 skip_covered=skip_covered, show_contexts=show_contexts, report_contexts=contexts,
926 skip_empty=skip_empty, 955 skip_empty=skip_empty, precision=precision,
927 ): 956 ):
928 reporter = HtmlReporter(self) 957 reporter = HtmlReporter(self)
929 return reporter.report(morfs) 958 return reporter.report(morfs)
930 959
931 def xml_report( 960 def xml_report(
932 self, morfs=None, outfile=None, ignore_errors=None, 961 self, morfs=None, outfile=None, ignore_errors=None,
933 omit=None, include=None, contexts=None, 962 omit=None, include=None, contexts=None, skip_empty=None,
934 ): 963 ):
935 """Generate an XML report of coverage results. 964 """Generate an XML report of coverage results.
936 965
937 The report is compatible with Cobertura reports. 966 The report is compatible with Cobertura reports.
938 967
944 Returns a float, the total percentage covered. 973 Returns a float, the total percentage covered.
945 974
946 """ 975 """
947 with override_config(self, 976 with override_config(self,
948 ignore_errors=ignore_errors, report_omit=omit, report_include=include, 977 ignore_errors=ignore_errors, report_omit=omit, report_include=include,
949 xml_output=outfile, report_contexts=contexts, 978 xml_output=outfile, report_contexts=contexts, skip_empty=skip_empty,
950 ): 979 ):
951 return render_report(self.config.xml_output, XmlReporter(self), morfs) 980 return render_report(self.config.xml_output, XmlReporter(self), morfs)
952 981
953 def json_report( 982 def json_report(
954 self, morfs=None, outfile=None, ignore_errors=None, 983 self, morfs=None, outfile=None, ignore_errors=None,
1075 # twice in sys.path. This means that the .pth file will be found twice, 1104 # twice in sys.path. This means that the .pth file will be found twice,
1076 # and executed twice, executing this function twice. We set a global 1105 # and executed twice, executing this function twice. We set a global
1077 # flag (an attribute on this function) to indicate that coverage.py has 1106 # flag (an attribute on this function) to indicate that coverage.py has
1078 # already been started, so we can avoid doing it twice. 1107 # already been started, so we can avoid doing it twice.
1079 # 1108 #
1080 # https://bitbucket.org/ned/coveragepy/issue/340/keyerror-subpy has more 1109 # https://github.com/nedbat/coveragepy/issues/340 has more details.
1081 # details.
1082 1110
1083 if hasattr(process_startup, "coverage"): 1111 if hasattr(process_startup, "coverage"):
1084 # We've annotated this function before, so we must have already 1112 # We've annotated this function before, so we must have already
1085 # started coverage.py in this process. Nothing to do. 1113 # started coverage.py in this process. Nothing to do.
1086 return None 1114 return None

eric ide

mercurial