diff --git a/cdd/__init__.py b/cdd/__init__.py index 7ea3d400..ca495a17 100644 --- a/cdd/__init__.py +++ b/cdd/__init__.py @@ -9,7 +9,7 @@ from logging import getLogger as get_logger __author__ = "Samuel Marks" # type: str -__version__ = "0.0.99rc37" # type: str +__version__ = "0.0.99rc38" # type: str __description__ = ( "Open API to/fro routes, models, and tests. " "Convert between docstrings, classes, methods, argparse, pydantic, and SQLalchemy." diff --git a/cdd/shared/pkg_utils.py b/cdd/shared/pkg_utils.py index 1a2ba24b..bd1c7cf4 100644 --- a/cdd/shared/pkg_utils.py +++ b/cdd/shared/pkg_utils.py @@ -102,13 +102,13 @@ def relative_filename(filename, remove_hints=tuple()): :type filename: ```str``` :param remove_hints: Hints as to what can be removed - :type remove_hints: ```tuple[str]``` + :type remove_hints: ```tuple[str, ...]``` :return: Relative `os.path` (if derived) else original :rtype: ```str``` """ _filename: str = filename.casefold() - lib = get_python_lib(), get_python_lib(prefix="") + lib = get_python_lib(), get_python_lib(prefix="") # type: tuple[str, str] return next( map( lambda elem: filename[len(elem) + 1 :], diff --git a/cdd/tests/test_compound/test_doctrans_utils.py b/cdd/tests/test_compound/test_doctrans_utils.py index 12485027..beab953c 100644 --- a/cdd/tests/test_compound/test_doctrans_utils.py +++ b/cdd/tests/test_compound/test_doctrans_utils.py @@ -1,6 +1,15 @@ """ Tests for doctrans_utils """ -from ast import Expr, Load, Module, Name, fix_missing_locations, get_docstring +from ast import ( + Expr, + FunctionDef, + Load, + Module, + Name, + arguments, + fix_missing_locations, + get_docstring, +) from collections import deque from copy import deepcopy from os import path @@ -8,6 +17,7 @@ from unittest import TestCase from unittest.mock import MagicMock, patch +import cdd.shared.ast_utils from cdd.compound.doctrans_utils import ( DocTrans, clear_annotation, @@ -284,5 +294,38 @@ def test_doctransify_cst(self) -> None: self.assertTrue(fake_maybe_replace_doc_str_in_function_or_class.called) self.assertEqual(fake_maybe_replace_doc_str_in_function_or_class.call_count, 6) + def test_doctransify_cst_early_exit(self) -> None: + """ + Tests that `doctransify_cst` early exits + """ + cst_list = list(deepcopy(cstify_cst)) + ast_mod = cdd.shared.ast_utils.annotate_ancestry( + Module( + body=[ + FunctionDef( + args=arguments( + args=[], + defaults=[], + kw_defaults=[], + kwarg=None, + kwonlyargs=[], + posonlyargs=[], + vararg=None, + arg=None, + ), + body=[], + name="foo", + arguments_args=None, + identifier_name=None, + stmt=None, + lineno=1, + ) + ], + type_ignores=[], + stmt=None, + ) + ) + doctransify_cst(cst_list, ast_mod) + unittest_main() diff --git a/cdd/tests/test_json_schema/test_emit_json_schema.py b/cdd/tests/test_json_schema/test_emit_json_schema.py index 9ddca9ea..8620183b 100644 --- a/cdd/tests/test_json_schema/test_emit_json_schema.py +++ b/cdd/tests/test_json_schema/test_emit_json_schema.py @@ -19,6 +19,7 @@ import cdd.shared.emit.file import cdd.sqlalchemy.emit from cdd.compound.gen_utils import get_input_mapping_from_path +from cdd.json_schema.utils.shared_utils import JSON_schema from cdd.tests.mocks.ir import intermediate_repr_no_default_sql_doc from cdd.tests.mocks.json_schema import config_schema from cdd.tests.utils_for_tests import unittest_main @@ -31,7 +32,7 @@ def test_to_json_schema(self) -> None: """ Tests that `emit.json_schema` with `intermediate_repr_no_default_doc` produces `config_schema` """ - gen_config_schema = cdd.json_schema.emit.json_schema( + gen_config_schema: JSON_schema = cdd.json_schema.emit.json_schema( deepcopy(intermediate_repr_no_default_sql_doc), "https://offscale.io/config.schema.json", emit_original_whitespace=True, @@ -44,6 +45,14 @@ def test_to_json_schema(self) -> None: config_schema, ) + def test_to_json_schema_early_exit(self) -> None: + """ + Tests that `emit.json_schema` has an early exit + """ + ir: dict = {"$id": "https://offscale.io/config.schema.json"} + gen_config_schema: dict = cdd.json_schema.emit.json_schema(deepcopy(ir), "") + self.assertDictEqual(ir, gen_config_schema) + def test_to_json_schema_file(self) -> None: """ Tests that `emit.json_schema` with `intermediate_repr_no_default_doc` produces `config_schema` diff --git a/cdd/tests/test_shared/test_pkg_utils.py b/cdd/tests/test_shared/test_pkg_utils.py index 0098cba3..b983e772 100644 --- a/cdd/tests/test_shared/test_pkg_utils.py +++ b/cdd/tests/test_shared/test_pkg_utils.py @@ -1,6 +1,7 @@ """ Tests for pkg utils """ from os import path +from platform import platform from site import getsitepackages from unittest import TestCase @@ -24,9 +25,13 @@ def test_get_python_lib(self) -> None: site_packages = path.dirname(path.dirname(site_packages)) self.assertEqual( ( - site_packages - if site_packages == python_lib - else path.join(site_packages, "python3", "dist-packages") + python_lib # Yes yes, I know + if platform == "win32" + else ( + site_packages + if site_packages == python_lib + else path.join(site_packages, "python3", "dist-packages") + ) ), python_lib, )