Skip to content

Commit

Permalink
[cdd/tests/{test_sqlalchemy/test_emit_sqlalchemy_utils,mocks/sqlalche…
Browse files Browse the repository at this point in the history
…my}.py] Fix tests for < 3.9
  • Loading branch information
SamuelMarks committed Sep 18, 2023
1 parent b185b7d commit 20e5996
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 51 deletions.
4 changes: 3 additions & 1 deletion cdd/compound/openapi/utils/emit_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ def generate_create_from_attr_staticmethod(params, cls_name, docstring_format):
args=[],
keywords=[
keyword(
arg=None,
value=DictComp(
key=Name(id="attr", ctx=Load()),
value=Call(
Expand Down Expand Up @@ -347,7 +348,8 @@ def generate_create_from_attr_staticmethod(params, cls_name, docstring_format):
is_async=0,
)
],
)
),
identifier=None,
)
],
expr=None,
Expand Down
2 changes: 1 addition & 1 deletion cdd/sqlalchemy/utils/shared_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def update_args_infer_typ_sqlalchemy(_param, args, name, nullable, x_typ_sql):
func=Name(type_name, Load()),
args=list(map(set_value, x_typ_sql.get("type_args", iter(())))),
keywords=[
keyword(arg=arg, value=set_value(val))
keyword(arg=arg, value=set_value(val), identifier=None)
for arg, val in x_typ_sql.get("type_kwargs", dict()).items()
],
expr=None,
Expand Down
20 changes: 16 additions & 4 deletions cdd/tests/mocks/fastapi_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ async def create_config(config: Config):
func=Name(id="JSONResponse", ctx=Load()),
args=[],
keywords=[
keyword(arg="status_code", value=set_value(404)),
keyword(
arg="status_code", value=set_value(404), identifier=None
),
keyword(
arg="content",
value=Dict(
Expand All @@ -93,6 +95,7 @@ async def create_config(config: Config):
)
),
),
identifier=None,
),
],
)
Expand All @@ -105,8 +108,12 @@ async def create_config(config: Config):
func=Name(id="JSONResponse", ctx=Load()),
args=[],
keywords=[
keyword(arg="status_code", value=set_value(201)),
keyword(arg="content", value=Name(id="config", ctx=Load())),
keyword(arg="status_code", value=set_value(201), identifier=None),
keyword(
arg="content",
value=Name(id="config", ctx=Load()),
identifier=None,
),
],
)
),
Expand All @@ -116,7 +123,11 @@ async def create_config(config: Config):
func=Attribute(value=Name(id="app", ctx=Load()), attr="post", ctx=Load()),
args=[set_value("/api/config")],
keywords=[
keyword(arg="response_model", value=Name(id="Config", ctx=Load())),
keyword(
arg="response_model",
value=Name(id="Config", ctx=Load()),
identifier=None,
),
keyword(
arg="responses",
value=Dict(
Expand All @@ -138,6 +149,7 @@ async def create_config(config: Config):
),
],
),
identifier=None,
),
],
)
Expand Down
4 changes: 3 additions & 1 deletion cdd/tests/mocks/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,9 @@ def call_cliff(
Name(id="total_loss", ctx=Load()),
Name(id="num_present", ctx=Load()),
],
keywords=[keyword(arg="name", value=set_value("value"))],
keywords=[
keyword(arg="name", value=set_value("value"), identifier=None)
],
)
),
],
Expand Down
46 changes: 33 additions & 13 deletions cdd/tests/mocks/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,13 @@
args=[set_value("dataset_name"), Name(ctx=Load(), id="String")],
func=Name(ctx=Load(), id="Column"),
keywords=[
keyword(arg="comment", value=set_value("name of dataset")),
keyword(arg="default", value=set_value("mnist")),
keyword(arg="primary_key", value=set_value(True)),
keyword(
arg="comment",
value=set_value("name of dataset"),
identifier=None,
),
keyword(arg="default", value=set_value("mnist"), identifier=None),
keyword(arg="primary_key", value=set_value(True), identifier=None),
],
),
Call(
Expand All @@ -119,9 +123,14 @@
keyword(
arg="comment",
value=set_value("directory to look for models in"),
identifier=None,
),
keyword(arg="default", value=set_value("~/tensorflow_datasets")),
keyword(arg="nullable", value=set_value(False)),
keyword(
arg="default",
value=set_value("~/tensorflow_datasets"),
identifier=None,
),
keyword(arg="nullable", value=set_value(False), identifier=None),
],
),
Call(
Expand All @@ -130,27 +139,32 @@
Call(
args=[set_value("np"), set_value("tf")],
func=Name(ctx=Load(), id="Enum"),
keywords=[keyword(arg="name", value=set_value("K"))],
keywords=[
keyword(arg="name", value=set_value("K"), identifier=None)
],
),
],
func=Name(ctx=Load(), id="Column"),
keywords=[
keyword(
arg="comment",
value=set_value("backend engine, e.g., `np` or `tf`"),
identifier=None,
),
keyword(arg="default", value=set_value("np")),
keyword(arg="nullable", value=set_value(False)),
keyword(arg="default", value=set_value("np"), identifier=None),
keyword(arg="nullable", value=set_value(False), identifier=None),
],
),
Call(
args=[set_value("as_numpy"), Name(ctx=Load(), id="Boolean")],
func=Name(ctx=Load(), id="Column"),
keywords=[
keyword(
arg="comment", value=set_value("Convert to numpy ndarrays")
arg="comment",
value=set_value("Convert to numpy ndarrays"),
identifier=None,
),
keyword(arg="nullable", value=set_value(True)),
keyword(arg="nullable", value=set_value(True), identifier=None),
],
),
Call(
Expand All @@ -162,6 +176,7 @@
value=set_value(
"pass this as arguments to data_loader function"
),
identifier=None,
),
keyword(arg="nullable", value=set_value(True)),
],
Expand All @@ -172,6 +187,7 @@
keyword(
arg="comment",
value=set_value(docstring_header_and_return_two_nl_str),
identifier=None,
)
],
),
Expand Down Expand Up @@ -372,7 +388,6 @@ def __repr__(self):
name="__repr__",
args=arguments(
posonlyargs=[],
arg=None,
args=[set_arg("self")],
kwonlyargs=[],
kw_defaults=[],
Expand Down Expand Up @@ -624,6 +639,8 @@ def __repr__(self):
kwonlyargs=[],
kw_defaults=[],
defaults=[],
vararg=None,
kwarg=None,
),
body=[
Expr(
Expand All @@ -633,7 +650,8 @@ def __repr__(self):
partial(indent, prefix=tab * 2),
(
"",
"Construct an instance from an object with identical columns (as attributes) as this `class`/`Table`",
"Construct an instance from an object with identical columns (as attributes)"
" as this `class`/`Table`",
tab * 2,
":return: A new instance made from the input object's attributes",
":rtype: ```foo```",
Expand All @@ -649,6 +667,7 @@ def __repr__(self):
args=[],
keywords=[
keyword(
arg=None,
value=DictComp(
key=Name(id="attr", ctx=Load()),
value=Call(
Expand Down Expand Up @@ -693,13 +712,14 @@ def __repr__(self):
is_async=0,
)
],
)
),
)
],
)
),
],
lineno=None,
returns=None,
decorator_list=[Name(id="staticmethod", ctx=Load())],
)

Expand Down
35 changes: 5 additions & 30 deletions cdd/tests/test_compound/test_sync_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,7 @@ def test_sync_properties_output_param_wrap_no_annotation(self) -> None:
"""Tests `sync_properties` with `output_param_wrap` set when type annotation isn't being replaced"""

with TemporaryDirectory() as tempdir:
(
input_filename,
input_str,
output_filename,
output_str,
) = populate_files(
(input_filename, input_str, output_filename, output_str,) = populate_files(
tempdir,
input_str=(
"from {package} import Literal\n\n"
Expand Down Expand Up @@ -198,12 +193,7 @@ def test_sync_properties_output_param_wrap_no_type(self) -> None:
"""Tests `sync_properties` with `output_param_wrap` set when replacement_node has no type"""

with TemporaryDirectory() as tempdir:
(
input_filename,
input_str,
output_filename,
output_str,
) = populate_files(
(input_filename, input_str, output_filename, output_str,) = populate_files(
tempdir,
output_str=(
"from {package} import Literal\n\n"
Expand Down Expand Up @@ -241,12 +231,7 @@ def test_sync_properties_output_param_wrap_subscript(self) -> None:
"""Tests `sync_properties` with `output_param_wrap` set when replacement_node is subscript and !input_eval"""

with TemporaryDirectory() as tempdir:
(
input_filename,
input_str,
output_filename,
output_str,
) = populate_files(
(input_filename, input_str, output_filename, output_str,) = populate_files(
tempdir,
input_str="a = tuple(range(5))",
output_str="def j(k):\n" "{tab}pass\n".format(tab=tab),
Expand Down Expand Up @@ -274,12 +259,7 @@ def test_sync_properties_output_param_wrap_subscript_eval0(self) -> None:
"""Tests `sync_properties` with `output_param_wrap` set when replacement_node is subscript"""

with TemporaryDirectory() as tempdir:
(
input_filename,
input_str,
output_filename,
output_str,
) = populate_files(
(input_filename, input_str, output_filename, output_str,) = populate_files(
tempdir, input_str="a = tuple(range(5))", output_str="def j(k): pass"
)

Expand Down Expand Up @@ -307,12 +287,7 @@ def test_sync_properties_output_param_wrap_subscript_eval1(self) -> None:
"""Tests `sync_properties` with `output_param_wrap` set when replacement_node is subscript"""

with TemporaryDirectory() as tempdir:
(
input_filename,
input_str,
output_filename,
output_str,
) = populate_files(
(input_filename, input_str, output_filename, output_str,) = populate_files(
tempdir,
input_str="import pip\n"
"c = { attr: getattr(pip, attr)"
Expand Down
2 changes: 1 addition & 1 deletion cdd/tests/test_sqlalchemy/test_emit_sqlalchemy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_param_to_sqlalchemy_column_call_when_sql_constraints(self) -> None:
gold=Call(
func=Name(id="Column", ctx=Load()),
args=[Name(id="String", ctx=Load())],
keywords=[keyword(arg="index", value=set_value(True))],
keywords=[keyword(arg="index", value=set_value(True), identifier=None)],
),
)

Expand Down

0 comments on commit 20e5996

Please sign in to comment.