Skip to content

Commit 65fc98e

Browse files
vstinnerpablogsal
andauthored
bpo-26901: Fix the Argument Clinic test suite (GH-8879)
* Fix Tools/clinic/clinic_test.py: add missing FakeClinic.destination_buffers attribute and pass a file argument to Clinic(). * Rename Tools/clinic/clinic_test.py to Lib/test/test_clinic.py: add temporary Tools/clinic/ to sys.path to import the clinic module. Co-Authored-By: Pablo Galindo <[email protected]>
1 parent 73b00be commit 65fc98e

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

Tools/clinic/clinic_test.py renamed to Lib/test/test_clinic.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
# Argument Clinic
22
# Copyright 2012-2013 by Larry Hastings.
33
# Licensed to the PSF under a contributor agreement.
4-
#
54

6-
import clinic
7-
from clinic import DSLParser
5+
from test import support
6+
from unittest import TestCase
87
import collections
98
import inspect
10-
from test import support
9+
import os.path
1110
import sys
1211
import unittest
13-
from unittest import TestCase
12+
13+
14+
clinic_path = os.path.join(os.path.dirname(__file__), '..', '..', 'Tools', 'clinic')
15+
clinic_path = os.path.normpath(clinic_path)
16+
if not os.path.exists(clinic_path):
17+
raise unittest.SkipTest(f'{clinic_path!r} path does not exist')
18+
sys.path.append(clinic_path)
19+
try:
20+
import clinic
21+
from clinic import DSLParser
22+
finally:
23+
del sys.path[-1]
1424

1525

1626
class FakeConverter:
@@ -35,14 +45,15 @@ def get(self, name, default):
3545
return self.used_converters.setdefault(name, FakeConverterFactory(name))
3646

3747
clinic.Clinic.presets_text = ''
38-
c = clinic.Clinic(language='C')
48+
c = clinic.Clinic(language='C', filename = "file")
3949

4050
class FakeClinic:
4151
def __init__(self):
4252
self.converters = FakeConvertersDict()
4353
self.legacy_converters = FakeConvertersDict()
4454
self.language = clinic.CLanguage(None)
4555
self.filename = None
56+
self.destination_buffers = {}
4657
self.block_parser = clinic.BlockParser('', self.language)
4758
self.modules = collections.OrderedDict()
4859
self.classes = collections.OrderedDict()
@@ -93,7 +104,7 @@ def test_eol(self):
93104
# so it would spit out an end line for you.
94105
# and since you really already had one,
95106
# the last line of the block got corrupted.
96-
c = clinic.Clinic(clinic.CLanguage(None))
107+
c = clinic.Clinic(clinic.CLanguage(None), filename="file")
97108
raw = "/*[clinic]\nfoo\n[clinic]*/"
98109
cooked = c.parse(raw).splitlines()
99110
end_line = cooked[2].rstrip()
@@ -252,7 +263,7 @@ def test_round_trip_2(self):
252263

253264
def _test_clinic(self, input, output):
254265
language = clinic.CLanguage(None)
255-
c = clinic.Clinic(language)
266+
c = clinic.Clinic(language, filename="file")
256267
c.parsers['inert'] = InertParser(c)
257268
c.parsers['copy'] = CopyParser(c)
258269
computed = c.parse(input)

0 commit comments

Comments
 (0)