Skip to content

Commit

Permalink
[cdd/tests/test_compound/test_exmod.py] Add tests for `emit_sqlalchem…
Browse files Browse the repository at this point in the history
…y_submodule=True` ; [cdd/sqlalchemy/utils/emit_utils.py] Fix keyword only arg issue with `alias` ; [cdd/tests/test_shared/test_pkg_utils.py] Work on `test_get_python_lib` ; [cdd/__init__.py] Bump version
  • Loading branch information
SamuelMarks committed Mar 15, 2024
1 parent 799d9a2 commit 23cfeac
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 14 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.99rc38" # type: str
__version__ = "0.0.99rc39" # type: str
__description__ = (
"Open API to/fro routes, models, and tests. "
"Convert between docstrings, classes, methods, argparse, pydantic, and SQLalchemy."
Expand Down
4 changes: 2 additions & 2 deletions cdd/sqlalchemy/utils/emit_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,8 @@ def generate_create_tables_mod(module_name):
module=module_name,
names=list(
map(
partial(
alias,
lambda name: alias(
name=name,
asname=None,
identifier=None,
identifier_name=None,
Expand Down
39 changes: 39 additions & 0 deletions cdd/tests/test_compound/test_exmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,45 @@ def test_exmod_output_directory_nonexistent(self) -> None:
dry_run=False,
)

def test_exmod_output__create_sqlalchemy_mod(self) -> None:
"""
Tests `exmod` module whence directory does not exist and that it:
- calls `_create_sqlalchemy_mod`
- that `_create_sqlalchemy_mod` works properly
"""

try:
with TemporaryDirectory(prefix="search_root", suffix="search_path") as root:
existent_module_dir, new_module_dir = self.create_and_install_pkg(root)
exmod(
module=self.module_name,
emit_name="sqlalchemy_table",
blacklist=tuple(),
whitelist=tuple(),
mock_imports=True,
emit_sqlalchemy_submodule=True,
output_directory=new_module_dir,
target_module_name="gold",
extra_modules=None,
no_word_wrap=None,
recursive=False,
dry_run=False,
)
# There are no conditionals in the generation, so just check existence
sqlalchemy_mod_dir = path.join(new_module_dir, "sqlalchemy_mod")
self.assertTrue(path.isdir(sqlalchemy_mod_dir))
for name in ("__init__", "create_tables", "connection"):
self.assertTrue(
path.isfile(
path.join(
sqlalchemy_mod_dir, "{}{}py".format(name, path.extsep)
)
)
)
finally:
# sys.path.remove(existent_module_dir)
self._pip(["uninstall", "-y", self.package_root_name])

@skipIf(
github_actions_and_non_windows_and_gte_3_12,
github_actions_err,
Expand Down
21 changes: 10 additions & 11 deletions cdd/tests/test_shared/test_pkg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@ def test_relative_filename(self) -> None:

def test_get_python_lib(self) -> None:
"""Tests that `get_python_lib` works"""
site_packages = getsitepackages()[0]
python_lib = get_python_lib()
if site_packages != python_lib:
# Yes yes, I know; win32 note:
site_packages = python_lib if platform == "win32" else getsitepackages()[0]
if site_packages == python_lib:
self.assertTrue(site_packages, python_lib)
else:
site_packages = path.dirname(path.dirname(site_packages))
self.assertEqual(
(
python_lib # Yes yes, I know
if platform == "win32"
else (
self.assertEqual(
(
site_packages
if site_packages == python_lib
else path.join(site_packages, "python3", "dist-packages")
)
),
python_lib,
)
),
python_lib,
)


unittest_main()

0 comments on commit 23cfeac

Please sign in to comment.