Debian Codegraph @

private/update-branch-coverage

raw
1 #!/usr/bin/env python3
2 # encoding=UTF-8
3
4 # Copyright © 2014-2025 Jakub Wilk <[email protected]>
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the “Software”), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 # SOFTWARE.
23
24 import glob
25 import io
26 import os
27 import sys
28
29 import nose
30 import nose.plugins.cover
31
32 [] = [*()] # Python >= 3.5 is required
33
34 class Coverage(nose.plugins.cover.Coverage):
35
36 stream = None
37
38 def report(self, stream):
39 return super().report(self.stream)
40
41 basedir = os.path.join(
42 os.path.dirname(__file__),
43 os.pardir,
44 )
45
46 def main():
47 os.chdir(basedir)
48 module_glob = os.path.join('tests', 'test_*.py')
49 modules = glob.glob(module_glob)
50 argv = [
51 sys.argv[0],
52 '--with-coverage',
53 '--cover-package=lib',
54 '--cover-erase',
55 *modules
56 ]
57 path = os.path.join(
58 'tests',
59 'coverage'
60 )
61 plugin = Coverage()
62 report_stream = plugin.stream = io.StringIO()
63 print('Generated automatically by private/update-branch-coverage. '
64 'Do not edit.\n', file=report_stream)
65 ok = nose.run(argv=argv, plugins=[plugin])
66 if not ok:
67 sys.exit(1)
68 report_stream.seek(0)
69 with open(path + '.tmp', 'wt', encoding='ASCII') as file:
70 for line in report_stream:
71 line = line.rstrip()
72 print(line, file=file)
73 os.rename(path + '.tmp', path)
74
75 if __name__ == '__main__':
76 main()
77
78 # vim:ts=4 sts=4 sw=4 et