From b7851c38c1b62d69909ef34bc3c3f91162967e6a Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 15 Aug 2023 16:23:05 +0200 Subject: [PATCH 1/5] gh-106368: Argument Clinic: Add test for cloned function with custom C base name --- Lib/test/test_clinic.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index a67cd301f6eaa8..30b0464162df36 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -638,6 +638,21 @@ class C "void *" "" err = "'__new__' must be a class method" self.expect_failure(block, err, lineno=7) + def test_cloned_with_custom_c_basename(self): + raw = dedent(""" + /*[clinic input] + foo2 + [clinic start generated code]*/ + /*[clinic input] + foo as foo1 = foo2 + [clinic start generated code]*/ + """) + self.clinic.parse(raw) + funcs = self.clinic.functions + self.assertEqual(len(funcs), 2) + self.assertEqual(funcs[1].name, "foo") + self.assertEqual(funcs[1].c_basename, "foo1") + class ParseFileUnitTest(TestCase): def expect_parsing_failure( From 4c09da8ac02a76e059a6274e99f8f3a4607652ae Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 15 Aug 2023 21:28:50 +0200 Subject: [PATCH 2/5] Don't create spurious clinic directories --- Lib/test/test_clinic.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index 646553f43dc07d..fc104ff1f0825e 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -656,6 +656,9 @@ def test_no_c_basename_cloned(self): def test_cloned_with_custom_c_basename(self): raw = dedent(""" /*[clinic input] + # Suppress output, to make sure we don't create spurious clinic/ + # directories. + output everything suppress foo2 [clinic start generated code]*/ /*[clinic input] From 323041cd9852d3ebba4847d59c700601236c34ec Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 15 Aug 2023 21:40:50 +0200 Subject: [PATCH 3/5] Add test_cloned_with_illegal_c_basename --- Lib/test/test_clinic.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index fc104ff1f0825e..e93d7056748d8c 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -671,6 +671,20 @@ def test_cloned_with_custom_c_basename(self): self.assertEqual(funcs[1].name, "foo") self.assertEqual(funcs[1].c_basename, "foo1") + def test_cloned_with_illegal_c_basename(self): + block = """ + /*[clinic input] + class C "void *" "" + foo1 + [clinic start generated code]*/ + + /*[clinic input] + foo2 as .illegal. = foo1 + [clinic start generated code]*/ + """ + err = "Illegal C basename: '.illegal. = foo1'" + self.expect_failure(block, err, lineno=7) + class ParseFileUnitTest(TestCase): def expect_parsing_failure( From dc779dc2af3d9dbf7c2dd05063df7090f2d34402 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 15 Aug 2023 21:43:31 +0200 Subject: [PATCH 4/5] Style --- Lib/test/test_clinic.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index e93d7056748d8c..5f85f1d42ed395 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -661,6 +661,7 @@ def test_cloned_with_custom_c_basename(self): output everything suppress foo2 [clinic start generated code]*/ + /*[clinic input] foo as foo1 = foo2 [clinic start generated code]*/ From 734fb4a64b3a511d2e6d342b8f224f3a91b5c3f3 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 15 Aug 2023 21:44:07 +0200 Subject: [PATCH 5/5] Comment --- Lib/test/test_clinic.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index 5f85f1d42ed395..76729c8c3e4f79 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -656,8 +656,7 @@ def test_no_c_basename_cloned(self): def test_cloned_with_custom_c_basename(self): raw = dedent(""" /*[clinic input] - # Suppress output, to make sure we don't create spurious clinic/ - # directories. + # Make sure we don't create spurious clinic/ directories. output everything suppress foo2 [clinic start generated code]*/