Skip to content

Commit a30976c

Browse files
committed
[cdd/tests/{test_sqlalchemy/test_emit_sqlalchemy.py,test_utils_for_tests.py}] Enable tests that fail on GITHUB_ACTIONS (for debugging) ; [cdd/__init__.py] Bump version ; [cdd/shared/pkg_utils.py] Use same implementation as setup.py (for coverage purposes)
1 parent 2035c70 commit a30976c

4 files changed

Lines changed: 52 additions & 44 deletions

File tree

cdd/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from logging import getLogger as get_logger
1010

1111
__author__ = "Samuel Marks" # type: str
12-
__version__ = "0.0.99rc36" # type: str
12+
__version__ = "0.0.99rc37" # type: str
1313
__description__ = (
1414
"Open API to/fro routes, models, and tests. "
1515
"Convert between docstrings, classes, methods, argparse, pydantic, and SQLalchemy."

cdd/shared/pkg_utils.py

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
from sysconfig import _PREFIX as PREFIX
1414
from sysconfig import get_python_version
1515

16+
Str = type(
17+
"_Never",
18+
tuple(),
19+
{
20+
"__init__": lambda s=None, n=None, constant_value=None, string=None, col_offset=None, lineno=None: s
21+
or n
22+
},
23+
)
24+
1625
def is_virtual_environment():
1726
"""
1827
Whether one is in a virtual environment
@@ -37,41 +46,49 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
3746
"/usr",
3847
"/usr/local",
3948
)
40-
if prefix is None:
41-
if standard_lib:
42-
prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
43-
else:
44-
prefix = plat_specific and EXEC_PREFIX or PREFIX
45-
46-
if os.name == "posix":
47-
if plat_specific or standard_lib:
49+
prefix = (
50+
prefix or plat_specific and (BASE_EXEC_PREFIX or BASE_PREFIX)
51+
if standard_lib
52+
else (EXEC_PREFIX or PREFIX)
53+
)
54+
55+
class DistutilsPlatformError(Exception):
56+
"""DistutilsPlatformError"""
57+
58+
assert os.name in frozenset(("posix", "nt")), DistutilsPlatformError(
59+
"I don't know where Python installs its library "
60+
"on platform '{}'".format(os.name)
61+
)
62+
return (
63+
(
64+
# plat_specific or standard_lib:
4865
# Platform-specific modules (any module from a non-pure-Python
4966
# module distribution) or standard Python library modules.
50-
libdir = sys.platlibdir
51-
else:
67+
# else:
5268
# Pure Python
53-
libdir = "lib"
54-
libpython = os.path.join(prefix, libdir, "python" + get_python_version())
55-
if standard_lib:
56-
return libpython
57-
elif is_default_prefix and not is_virtual_environment():
58-
return os.path.join(prefix, "lib", "python3", "dist-packages")
59-
else:
60-
return os.path.join(libpython, "site-packages")
61-
elif os.name == "nt":
62-
if standard_lib:
63-
return os.path.join(prefix, "Lib")
64-
else:
65-
return os.path.join(prefix, "Lib", "site-packages")
66-
else:
67-
68-
class DistutilsPlatformError(Exception):
69-
"""DistutilsPlatformError"""
70-
71-
raise DistutilsPlatformError(
72-
"I don't know where Python installs its library "
73-
"on platform '%s'" % os.name
69+
lambda libpython: (
70+
libpython
71+
if standard_lib
72+
else (
73+
os.path.join(prefix, "lib", "python3", "dist-packages")
74+
if is_default_prefix and not is_virtual_environment()
75+
else os.path.join(libpython, "site-packages")
76+
)
77+
)
78+
)(
79+
os.path.join(
80+
prefix,
81+
sys.platlibdir if plat_specific or standard_lib else "lib",
82+
"python" + get_python_version(),
83+
)
84+
)
85+
if os.name == "posix"
86+
else (
87+
os.path.join(prefix, "Lib")
88+
if standard_lib
89+
else os.path.join(prefix, "Lib", "site-packages")
7490
)
91+
)
7592

7693
else:
7794
from distutils.sysconfig import get_python_lib
@@ -92,10 +109,8 @@ def relative_filename(filename, remove_hints=tuple()):
92109
"""
93110
_filename: str = filename.casefold()
94111
lib = get_python_lib(), get_python_lib(prefix="")
95-
for elem in remove_hints + lib:
96-
if _filename.startswith(elem.casefold()):
97-
return filename[len(elem) + 1 :]
98-
return filename
112+
return next(map(lambda elem: filename[len(elem) + 1 :],
113+
filter(lambda elem: _filename.startswith(elem.casefold()), remove_hints + lib)), filename)
99114

100115

101116
__all__ = ["relative_filename"] # type: list[str]

cdd/tests/test_sqlalchemy/test_emit_sqlalchemy.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ def test_to_sqlalchemy_table_with_inferred_pk(self) -> None:
7878
gold=empty_with_inferred_pk_column_assign,
7979
)
8080

81-
@skipIf(
82-
"GITHUB_ACTIONS" in os.environ and system() in frozenset(("Darwin", "Linux")),
83-
"GitHub Actions fails this test on macOS & Linux (unable to replicate locally)",
84-
)
8581
def test_to_sqlalchemy(self) -> None:
8682
"""
8783
Tests that `emit.sqlalchemy` with `intermediate_repr_no_default_sql_doc` produces `config_tbl_ast`

cdd/tests/test_utils_for_tests.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,14 @@ class TestUtilsForTests(TestCase):
2121
Tests whether docstrings are parsed out—and emitted—correctly
2222
"""
2323

24-
@skipIf(
25-
"GITHUB_ACTIONS" in environ and version_info[:2] >= (3, 6),
26-
"GitHub Actions fails this test (unable to replicate locally)",
27-
)
2824
def test_unittest_main(self) -> None:
2925
"""
3026
Tests whether `unittest_main` is called when `__name__ == '__main__'`
3127
"""
3228
self.assertEqual(type(unittest_main).__name__, "function")
3329
self.assertIsNone(unittest_main())
3430
argparse_mock = MagicMock()
31+
# cdd.tests.utils_for_tests.py
3532
with patch("cdd.tests.utils_for_tests.__name__", "__main__"), patch(
3633
"sys.stderr", new_callable=StringIO
3734
), self.assertRaises(SystemExit) as e:

0 commit comments

Comments
 (0)