Skip to content

Commit

Permalink
[cdd/tests/{test_sqlalchemy/test_emit_sqlalchemy.py,test_utils_for_te…
Browse files Browse the repository at this point in the history
…sts.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)
  • Loading branch information
SamuelMarks committed Mar 15, 2024
1 parent d9d4dc0 commit 2f06c04
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 44 deletions.
2 changes: 1 addition & 1 deletion cdd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from logging import getLogger as get_logger

__author__ = "Samuel Marks" # type: str
__version__ = "0.0.99rc36" # type: str
__version__ = "0.0.99rc37" # type: str
__description__ = (
"Open API to/fro routes, models, and tests. "
"Convert between docstrings, classes, methods, argparse, pydantic, and SQLalchemy."
Expand Down
85 changes: 50 additions & 35 deletions cdd/shared/pkg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
from sysconfig import _PREFIX as PREFIX
from sysconfig import get_python_version

Str = type(
"_Never",
tuple(),
{
"__init__": lambda s=None, n=None, constant_value=None, string=None, col_offset=None, lineno=None: s
or n
},
)

def is_virtual_environment():
"""
Whether one is in a virtual environment
Expand All @@ -37,41 +46,49 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
"/usr",
"/usr/local",
)
if prefix is None:
if standard_lib:
prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
else:
prefix = plat_specific and EXEC_PREFIX or PREFIX

if os.name == "posix":
if plat_specific or standard_lib:
prefix = (
prefix or plat_specific and (BASE_EXEC_PREFIX or BASE_PREFIX)
if standard_lib
else (EXEC_PREFIX or PREFIX)
)

class DistutilsPlatformError(Exception):
"""DistutilsPlatformError"""

assert os.name in frozenset(("posix", "nt")), DistutilsPlatformError(
"I don't know where Python installs its library "
"on platform '{}'".format(os.name)
)
return (
(
# plat_specific or standard_lib:
# Platform-specific modules (any module from a non-pure-Python
# module distribution) or standard Python library modules.
libdir = sys.platlibdir
else:
# else:
# Pure Python
libdir = "lib"
libpython = os.path.join(prefix, libdir, "python" + get_python_version())
if standard_lib:
return libpython
elif is_default_prefix and not is_virtual_environment():
return os.path.join(prefix, "lib", "python3", "dist-packages")
else:
return os.path.join(libpython, "site-packages")
elif os.name == "nt":
if standard_lib:
return os.path.join(prefix, "Lib")
else:
return os.path.join(prefix, "Lib", "site-packages")
else:

class DistutilsPlatformError(Exception):
"""DistutilsPlatformError"""

raise DistutilsPlatformError(
"I don't know where Python installs its library "
"on platform '%s'" % os.name
lambda libpython: (
libpython
if standard_lib
else (
os.path.join(prefix, "lib", "python3", "dist-packages")
if is_default_prefix and not is_virtual_environment()
else os.path.join(libpython, "site-packages")
)
)
)(
os.path.join(
prefix,
sys.platlibdir if plat_specific or standard_lib else "lib",
"python" + get_python_version(),
)
)
if os.name == "posix"
else (
os.path.join(prefix, "Lib")
if standard_lib
else os.path.join(prefix, "Lib", "site-packages")
)
)

else:
from distutils.sysconfig import get_python_lib
Expand All @@ -92,10 +109,8 @@ def relative_filename(filename, remove_hints=tuple()):
"""
_filename: str = filename.casefold()
lib = get_python_lib(), get_python_lib(prefix="")
for elem in remove_hints + lib:
if _filename.startswith(elem.casefold()):
return filename[len(elem) + 1 :]
return filename
return next(map(lambda elem: filename[len(elem) + 1 :],
filter(lambda elem: _filename.startswith(elem.casefold()), remove_hints + lib)), filename)


__all__ = ["relative_filename"] # type: list[str]
4 changes: 0 additions & 4 deletions cdd/tests/test_sqlalchemy/test_emit_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ def test_to_sqlalchemy_table_with_inferred_pk(self) -> None:
gold=empty_with_inferred_pk_column_assign,
)

@skipIf(
"GITHUB_ACTIONS" in os.environ and system() in frozenset(("Darwin", "Linux")),
"GitHub Actions fails this test on macOS & Linux (unable to replicate locally)",
)
def test_to_sqlalchemy(self) -> None:
"""
Tests that `emit.sqlalchemy` with `intermediate_repr_no_default_sql_doc` produces `config_tbl_ast`
Expand Down
5 changes: 1 addition & 4 deletions cdd/tests/test_utils_for_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ class TestUtilsForTests(TestCase):
Tests whether docstrings are parsed out—and emitted—correctly
"""

@skipIf(
"GITHUB_ACTIONS" in environ and version_info[:2] >= (3, 6),
"GitHub Actions fails this test (unable to replicate locally)",
)
def test_unittest_main(self) -> None:
"""
Tests whether `unittest_main` is called when `__name__ == '__main__'`
"""
self.assertEqual(type(unittest_main).__name__, "function")
self.assertIsNone(unittest_main())
argparse_mock = MagicMock()
# cdd.tests.utils_for_tests.py
with patch("cdd.tests.utils_for_tests.__name__", "__main__"), patch(
"sys.stderr", new_callable=StringIO
), self.assertRaises(SystemExit) as e:
Expand Down

0 comments on commit 2f06c04

Please sign in to comment.