Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.12] gh-106368: Increase Argument Clinic CLI test coverage (GH-107277)#107282

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-106368: Increase Argument Clinic CLI test coverage (GH-107277)
(cherry picked from commit579100f)Co-authored-by: Erlend E. Aasland <erlend@python.org>
  • Loading branch information
@erlend-aasland@miss-islington
erlend-aasland authored andmiss-islington committedJul 26, 2023
commitff88620de433d05ee34ddf0131eb7a0135a5b1d0
78 changes: 75 additions & 3 deletionsLib/test/test_clinic.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1348,18 +1348,18 @@ def test_scaffolding(self):

class ClinicExternalTest(TestCase):
maxDiff = None
clinic_py = os.path.join(test_tools.toolsdir, "clinic", "clinic.py")

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],
[sys.executable, "-Xutf8",self.clinic_py, *args],
encoding="utf-8",
bufsize=0,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
) as proc:
proc.wait()
if expect_success== bool(proc.returncode):
if expect_successandproc.returncode:
self.fail("".join(proc.stderr))
stdout = proc.stdout.read()
stderr = proc.stderr.read()
Expand DownExpand Up@@ -1449,6 +1449,49 @@ def test_cli_force(self):
generated = f.read()
self.assertTrue(generated.endswith(checksum))

def test_cli_make(self):
c_code = dedent("""
/*[clinic input]
[clinic start generated code]*/
""")
py_code = "pass"
c_files = "file1.c", "file2.c"
py_files = "file1.py", "file2.py"

def create_files(files, srcdir, code):
for fn in files:
path = os.path.join(srcdir, fn)
with open(path, "w", encoding="utf-8") as f:
f.write(code)

with os_helper.temp_dir() as tmp_dir:
# add some folders, some C files and a Python file
create_files(c_files, tmp_dir, c_code)
create_files(py_files, tmp_dir, py_code)

# create C files in externals/ dir
ext_path = os.path.join(tmp_dir, "externals")
with os_helper.temp_dir(path=ext_path) as externals:
create_files(c_files, externals, c_code)

# run clinic in verbose mode with --make on tmpdir
out = self.expect_success("-v", "--make", "--srcdir", tmp_dir)

# expect verbose mode to only mention the C files in tmp_dir
for filename in c_files:
with self.subTest(filename=filename):
path = os.path.join(tmp_dir, filename)
self.assertIn(path, out)
for filename in py_files:
with self.subTest(filename=filename):
path = os.path.join(tmp_dir, filename)
self.assertNotIn(path, out)
# don't expect C files from the externals dir
for filename in c_files:
with self.subTest(filename=filename):
path = os.path.join(ext_path, filename)
self.assertNotIn(path, out)

def test_cli_verbose(self):
with os_helper.temp_dir() as tmp_dir:
fn = os.path.join(tmp_dir, "test.c")
Expand DownExpand Up@@ -1534,6 +1577,35 @@ def test_cli_converters(self):
f"expected converter {converter!r}, got {line!r}"
)

def test_cli_fail_converters_and_filename(self):
out = self.expect_failure("--converters", "test.c")
msg = (
"Usage error: can't specify --converters "
"and a filename at the same time"
)
self.assertIn(msg, out)

def test_cli_fail_no_filename(self):
out = self.expect_failure()
self.assertIn("usage: clinic.py", out)

def test_cli_fail_output_and_multiple_files(self):
out = self.expect_failure("-o", "out.c", "input.c", "moreinput.c")
msg = "Usage error: can't use -o with multiple filenames"
self.assertIn(msg, out)

def test_cli_fail_filename_or_output_and_make(self):
for opts in ("-o", "out.c"), ("filename.c",):
with self.subTest(opts=opts):
out = self.expect_failure("--make", *opts)
msg = "Usage error: can't use -o or filenames with --make"
self.assertIn(msg, out)

def test_cli_fail_make_without_srcdir(self):
out = self.expect_failure("--make", "--srcdir", "")
msg = "Usage error: --srcdir must not be empty with --make"
self.assertIn(msg, out)


try:
import _testclinic as ac_tester
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp