Skip to content

Commit

Permalink
100% Test Success (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
skushnir123 committed Feb 15, 2023
1 parent 7f635df commit a345b7d
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
28 changes: 26 additions & 2 deletions cdd/tests/mocks/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,19 @@
"default"
] = NoneStr

intermediate_repr_no_default_sql_with_sql_types = deepcopy(
intermediate_repr_no_default_sql_doc
)
for param, typ in (
("dataset_name", "String"),
("tfds_dir", "String"),
("as_numpy", "Boolean"),
("data_loader_kwargs", "JSON"),
):
intermediate_repr_no_default_sql_with_sql_types["params"][param]["x_typ"] = {
"sql": {"type": typ}
}


intermediate_repr_empty = {
"name": None,
Expand Down Expand Up @@ -1187,8 +1200,18 @@
"name": "node",
"params": OrderedDict(
(
("node_id", {"doc": "[PK]", "typ": "int"}),
("primary_element", {"doc": "[FK(element.element_id)]", "typ": "int"}),
(
"node_id",
{"x_typ": {"sql": {"type": "Integer"}}, "doc": "[PK]", "typ": "int"},
),
(
"primary_element",
{
"x_typ": {"sql": {"type": "Integer"}},
"doc": "[FK(element.element_id)]",
"typ": "int",
},
),
)
),
"returns": None,
Expand All @@ -1215,6 +1238,7 @@
"intermediate_repr_no_default_sql_doc",
"intermediate_repr_no_default_sql_with_nones_doc",
"intermediate_repr_no_default_with_nones_doc",
"intermediate_repr_no_default_sql_with_sql_types",
"intermediate_repr_node_pk",
"intermediate_repr_only_return_type",
"method_complex_args_variety_ir",
Expand Down
13 changes: 12 additions & 1 deletion cdd/tests/mocks/json_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Mocks for JSON Schema
"""
from copy import deepcopy

from cdd.tests.mocks.docstrings import docstring_header_and_return_no_nl_str

Expand Down Expand Up @@ -38,6 +39,16 @@
"required": ["dataset_name", "tfds_dir", "K"],
}

config_schema_with_sql_types = deepcopy(config_schema)
for param, typ in (
("dataset_name", "String"),
("tfds_dir", "String"),
("as_numpy", "Boolean"),
("data_loader_kwargs", "JSON"),
):
config_schema_with_sql_types["properties"][param]["x_typ"] = {"sql": {"type": typ}}


server_error_schema = {
"$id": "https://offscale.io/error_json.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
Expand All @@ -62,4 +73,4 @@
}


__all__ = ["config_schema", "server_error_schema"]
__all__ = ["config_schema", "server_error_schema", "config_schema_with_sql_types"]
15 changes: 13 additions & 2 deletions cdd/tests/mocks/openapi.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""
OpenAPI mocks
"""
from copy import deepcopy

from cdd.tests.mocks.json_schema import config_schema, server_error_schema
from cdd.tests.mocks.json_schema import config_schema, config_schema_with_sql_types, server_error_schema
from cdd.tests.mocks.routes import route_config

openapi_dict = {
Expand Down Expand Up @@ -117,4 +118,14 @@
},
}

__all__ = ["openapi_dict"]
openapi_dict_with_sql_types = deepcopy(openapi_dict)
openapi_dict_with_sql_types["components"]["schemas"] = {
name: {k: v for k, v in schema.items() if not k.startswith("$")}
for name, schema in {
route_config["name"]: config_schema_with_sql_types,
"ServerError": server_error_schema,
}.items()
}


__all__ = ["openapi_dict", "openapi_dict_with_sql_types"]
4 changes: 2 additions & 2 deletions cdd/tests/test_compound/test_openapi_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from unittest import TestCase

from cdd.compound.openapi.gen_openapi import openapi_bulk
from cdd.tests.mocks.openapi import openapi_dict
from cdd.tests.mocks.openapi import openapi_dict_with_sql_types
from cdd.tests.mocks.routes import (
create_route,
destroy_route,
Expand Down Expand Up @@ -55,7 +55,7 @@ def test_openapi_bulk(self) -> None:
model_paths=(models_filename,),
routes_paths=(routes_filename,),
),
openapi_dict,
openapi_dict_with_sql_types,
)

self.assertEqual(
Expand Down
5 changes: 3 additions & 2 deletions cdd/tests/test_sqlalchemy/test_parse_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import cdd.sqlalchemy.parse
from cdd.tests.mocks.ir import (
intermediate_repr_no_default_sql_doc,
intermediate_repr_no_default_sql_with_sql_types,
intermediate_repr_node_pk,
)
from cdd.tests.mocks.sqlalchemy import (
Expand Down Expand Up @@ -58,7 +59,7 @@ def test_from_sqlalchemy_table(self) -> None:
ir = cdd.sqlalchemy.parse.sqlalchemy_table(ast.parse(variant).body[0])
self.assertEqual(ir["name"], "config_tbl")
ir["name"] = None
self.assertDictEqual(ir, intermediate_repr_no_default_sql_doc)
self.assertDictEqual(ir, intermediate_repr_no_default_sql_with_sql_types)

def test_from_sqlalchemy(self) -> None:
"""
Expand All @@ -75,7 +76,7 @@ def test_from_sqlalchemy(self) -> None:
ir = cdd.sqlalchemy.parse.sqlalchemy(deepcopy(config_decl_base_ast))
self.assertEqual(ir["name"], "config_tbl")
ir["name"] = None
self.assertDictEqual(ir, intermediate_repr_no_default_sql_doc)
self.assertDictEqual(ir, intermediate_repr_no_default_sql_with_sql_types)

def test_from_sqlalchemy_with_foreign_rel(self) -> None:
"""Test from SQLalchemy with a foreign key relationship"""
Expand Down
1 change: 1 addition & 0 deletions cdd/tests/test_sqlalchemy/test_parse_sqlalchemy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_column_call_to_param_pk(self) -> None:
"default": config_schema["properties"][_name]["default"],
"typ": "str",
"doc": config_schema["properties"][_name]["description"],
"x_typ": {"sql": {"type": "String"}},
},
)
)("dataset_name")
Expand Down

0 comments on commit a345b7d

Please sign in to comment.