Unverified Kaydet (Commit) 65fc98e7 authored tarafından Victor Stinner's avatar Victor Stinner Kaydeden (comit) GitHub

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: 's avatarPablo Galindo <pablogsal@gmail.com>
üst 73b00bec
# Argument Clinic # Argument Clinic
# Copyright 2012-2013 by Larry Hastings. # Copyright 2012-2013 by Larry Hastings.
# Licensed to the PSF under a contributor agreement. # Licensed to the PSF under a contributor agreement.
#
import clinic from test import support
from clinic import DSLParser from unittest import TestCase
import collections import collections
import inspect import inspect
from test import support import os.path
import sys import sys
import unittest import unittest
from unittest import TestCase
clinic_path = os.path.join(os.path.dirname(__file__), '..', '..', 'Tools', 'clinic')
clinic_path = os.path.normpath(clinic_path)
if not os.path.exists(clinic_path):
raise unittest.SkipTest(f'{clinic_path!r} path does not exist')
sys.path.append(clinic_path)
try:
import clinic
from clinic import DSLParser
finally:
del sys.path[-1]
class FakeConverter: class FakeConverter:
...@@ -35,7 +45,7 @@ class FakeConvertersDict: ...@@ -35,7 +45,7 @@ class FakeConvertersDict:
return self.used_converters.setdefault(name, FakeConverterFactory(name)) return self.used_converters.setdefault(name, FakeConverterFactory(name))
clinic.Clinic.presets_text = '' clinic.Clinic.presets_text = ''
c = clinic.Clinic(language='C') c = clinic.Clinic(language='C', filename = "file")
class FakeClinic: class FakeClinic:
def __init__(self): def __init__(self):
...@@ -43,6 +53,7 @@ class FakeClinic: ...@@ -43,6 +53,7 @@ class FakeClinic:
self.legacy_converters = FakeConvertersDict() self.legacy_converters = FakeConvertersDict()
self.language = clinic.CLanguage(None) self.language = clinic.CLanguage(None)
self.filename = None self.filename = None
self.destination_buffers = {}
self.block_parser = clinic.BlockParser('', self.language) self.block_parser = clinic.BlockParser('', self.language)
self.modules = collections.OrderedDict() self.modules = collections.OrderedDict()
self.classes = collections.OrderedDict() self.classes = collections.OrderedDict()
...@@ -93,7 +104,7 @@ class ClinicWholeFileTest(TestCase): ...@@ -93,7 +104,7 @@ class ClinicWholeFileTest(TestCase):
# so it would spit out an end line for you. # so it would spit out an end line for you.
# and since you really already had one, # and since you really already had one,
# the last line of the block got corrupted. # the last line of the block got corrupted.
c = clinic.Clinic(clinic.CLanguage(None)) c = clinic.Clinic(clinic.CLanguage(None), filename="file")
raw = "/*[clinic]\nfoo\n[clinic]*/" raw = "/*[clinic]\nfoo\n[clinic]*/"
cooked = c.parse(raw).splitlines() cooked = c.parse(raw).splitlines()
end_line = cooked[2].rstrip() end_line = cooked[2].rstrip()
...@@ -252,7 +263,7 @@ xyz ...@@ -252,7 +263,7 @@ xyz
def _test_clinic(self, input, output): def _test_clinic(self, input, output):
language = clinic.CLanguage(None) language = clinic.CLanguage(None)
c = clinic.Clinic(language) c = clinic.Clinic(language, filename="file")
c.parsers['inert'] = InertParser(c) c.parsers['inert'] = InertParser(c)
c.parsers['copy'] = CopyParser(c) c.parsers['copy'] = CopyParser(c)
computed = c.parse(input) computed = c.parse(input)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment