summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorAlex Waygood <Alex.Waygood@Gmail.com>2023-08-28 18:25:16 (GMT)
committerGitHub <noreply@github.com>2023-08-28 18:25:16 (GMT)
commit242bef459bfbd0ec5e45e6d47df2709093cfefa7 (patch)
treecc333c1c6277caa2b2b45df4113424d5b8450183 /Lib/test
parent47d7eba889bc03884744f978f5f8612380363332 (diff)
downloadcpython-242bef459bfbd0ec5e45e6d47df2709093cfefa7.zip
cpython-242bef459bfbd0ec5e45e6d47df2709093cfefa7.tar.gz
cpython-242bef459bfbd0ec5e45e6d47df2709093cfefa7.tar.bz2
gh-108494: Argument clinic: Improve the `parse_file()` API (#108575)
Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_clinic.py26
1 files changed, 6 insertions, 20 deletions
diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py
index fcccf98..0592c2e 100644
--- a/Lib/test/test_clinic.py
+++ b/Lib/test/test_clinic.py
@@ -13,7 +13,6 @@ import inspect
import os.path
import re
import sys
-import types
import unittest
test_tools.skip_if_missing('clinic')
@@ -22,16 +21,9 @@ with test_tools.imports_under_tool('clinic'):
from clinic import DSLParser
-def default_namespace():
- ns = types.SimpleNamespace()
- ns.force = False
- ns.limited_capi = clinic.DEFAULT_LIMITED_CAPI
- return ns
-
-
def _make_clinic(*, filename='clinic_tests'):
clang = clinic.CLanguage(None)
- c = clinic.Clinic(clang, filename=filename)
+ c = clinic.Clinic(clang, filename=filename, limited_capi=False)
c.block_parser = clinic.BlockParser('', clang)
return c
@@ -60,11 +52,6 @@ def _expect_failure(tc, parser, code, errmsg, *, filename=None, lineno=None,
return cm.exception
-class MockClinic:
- def __init__(self):
- self.limited_capi = clinic.DEFAULT_LIMITED_CAPI
-
-
class ClinicWholeFileTest(TestCase):
maxDiff = None
@@ -138,7 +125,7 @@ class ClinicWholeFileTest(TestCase):
clang.body_prefix = "//"
clang.start_line = "//[{dsl_name} start]"
clang.stop_line = "//[{dsl_name} stop]"
- cl = clinic.Clinic(clang, filename="test.c")
+ cl = clinic.Clinic(clang, filename="test.c", limited_capi=False)
raw = dedent("""
//[clinic start]
//module test
@@ -704,9 +691,8 @@ class ParseFileUnitTest(TestCase):
self, *, filename, expected_error, verify=True, output=None
):
errmsg = re.escape(dedent(expected_error).strip())
- ns = default_namespace()
with self.assertRaisesRegex(clinic.ClinicError, errmsg):
- clinic.parse_file(filename, ns=ns)
+ clinic.parse_file(filename, limited_capi=False)
def test_parse_file_no_extension(self) -> None:
self.expect_parsing_failure(
@@ -846,9 +832,9 @@ class ClinicBlockParserTest(TestCase):
blocks = list(clinic.BlockParser(input, language))
writer = clinic.BlockPrinter(language)
- mock_clinic = MockClinic()
+ c = _make_clinic()
for block in blocks:
- writer.print_block(block, clinic=mock_clinic)
+ writer.print_block(block, clinic=c)
output = writer.f.getvalue()
assert output == input, "output != input!\n\noutput " + repr(output) + "\n\n input " + repr(input)
@@ -874,7 +860,7 @@ xyz
def _test_clinic(self, input, output):
language = clinic.CLanguage(None)
- c = clinic.Clinic(language, filename="file")
+ c = clinic.Clinic(language, filename="file", limited_capi=False)
c.parsers['inert'] = InertParser(c)
c.parsers['copy'] = CopyParser(c)
computed = c.parse(input)