Skip to content

bpo-26901: Fix the Argument Clinic test suite #8879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions Tools/clinic/clinic_test.py → Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
# Argument Clinic
# Copyright 2012-2013 by Larry Hastings.
# Licensed to the PSF under a contributor agreement.
#

import clinic
from clinic import DSLParser
from test import support
from unittest import TestCase
import collections
import inspect
from test import support
import os.path
import sys
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:
Expand All @@ -35,14 +45,15 @@ def get(self, name, default):
return self.used_converters.setdefault(name, FakeConverterFactory(name))

clinic.Clinic.presets_text = ''
c = clinic.Clinic(language='C')
c = clinic.Clinic(language='C', filename = "file")

class FakeClinic:
def __init__(self):
self.converters = FakeConvertersDict()
self.legacy_converters = FakeConvertersDict()
self.language = clinic.CLanguage(None)
self.filename = None
self.destination_buffers = {}
self.block_parser = clinic.BlockParser('', self.language)
self.modules = collections.OrderedDict()
self.classes = collections.OrderedDict()
Expand Down Expand Up @@ -93,7 +104,7 @@ def test_eol(self):
# so it would spit out an end line for you.
# and since you really already had one,
# 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]*/"
cooked = c.parse(raw).splitlines()
end_line = cooked[2].rstrip()
Expand Down Expand Up @@ -252,7 +263,7 @@ def test_round_trip_2(self):

def _test_clinic(self, input, output):
language = clinic.CLanguage(None)
c = clinic.Clinic(language)
c = clinic.Clinic(language, filename="file")
c.parsers['inert'] = InertParser(c)
c.parsers['copy'] = CopyParser(c)
computed = c.parse(input)
Expand Down