Skip to content

gh-106368: Increase Argument Clinic CLI test coverage #107156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 24, 2023
Next Next commit
gh-106368: Increase Argument Clinic CLI test coverage
Instead of hacking into the Clinic class, use the Argument Clinic tool
to run the ClinicWholeFileTest test suite.
  • Loading branch information
erlend-aasland committed Jul 23, 2023
commit 12c0dc78c36a87249f63b1cc25cd9a177527e373
39 changes: 38 additions & 1 deletion Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

from test import support, test_tools
from test.support import os_helper
from test.support import SHORT_TIMEOUT, requires_subprocess
from test.support.os_helper import TESTFN, unlink
from textwrap import dedent
from unittest import TestCase
import collections
import inspect
import os.path
import subprocess
import sys
import unittest

Expand Down Expand Up @@ -1346,6 +1349,34 @@ def test_scaffolding(self):
class ClinicExternalTest(TestCase):
maxDiff = None

def _do_test(self, *args, expect_success=True):
clinic_py = os.path.join(test_tools.toolsdir, "clinic", "clinic.py")
with subprocess.Popen(
[sys.executable, "-Xutf8", clinic_py, *args],
encoding="utf-8",
bufsize=0,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
) as proc:
proc.wait()
if expect_success == bool(proc.returncode):
self.fail("".join(proc.stderr))
stdout = proc.stdout.read()
stderr = proc.stderr.read()
if expect_success:
self.assertEqual(stderr, "")
else:
self.assertEqual(stdout, "")
return stdout, stderr

def expect_success(self, *args):
out, _ = self._do_test(*args)
return out

def expect_failure(self, *args):
_, err = self._do_test(*args, expect_success=False)
return err

def test_external(self):
CLINIC_TEST = 'clinic.test.c'
# bpo-42398: Test that the destination file is left unchanged if the
Expand All @@ -1361,7 +1392,9 @@ def test_external(self):
f.write(orig_contents)
old_mtime_ns = os.stat(testfile).st_mtime_ns

clinic.parse_file(testfile)
# Run clinic CLI and verify that it does not complain.
out = self.expect_success("-f", testfile)
self.assertEqual(out, "")

with open(testfile, 'r', encoding='utf-8') as f:
new_contents = f.read()
Expand All @@ -1372,6 +1405,10 @@ def test_external(self):
# if the content does not change
self.assertEqual(new_mtime_ns, old_mtime_ns)

def test_cli_help(self):
out = self.expect_success("-h")
self.assertIn("usage: clinic.py", out)


try:
import _testclinic as ac_tester
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy