mirror of
https://github.com/python/cpython.git
synced 2025-10-07 15:42:02 +00:00
bpo-31908: Fix output of cover files for trace module command-line tool. (GH-4205)
Previously emitted cover files only when --missing option was used.
(cherry picked from commit 47ab15470d
)
Co-authored-by: Michael Selik <mike@selik.org>
This commit is contained in:
parent
8075868f19
commit
e4eeb6eff1
3 changed files with 60 additions and 23 deletions
|
@ -2,6 +2,7 @@ import os
|
|||
import sys
|
||||
from test.support import TESTFN, rmtree, unlink, captured_stdout
|
||||
from test.support.script_helper import assert_python_ok, assert_python_failure
|
||||
import textwrap
|
||||
import unittest
|
||||
|
||||
import trace
|
||||
|
@ -365,6 +366,46 @@ class Test_Ignore(unittest.TestCase):
|
|||
# Matched before.
|
||||
self.assertTrue(ignore.names(jn('bar', 'baz.py'), 'baz'))
|
||||
|
||||
# Created for Issue 31908 -- CLI utility not writing cover files
|
||||
class TestCoverageCommandLineOutput(unittest.TestCase):
|
||||
|
||||
codefile = 'tmp.py'
|
||||
coverfile = 'tmp.cover'
|
||||
|
||||
def setUp(self):
|
||||
with open(self.codefile, 'w') as f:
|
||||
f.write(textwrap.dedent('''\
|
||||
x = 42
|
||||
if []:
|
||||
print('unreachable')
|
||||
'''))
|
||||
|
||||
def tearDown(self):
|
||||
unlink(self.codefile)
|
||||
unlink(self.coverfile)
|
||||
|
||||
def test_cover_files_written_no_highlight(self):
|
||||
argv = '-m trace --count'.split() + [self.codefile]
|
||||
status, stdout, stderr = assert_python_ok(*argv)
|
||||
self.assertTrue(os.path.exists(self.coverfile))
|
||||
with open(self.coverfile) as f:
|
||||
self.assertEqual(f.read(),
|
||||
" 1: x = 42\n"
|
||||
" 1: if []:\n"
|
||||
" print('unreachable')\n"
|
||||
)
|
||||
|
||||
def test_cover_files_written_with_highlight(self):
|
||||
argv = '-m trace --count --missing'.split() + [self.codefile]
|
||||
status, stdout, stderr = assert_python_ok(*argv)
|
||||
self.assertTrue(os.path.exists(self.coverfile))
|
||||
with open(self.coverfile) as f:
|
||||
self.assertEqual(f.read(), textwrap.dedent('''\
|
||||
1: x = 42
|
||||
1: if []:
|
||||
>>>>>> print('unreachable')
|
||||
'''))
|
||||
|
||||
class TestCommandLine(unittest.TestCase):
|
||||
|
||||
def test_failures(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue