Skip to content

Commit

Permalink
[cdd/tests/test_shared/test_pkg_utils.py] Work on `test_get_python_li…
Browse files Browse the repository at this point in the history
…b` ; [cdd/__init__.py] Bump version ; [cdd/tests/{test_json_schema/test_emit_json_schema.py,test_compound/test_doctrans_utils.py}] Increase test coverage
  • Loading branch information
SamuelMarks committed Mar 15, 2024
1 parent 0e6f7e0 commit 799d9a2
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 8 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.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."
Expand Down
4 changes: 2 additions & 2 deletions cdd/shared/pkg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 :],
Expand Down
45 changes: 44 additions & 1 deletion cdd/tests/test_compound/test_doctrans_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
""" 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
from os.path import extsep
from unittest import TestCase
from unittest.mock import MagicMock, patch

import cdd.shared.ast_utils
from cdd.compound.doctrans_utils import (
DocTrans,
clear_annotation,
Expand Down Expand Up @@ -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()
11 changes: 10 additions & 1 deletion cdd/tests/test_json_schema/test_emit_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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`
Expand Down
11 changes: 8 additions & 3 deletions cdd/tests/test_shared/test_pkg_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" Tests for pkg utils """

from os import path
from platform import platform
from site import getsitepackages
from unittest import TestCase

Expand All @@ -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,
)
Expand Down

0 comments on commit 799d9a2

Please sign in to comment.