Skip to content

Commit

Permalink
bpo-36876: Add a tool that identifies unsupported global C variables. (
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently authored Sep 11, 2019
1 parent 9936371 commit ee536b2
Show file tree
Hide file tree
Showing 51 changed files with 9,467 additions and 19 deletions.
22 changes: 22 additions & 0 deletions Lib/test/test_check_c_globals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import unittest
import test.test_tools

test.test_tools.skip_if_missing('c-analyzer')
with test.test_tools.imports_under_tool('c-analyzer'):
from c_globals.__main__ import main


class ActualChecks(unittest.TestCase):

# XXX Also run the check in "make check".
@unittest.expectedFailure
def test_check_c_globals(self):
try:
main('check', {})
except NotImplementedError:
raise unittest.SkipTest('not supported on this host')


if __name__ == '__main__':
# Test needs to be a package, so we can do relative imports.
unittest.main()
13 changes: 3 additions & 10 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,18 @@
# Copyright 2012-2013 by Larry Hastings.
# Licensed to the PSF under a contributor agreement.

from test import support
from test import support, test_tools
from unittest import TestCase
import collections
import inspect
import os.path
import sys
import unittest


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:
test_tools.skip_if_missing('clinic')
with test_tools.imports_under_tool('clinic'):
import clinic
from clinic import DSLParser
finally:
del sys.path[-1]


class FakeConverter:
Expand Down
31 changes: 22 additions & 9 deletions Lib/test/test_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
"""Support functions for testing scripts in the Tools directory."""
import os
import unittest
import contextlib
import importlib
import os.path
import unittest
from test import support

basepath = os.path.dirname( # <src/install dir>
os.path.dirname( # Lib
os.path.dirname( # test
os.path.dirname(__file__)))) # test_tools
basepath = os.path.normpath(
os.path.dirname( # <src/install dir>
os.path.dirname( # Lib
os.path.dirname( # test
os.path.dirname(__file__))))) # test_tools

toolsdir = os.path.join(basepath, 'Tools')
scriptsdir = os.path.join(toolsdir, 'scripts')

def skip_if_missing():
if not os.path.isdir(scriptsdir):
raise unittest.SkipTest('scripts directory could not be found')
def skip_if_missing(tool=None):
if tool:
tooldir = os.path.join(toolsdir, tool)
else:
tool = 'scripts'
tooldir = scriptsdir
if not os.path.isdir(tooldir):
raise unittest.SkipTest(f'{tool} directory could not be found')

@contextlib.contextmanager
def imports_under_tool(name, *subdirs):
tooldir = os.path.join(toolsdir, name, *subdirs)
with support.DirsOnSysPath(tooldir) as cm:
yield cm

def import_tool(toolname):
with support.DirsOnSysPath(scriptsdir):
Expand Down
15 changes: 15 additions & 0 deletions Lib/test/test_tools/test_c_analyzer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import contextlib
import os.path
import test.test_tools
from test.support import load_package_tests


@contextlib.contextmanager
def tool_imports_for_tests():
test.test_tools.skip_if_missing('c-analyzer')
with test.test_tools.imports_under_tool('c-analyzer'):
yield


def load_tests(*args):
return load_package_tests(os.path.dirname(__file__), *args)
5 changes: 5 additions & 0 deletions Lib/test/test_tools/test_c_analyzer/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import load_tests
import unittest


unittest.main()
Empty file.
Loading

0 comments on commit ee536b2

Please sign in to comment.