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
Prev Previous commit
Next Next commit
Test force/no-force runs
  • Loading branch information
erlend-aasland committed Jul 23, 2023
commit 39ee0eb98dcc55cc09a0d42e4ea84fefe00acc59
54 changes: 45 additions & 9 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1363,19 +1363,15 @@ def _do_test(self, *args, expect_success=True):
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
# Clinic never writes to stderr.
self.assertEqual(stderr, "")
return stdout

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

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

def test_external(self):
CLINIC_TEST = 'clinic.test.c'
Expand Down Expand Up @@ -1412,6 +1408,46 @@ def test_no_change(self):
# if the content does not change
self.assertEqual(pre_mtime, post_mtime)

def test_cli_force(self):
invalid_input = dedent("""
/*[clinic input]
output preset block
module test
test.fn
a: int
[clinic start generated code]*/

const char *hand_edited = "output block is overwritten";
/*[clinic end generated code: output=bogus input=bogus]*/
""")
fail_msg = dedent("""
Checksum mismatch!
Expected: bogus
Computed: 2ed19
Suggested fix: remove all generated code including the end marker,
or use the '-f' option.
""")
with os_helper.temp_dir() as tmp_dir:
fn = os.path.join(tmp_dir, "test.c")
with open(fn, "w", encoding="utf-8") as f:
f.write(invalid_input)
# First, run the CLI without -f and expect failure.
# Note, we cannot check the entire fail msg, because the path to
# the tmp file will change for every run.
out = self.expect_failure(fn)
self.assertTrue(out.endswith(fail_msg))
# Then, force regeneration; success expected.
out = self.expect_success("-f", fn)
self.assertEqual(out, "")
# Verify by checking the checksum.
checksum = (
"/*[clinic end generated code: "
"output=2124c291eb067d76 input=9543a8d2da235301]*/\n"
)
with open(fn, 'r', encoding='utf-8') as f:
generated = f.read()
self.assertTrue(generated.endswith(checksum))

def test_cli_help(self):
out = self.expect_success("-h")
self.assertIn("usage: clinic.py", out)
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