@@ -167,7 +167,8 @@ class CoverageData(SimpleReprMixin):
167
167
To record data for contexts, use :meth:`set_context` to set a context to
168
168
be used for subsequent :meth:`add_lines` and :meth:`add_arcs` calls.
169
169
170
- To add a source file without any measured data, use :meth:`touch_file`.
170
+ To add a source file without any measured data, use :meth:`touch_file`,
171
+ or :meth:`touch_files` for a list of such files.
171
172
172
173
Write the data to its file with :meth:`write`.
173
174
@@ -536,16 +537,26 @@ def touch_file(self, filename, plugin_name=""):
536
537
`plugin_name` is the name of the plugin responsible for this file. It is used
537
538
to associate the right filereporter, etc.
538
539
"""
540
+ self .touch_files ([filename ], plugin_name )
541
+
542
+ def touch_files (self , filenames , plugin_name = "" ):
543
+ """Ensure that `filenames` appear in the data, empty if needed.
544
+
545
+ `plugin_name` is the name of the plugin responsible for these files. It is used
546
+ to associate the right filereporter, etc.
547
+ """
539
548
if self ._debug .should ('dataop' ):
540
- self ._debug .write ("Touching %r" % (filename ,))
549
+ self ._debug .write ("Touching %r" % (filenames ,))
541
550
self ._start_using ()
542
- if not self ._has_arcs and not self ._has_lines :
543
- raise CoverageException ("Can't touch files in an empty CoverageData" )
544
-
545
- self ._file_id (filename , add = True )
546
- if plugin_name :
547
- # Set the tracer for this file
548
- self .add_file_tracers ({filename : plugin_name })
551
+ with self ._connect (): # Use this to get one transaction.
552
+ if not self ._has_arcs and not self ._has_lines :
553
+ raise CoverageException ("Can't touch files in an empty CoverageData" )
554
+
555
+ for filename in filenames :
556
+ self ._file_id (filename , add = True )
557
+ if plugin_name :
558
+ # Set the tracer for this file
559
+ self .add_file_tracers ({filename : plugin_name })
549
560
550
561
def update (self , other_data , aliases = None ):
551
562
"""Update this data with data from several other :class:`CoverageData` instances.
0 commit comments