8000 bpo-36876: Add a tool that identifies unsupported global C variables.… · python/cpython@ee536b2 · GitHub
[go: up one dir, main page]

Skip to content
Sign in

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ee536b2

Browse files
bpo-36876: Add a tool that identifies unsupported global C variables. (#15877)
1 parent 9936371 commit ee536b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+9467
-19
lines changed

Lib/test/test_check_c_globals.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import unittest
2+
import test.test_tools
3+
4+
test.test_tools.skip_if_missing('c-analyzer')
5+
with test.test_tools.imports_under_tool('c-analyzer'):
6+
from c_globals.__main__ import main
7+
8+
9+
class ActualChecks(unittest.TestCase):
10+
11+
# XXX Also run the check in "make check".
12+
@unittest.expectedFailure
13+
def test_check_c_globals(self):
14+
try:
15+
main('check', {})
16+
except NotImplementedError:
17+
raise unittest.SkipTest('not supported on this host')
18+
19+
20+
if __name__ == '__main__':
21+
# Test needs to be a package, so we can do relative imports.
22+
unittest.main()

Lib/test/test_clinic.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,18 @@
22
# Copyright 2012-2013 by Larry Hastings.
33
# Licensed to the PSF under a contributor agreement.
44

5-
from test import support
5+
from test import support, test_tools
66
from unittest import TestCase
77
import collections
88
import inspect
99
import os.path
1010
import sys
1111
import unittest
1212

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:
13+
test_tools.skip_if_missing('clinic')
14+
with test_tools.imports_under_tool('clinic'):
2015
import clinic
2116
from clinic import DSLParser
22-
finally:
23-
del sys.path[-1]
2417

2518

2619
class FakeConverter:

Lib/test/test_tools/__init__.py

Lines changed: 22 additions & 9 deletions
< 10000 td data-grid-cell-id="diff-c7fce17decb094b7939b53b5cc8d05b3de01034c90a28ff603fa96bffb510372-17-21-2" data-line-anchor="diff-c7fce17decb094b7939b53b5cc8d05b3de01034c90a28ff603fa96bffb510372R21" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionLine-bgColor, var(--diffBlob-addition-bgColor-line));padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell left-side">+
tool = 'scripts'
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
"""Support functions for testing scripts in the Tools directory."""
2-
import os
3-
import unittest
2+
import contextlib
43
import importlib
4+
import os.path
5+
import unittest
56
from test import support
67

7-
basepath = os.path.dirname( # <src/install dir>
8-
os.path.dirname( # Lib
9-
os.path.dirname( # test
10-
os.path.dirname(__file__)))) # test_tools
8+
basepath = os.path.normpath(
9+
os.path.dirname( # <src/install dir>
10+
os.path.dirname( # Lib
11+
os.path.dirname( # test
12+
os.path.dirname(__file__))))) # test_tools
1113

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

15-
def skip_if_missing():
16-
if not os.path.isdir(scriptsdir):
17-
raise unittest.SkipTest('scripts directory could not be found')
17+
def skip_if_missing(tool=None):
18+
if tool:
19+
tooldir = os.path.join(toolsdir, tool)
20+
else:
21
22+
tooldir = scriptsdir
23+
if not os.path.isdir(tooldir):
24+
raise unittest.SkipTest(f'{tool} directory could not be found')
25+
26+
@contextlib.contextmanager
27+
def imports_under_tool(name, *subdirs):
28+
tooldir = os.path.join(toolsdir, name, *subdirs)
29+
with support.DirsOnSysPath(tooldir) as cm:
30+
yield cm
1831

1932
def import_tool(toolname):
2033
with support.DirsOnSysPath(scriptsdir):
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import contextlib
2+
import os.path
3+
import test.test_tools
4+
from test.support import load_package_tests
5+
6+
7+
@contextlib.contextmanager
8+
def tool_imports_for_tests():
9+
test.test_tools.skip_if_missing('c-analyzer')
10+
with test.test_tools.imports_under_tool('c-analyzer'):
11+
yield
12+
13+
14+
def load_tests(*args):
15+
return load_package_tests(os.path.dirname(__file__), *args)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from . import load_tests
2+
import unittest
3+
4+
5+
unittest.main()

Lib/test/test_tools/test_c_analyzer/test_c_analyzer_common/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)
0