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

Commit579100f

Browse files
gh-106368: Increase Argument Clinic CLI test coverage (#107277)
1 parent33838fe commit579100f

File tree

1 file changed

+75
-3
lines changed

1 file changed

+75
-3
lines changed

‎Lib/test/test_clinic.py‎

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,18 +1348,18 @@ def test_scaffolding(self):
13481348

13491349
classClinicExternalTest(TestCase):
13501350
maxDiff=None
1351+
clinic_py=os.path.join(test_tools.toolsdir,"clinic","clinic.py")
13511352

13521353
def_do_test(self,*args,expect_success=True):
1353-
clinic_py=os.path.join(test_tools.toolsdir,"clinic","clinic.py")
13541354
withsubprocess.Popen(
1355-
[sys.executable,"-Xutf8",clinic_py,*args],
1355+
[sys.executable,"-Xutf8",self.clinic_py,*args],
13561356
encoding="utf-8",
13571357
bufsize=0,
13581358
stdout=subprocess.PIPE,
13591359
stderr=subprocess.PIPE,
13601360
)asproc:
13611361
proc.wait()
1362-
ifexpect_success==bool(proc.returncode):
1362+
ifexpect_successandproc.returncode:
13631363
self.fail("".join(proc.stderr))
13641364
stdout=proc.stdout.read()
13651365
stderr=proc.stderr.read()
@@ -1449,6 +1449,49 @@ def test_cli_force(self):
14491449
generated=f.read()
14501450
self.assertTrue(generated.endswith(checksum))
14511451

1452+
deftest_cli_make(self):
1453+
c_code=dedent("""
1454+
/*[clinic input]
1455+
[clinic start generated code]*/
1456+
""")
1457+
py_code="pass"
1458+
c_files="file1.c","file2.c"
1459+
py_files="file1.py","file2.py"
1460+
1461+
defcreate_files(files,srcdir,code):
1462+
forfninfiles:
1463+
path=os.path.join(srcdir,fn)
1464+
withopen(path,"w",encoding="utf-8")asf:
1465+
f.write(code)
1466+
1467+
withos_helper.temp_dir()astmp_dir:
1468+
# add some folders, some C files and a Python file
1469+
create_files(c_files,tmp_dir,c_code)
1470+
create_files(py_files,tmp_dir,py_code)
1471+
1472+
# create C files in externals/ dir
1473+
ext_path=os.path.join(tmp_dir,"externals")
1474+
withos_helper.temp_dir(path=ext_path)asexternals:
1475+
create_files(c_files,externals,c_code)
1476+
1477+
# run clinic in verbose mode with --make on tmpdir
1478+
out=self.expect_success("-v","--make","--srcdir",tmp_dir)
1479+
1480+
# expect verbose mode to only mention the C files in tmp_dir
1481+
forfilenameinc_files:
1482+
withself.subTest(filename=filename):
1483+
path=os.path.join(tmp_dir,filename)
1484+
self.assertIn(path,out)
1485+
forfilenameinpy_files:
1486+
withself.subTest(filename=filename):
1487+
path=os.path.join(tmp_dir,filename)
1488+
self.assertNotIn(path,out)
1489+
# don't expect C files from the externals dir
1490+
forfilenameinc_files:
1491+
withself.subTest(filename=filename):
1492+
path=os.path.join(ext_path,filename)
1493+
self.assertNotIn(path,out)
1494+
14521495
deftest_cli_verbose(self):
14531496
withos_helper.temp_dir()astmp_dir:
14541497
fn=os.path.join(tmp_dir,"test.c")
@@ -1534,6 +1577,35 @@ def test_cli_converters(self):
15341577
f"expected converter{converter!r}, got{line!r}"
15351578
)
15361579

1580+
deftest_cli_fail_converters_and_filename(self):
1581+
out=self.expect_failure("--converters","test.c")
1582+
msg= (
1583+
"Usage error: can't specify --converters "
1584+
"and a filename at the same time"
1585+
)
1586+
self.assertIn(msg,out)
1587+
1588+
deftest_cli_fail_no_filename(self):
1589+
out=self.expect_failure()
1590+
self.assertIn("usage: clinic.py",out)
1591+
1592+
deftest_cli_fail_output_and_multiple_files(self):
1593+
out=self.expect_failure("-o","out.c","input.c","moreinput.c")
1594+
msg="Usage error: can't use -o with multiple filenames"
1595+
self.assertIn(msg,out)
1596+
1597+
deftest_cli_fail_filename_or_output_and_make(self):
1598+
foroptsin ("-o","out.c"), ("filename.c",):
1599+
withself.subTest(opts=opts):
1600+
out=self.expect_failure("--make",*opts)
1601+
msg="Usage error: can't use -o or filenames with --make"
1602+
self.assertIn(msg,out)
1603+
1604+
deftest_cli_fail_make_without_srcdir(self):
1605+
out=self.expect_failure("--make","--srcdir","")
1606+
msg="Usage error: --srcdir must not be empty with --make"
1607+
self.assertIn(msg,out)
1608+
15371609

15381610
try:
15391611
import_testclinicasac_tester

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp