Skip to content

Commit 87871b7

Browse files
committed
[cdd/tests/test_shared/test_pkg_utils.py] Work on test_get_python_lib ; [cdd/__init__.py] Bump version ; [cdd/tests/{test_json_schema/test_emit_json_schema.py,test_compound/test_doctrans_utils.py}] Increase test coverage
1 parent 5287111 commit 87871b7

5 files changed

Lines changed: 65 additions & 8 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.99rc37" # type: str
12+
__version__ = "0.0.99rc38" # 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ def relative_filename(filename, remove_hints=tuple()):
102102
:type filename: ```str```
103103
104104
:param remove_hints: Hints as to what can be removed
105-
:type remove_hints: ```tuple[str]```
105+
:type remove_hints: ```tuple[str, ...]```
106106
107107
:return: Relative `os.path` (if derived) else original
108108
:rtype: ```str```
109109
"""
110110
_filename: str = filename.casefold()
111-
lib = get_python_lib(), get_python_lib(prefix="")
111+
lib = get_python_lib(), get_python_lib(prefix="") # type: tuple[str, str]
112112
return next(
113113
map(
114114
lambda elem: filename[len(elem) + 1 :],

cdd/tests/test_compound/test_doctrans_utils.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
""" Tests for doctrans_utils """
22

3-
from ast import Expr, Load, Module, Name, fix_missing_locations, get_docstring
3+
from ast import (
4+
Expr,
5+
FunctionDef,
6+
Load,
7+
Module,
8+
Name,
9+
arguments,
10+
fix_missing_locations,
11+
get_docstring,
12+
)
413
from collections import deque
514
from copy import deepcopy
615
from os import path
716
from os.path import extsep
817
from unittest import TestCase
918
from unittest.mock import MagicMock, patch
1019

20+
import cdd.shared.ast_utils
1121
from cdd.compound.doctrans_utils import (
1222
DocTrans,
1323
clear_annotation,
@@ -284,5 +294,38 @@ def test_doctransify_cst(self) -> None:
284294
self.assertTrue(fake_maybe_replace_doc_str_in_function_or_class.called)
285295
self.assertEqual(fake_maybe_replace_doc_str_in_function_or_class.call_count, 6)
286296

297+
def test_doctransify_cst_early_exit(self) -> None:
298+
"""
299+
Tests that `doctransify_cst` early exits
300+
"""
301+
cst_list = list(deepcopy(cstify_cst))
302+
ast_mod = cdd.shared.ast_utils.annotate_ancestry(
303+
Module(
304+
body=[
305+
FunctionDef(
306+
args=arguments(
307+
args=[],
308+
defaults=[],
309+
kw_defaults=[],
310+
kwarg=None,
311+
kwonlyargs=[],
312+
posonlyargs=[],
313+
vararg=None,
314+
arg=None,
315+
),
316+
body=[],
317+
name="foo",
318+
arguments_args=None,
319+
identifier_name=None,
320+
stmt=None,
321+
lineno=1,
322+
)
323+
],
324+
type_ignores=[],
325+
stmt=None,
326+
)
327+
)
328+
doctransify_cst(cst_list, ast_mod)
329+
287330

288331
unittest_main()

cdd/tests/test_json_schema/test_emit_json_schema.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import cdd.shared.emit.file
2020
import cdd.sqlalchemy.emit
2121
from cdd.compound.gen_utils import get_input_mapping_from_path
22+
from cdd.json_schema.utils.shared_utils import JSON_schema
2223
from cdd.tests.mocks.ir import intermediate_repr_no_default_sql_doc
2324
from cdd.tests.mocks.json_schema import config_schema
2425
from cdd.tests.utils_for_tests import unittest_main
@@ -31,7 +32,7 @@ def test_to_json_schema(self) -> None:
3132
"""
3233
Tests that `emit.json_schema` with `intermediate_repr_no_default_doc` produces `config_schema`
3334
"""
34-
gen_config_schema = cdd.json_schema.emit.json_schema(
35+
gen_config_schema: JSON_schema = cdd.json_schema.emit.json_schema(
3536
deepcopy(intermediate_repr_no_default_sql_doc),
3637
"https://offscale.io/config.schema.json",
3738
emit_original_whitespace=True,
@@ -44,6 +45,14 @@ def test_to_json_schema(self) -> None:
4445
config_schema,
4546
)
4647

48+
def test_to_json_schema_early_exit(self) -> None:
49+
"""
50+
Tests that `emit.json_schema` has an early exit
51+
"""
52+
ir: dict = {"$id": "https://offscale.io/config.schema.json"}
53+
gen_config_schema: dict = cdd.json_schema.emit.json_schema(deepcopy(ir), "")
54+
self.assertDictEqual(ir, gen_config_schema)
55+
4756
def test_to_json_schema_file(self) -> None:
4857
"""
4958
Tests that `emit.json_schema` with `intermediate_repr_no_default_doc` produces `config_schema`

cdd/tests/test_shared/test_pkg_utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
""" Tests for pkg utils """
22

33
from os import path
4+
from platform import platform
45
from site import getsitepackages
56
from unittest import TestCase
67

@@ -24,9 +25,13 @@ def test_get_python_lib(self) -> None:
2425
site_packages = path.dirname(path.dirname(site_packages))
2526
self.assertEqual(
2627
(
27-
site_packages
28-
if site_packages == python_lib
29-
else path.join(site_packages, "python3", "dist-packages")
28+
python_lib # Yes yes, I know
29+
if platform == "win32"
30+
else (
31+
site_packages
32+
if site_packages == python_lib
33+
else path.join(site_packages, "python3", "dist-packages")
34+
)
3035
),
3136
python_lib,
3237
)

0 commit comments

Comments
 (0)