MCPcopy Index your code
hub / github.com/python/cpython / test_file_dest

Method test_file_dest

Lib/test/test_clinic.py:3232–3286  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3230 self.assertIn(msg, err)
3231
3232 def test_file_dest(self):
3233 block = dedent("""
3234 /*[clinic input]
3235 destination test new file {path}.h
3236 output everything test
3237 func
3238 a: object
3239 /
3240 [clinic start generated code]*/
3241 """)
3242 expected_checksum_line = (
3243 "/*[clinic end generated code: "
3244 "output=da39a3ee5e6b4b0d input=b602ab8e173ac3bd]*/\n"
3245 )
3246 expected_output = dedent("""\
3247 /*[clinic input]
3248 preserve
3249 [clinic start generated code]*/
3250
3251 PyDoc_VAR(func__doc__);
3252
3253 PyDoc_STRVAR(func__doc__,
3254 "func($module, a, /)\\n"
3255 "--\\n"
3256 "\\n");
3257
3258 #define FUNC_METHODDEF \\
3259 {"func", (PyCFunction)func, METH_O, func__doc__},
3260
3261 static PyObject *
3262 func(PyObject *module, PyObject *a)
3263 /*[clinic end generated code: output=3dde2d13002165b9 input=a9049054013a1b77]*/
3264 """)
3265 with os_helper.temp_dir() as tmp_dir:
3266 in_fn = os.path.join(tmp_dir, "test.c")
3267 out_fn = os.path.join(tmp_dir, "test.c.h")
3268 with open(in_fn, "w", encoding="utf-8") as f:
3269 f.write(block)
3270 with open(out_fn, "w", encoding="utf-8") as f:
3271 f.write("") # Write an empty output file!
3272 # Clinic should complain about the empty output file.
3273 _, err = self.expect_failure(in_fn)
3274 expected_err = (f"Modified destination file {out_fn!r}; "
3275 "not overwriting!")
3276 self.assertIn(expected_err, err)
3277 # Run clinic again, this time with the -f option.
3278 _ = self.expect_success("-f", in_fn)
3279 # Read back the generated output.
3280 with open(in_fn, encoding="utf-8") as f:
3281 data = f.read()
3282 expected_block = f"{block}{expected_checksum_line}"
3283 self.assertEqual(data, expected_block)
3284 with open(out_fn, encoding="utf-8") as f:
3285 data = f.read()
3286 self.assertEqual(data, expected_output)
3287
3288try:
3289 import _testclinic as ac_tester

Callers

nothing calls this directly

Calls 10

expect_failureMethod · 0.95
expect_successMethod · 0.95
dedentFunction · 0.90
temp_dirMethod · 0.80
assertInMethod · 0.80
openFunction · 0.50
joinMethod · 0.45
writeMethod · 0.45
readMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected