diff --git a/tests/codegen/test-project1/edgedb.toml b/tests/codegen/test-project1/edgedb.toml new file mode 100644 index 00000000..e69de29b diff --git a/tests/codegen/test-project1/generated_async_edgeql.py.assert b/tests/codegen/test-project1/generated_async_edgeql.py.assert new file mode 100644 index 00000000..3f10ec50 --- /dev/null +++ b/tests/codegen/test-project1/generated_async_edgeql.py.assert @@ -0,0 +1,16 @@ +# AUTOGENERATED FROM 'select_scalar.edgeql' WITH: +# $ edgedb-py --target async --file + + +from __future__ import annotations +import edgedb + + +async def select_scalar( + client: edgedb.AsyncIOClient, +) -> int: + return await client.query_single( + """\ + select 1;\ + """, + ) diff --git a/tests/codegen/test-project1/select_scalar.edgeql b/tests/codegen/test-project1/select_scalar.edgeql new file mode 100644 index 00000000..ab290eb4 --- /dev/null +++ b/tests/codegen/test-project1/select_scalar.edgeql @@ -0,0 +1 @@ +select 1; diff --git a/tests/codegen/test-project1/select_scalar_async_edgeql.py.assert b/tests/codegen/test-project1/select_scalar_async_edgeql.py.assert new file mode 100644 index 00000000..611ebdd4 --- /dev/null +++ b/tests/codegen/test-project1/select_scalar_async_edgeql.py.assert @@ -0,0 +1,25 @@ +# AUTOGENERATED FROM 'select_scalar.edgeql' WITH: +# $ edgedb-py + + +from __future__ import annotations +import edgedb + + +class NoPydanticValidation: + @classmethod + def __get_validators__(cls): + from pydantic.dataclasses import dataclass as pydantic_dataclass + pydantic_dataclass(cls) + cls.__pydantic_model__.__get_validators__ = lambda: [] + return [] + + +async def select_scalar( + client: edgedb.AsyncIOClient, +) -> int: + return await client.query_single( + """\ + select 1;\ + """, + ) diff --git a/tests/codegen/test-project1/select_scalar_edgeql.py.assert b/tests/codegen/test-project1/select_scalar_edgeql.py.assert new file mode 100644 index 00000000..52de1a44 --- /dev/null +++ b/tests/codegen/test-project1/select_scalar_edgeql.py.assert @@ -0,0 +1,16 @@ +# AUTOGENERATED FROM 'select_scalar.edgeql' WITH: +# $ edgedb-py --target blocking + + +from __future__ import annotations +import edgedb + + +def select_scalar( + client: edgedb.Client, +) -> int: + return client.query_single( + """\ + select 1;\ + """, + ) diff --git a/tests/codegen/test-project2/argnames/query_one.edgeql b/tests/codegen/test-project2/argnames/query_one.edgeql new file mode 100644 index 00000000..129cedad --- /dev/null +++ b/tests/codegen/test-project2/argnames/query_one.edgeql @@ -0,0 +1 @@ +select $arg_name_with_underscores diff --git a/tests/codegen/test-project2/argnames/query_one_async_edgeql.py.assert b/tests/codegen/test-project2/argnames/query_one_async_edgeql.py.assert new file mode 100644 index 00000000..31522841 --- /dev/null +++ b/tests/codegen/test-project2/argnames/query_one_async_edgeql.py.assert @@ -0,0 +1,28 @@ +# AUTOGENERATED FROM 'argnames/query_one.edgeql' WITH: +# $ edgedb-py + + +from __future__ import annotations +import edgedb + + +class NoPydanticValidation: + @classmethod + def __get_validators__(cls): + from pydantic.dataclasses import dataclass as pydantic_dataclass + pydantic_dataclass(cls) + cls.__pydantic_model__.__get_validators__ = lambda: [] + return [] + + +async def query_one( + client: edgedb.AsyncIOClient, + *, + arg_name_with_underscores: int, +) -> int: + return await client.query_single( + """\ + select $arg_name_with_underscores\ + """, + arg_name_with_underscores=arg_name_with_underscores, + ) diff --git a/tests/codegen/test-project2/argnames/query_one_edgeql.py.assert b/tests/codegen/test-project2/argnames/query_one_edgeql.py.assert new file mode 100644 index 00000000..d8a944a8 --- /dev/null +++ b/tests/codegen/test-project2/argnames/query_one_edgeql.py.assert @@ -0,0 +1,19 @@ +# AUTOGENERATED FROM 'argnames/query_one.edgeql' WITH: +# $ edgedb-py --target blocking + + +from __future__ import annotations +import edgedb + + +def query_one( + client: edgedb.Client, + *, + arg_name_with_underscores: int, +) -> int: + return client.query_single( + """\ + select $arg_name_with_underscores\ + """, + arg_name_with_underscores=arg_name_with_underscores, + ) diff --git a/tests/codegen/test-project2/dbschema/migrations/00001.edgeqll b/tests/codegen/test-project2/dbschema/migrations/00001.edgeqll new file mode 100644 index 00000000..88bbd870 --- /dev/null +++ b/tests/codegen/test-project2/dbschema/migrations/00001.edgeqll @@ -0,0 +1,12 @@ +CREATE MIGRATION m1fqtauhtvc2w56wh2676x5g26aye22ghx7b7mtnbfekxpmxmnjx2a + ONTO initial +{ + CREATE TYPE default::Person { + CREATE MULTI LINK friends -> default::Person { + CREATE PROPERTY strength -> std::float64; + }; + CREATE REQUIRED PROPERTY name -> std::str { + CREATE CONSTRAINT std::exclusive; + }; + }; +}; diff --git a/tests/codegen/test-project2/edgedb.toml b/tests/codegen/test-project2/edgedb.toml new file mode 100644 index 00000000..e69de29b diff --git a/tests/codegen/test-project2/generated_async_edgeql.py.assert b/tests/codegen/test-project2/generated_async_edgeql.py.assert new file mode 100644 index 00000000..6268293b --- /dev/null +++ b/tests/codegen/test-project2/generated_async_edgeql.py.assert @@ -0,0 +1,362 @@ +# AUTOGENERATED FROM: +# 'parpkg/subpkg/my_query.edgeql' +# 'argnames/query_one.edgeql' +# 'parpkg/select_args.edgeql' +# 'object/select_object.edgeql' +# 'object/select_objects.edgeql' +# 'scalar/select_scalar.edgeql' +# 'scalar/select_scalars.edgeql' +# WITH: +# $ edgedb-py --target async --file + + +from __future__ import annotations +import dataclasses +import datetime +import edgedb +import enum +import uuid + + +MyScalar = int + + +class MyEnum(enum.Enum): + THIS = "This" + THAT = "That" + + +@dataclasses.dataclass +class MyQueryResult: + id: uuid.UUID + a: uuid.UUID + b: uuid.UUID | None + c: str + d: str | None + e: bytes + f: bytes | None + g: int + h: int | None + i: int + j: int | None + k: int + l: int | None + m: float + n: float | None + o: float + p: float | None + q: bool + r: bool | None + s: datetime.datetime + t: datetime.datetime | None + u: datetime.datetime + v: datetime.datetime | None + w: datetime.date + x: datetime.date | None + y: datetime.time + z: datetime.time | None + aa: datetime.timedelta + ab: datetime.timedelta | None + ac: int + ad: int | None + ae: edgedb.RelativeDuration + af: edgedb.RelativeDuration | None + ag: edgedb.DateDuration + ah: edgedb.DateDuration | None + ai: edgedb.ConfigMemory + aj: edgedb.ConfigMemory | None + ak: edgedb.Range[int] + al: edgedb.Range[int] | None + am: edgedb.Range[int] + an: edgedb.Range[int] | None + ao: edgedb.Range[float] + ap: edgedb.Range[float] | None + aq: edgedb.Range[float] + ar: edgedb.Range[float] | None + as_: edgedb.Range[datetime.datetime] + at: edgedb.Range[datetime.datetime] | None + au: edgedb.Range[datetime.datetime] + av: edgedb.Range[datetime.datetime] | None + aw: edgedb.Range[datetime.date] + ax: edgedb.Range[datetime.date] | None + ay: MyScalar + az: MyScalar | None + ba: MyEnum + bb: MyEnum | None + + +@dataclasses.dataclass +class SelectArgsResult: + id: uuid.UUID + Str: str + DateTime: datetime.datetime + + +@dataclasses.dataclass +class SelectObjectResult: + id: uuid.UUID + Name: str + Language: str + Params: list[SelectObjectResultParamsItem] + + +@dataclasses.dataclass +class SelectObjectResultParamsItem: + id: uuid.UUID + Name: str + Default: str | None + + +async def my_query( + client: edgedb.AsyncIOClient, + *, + a: uuid.UUID, + b: uuid.UUID, + c: str, + d: str, + e: bytes, + f: bytes, + g: int, + h: int, + i: int, + j: int, + k: int, + l: int, + m: float, + n: float, + o: float, + p: float, + q: bool, + r: bool, + s: datetime.datetime, + t: datetime.datetime, + u: datetime.datetime, + v: datetime.datetime, + w: datetime.date, + x: datetime.date, + y: datetime.time, + z: datetime.time, + aa: datetime.timedelta, + ab: datetime.timedelta, + ac: int, + ad: int, + ae: edgedb.RelativeDuration, + af: edgedb.RelativeDuration, + ag: edgedb.DateDuration, + ah: edgedb.DateDuration, + ai: edgedb.ConfigMemory, + aj: edgedb.ConfigMemory, + ak: edgedb.Range[int], + al: edgedb.Range[int], + am: edgedb.Range[int], + an: edgedb.Range[int], + ao: edgedb.Range[float], + ap: edgedb.Range[float], + aq: edgedb.Range[float], + ar: edgedb.Range[float], + as_: edgedb.Range[datetime.datetime], + at: edgedb.Range[datetime.datetime], + au: edgedb.Range[datetime.datetime], + av: edgedb.Range[datetime.datetime], + aw: edgedb.Range[datetime.date], + ax: edgedb.Range[datetime.date], +) -> MyQueryResult: + return await client.query_single( + """\ + create scalar type MyScalar extending int64; + create scalar type MyEnum extending enum; + + select { + a := $a, + b := $b, + c := $c, + d := $d, + e := $e, + f := $f, + g := $g, + h := $h, + i := $i, + j := $j, + k := $k, + l := $l, + m := $m, + n := $n, + o := $o, + p := $p, + q := $q, + r := $r, + s := $s, + t := $t, + u := $u, + v := $v, + w := $w, + x := $x, + y := $y, + z := $z, + aa := $aa, + ab := $ab, + ac := $ac, + ad := $ad, + ae := $ae, + af := $af, + ag := $ag, + ah := $ah, + ai := $ai, + aj := $aj, + ak := >$ak, + al := >$al, + am := >$am, + an := >$an, + ao := >$ao, + ap := >$ap, + aq := >$aq, + ar := >$ar, + as_ := >$as_, + at := >$at, + au := >$au, + av := >$av, + aw := >$aw, + ax := >$ax, + ay := 1, + az := {}, + ba := MyEnum.This, + bb := {}, + }\ + """, + a=a, + b=b, + c=c, + d=d, + e=e, + f=f, + g=g, + h=h, + i=i, + j=j, + k=k, + l=l, + m=m, + n=n, + o=o, + p=p, + q=q, + r=r, + s=s, + t=t, + u=u, + v=v, + w=w, + x=x, + y=y, + z=z, + aa=aa, + ab=ab, + ac=ac, + ad=ad, + ae=ae, + af=af, + ag=ag, + ah=ah, + ai=ai, + aj=aj, + ak=ak, + al=al, + am=am, + an=an, + ao=ao, + ap=ap, + aq=aq, + ar=ar, + as_=as_, + at=at, + au=au, + av=av, + aw=aw, + ax=ax, + ) + + +async def query_one( + client: edgedb.AsyncIOClient, + *, + arg_name_with_underscores: int, +) -> int: + return await client.query_single( + """\ + select $arg_name_with_underscores\ + """, + arg_name_with_underscores=arg_name_with_underscores, + ) + + +async def select_args( + client: edgedb.AsyncIOClient, + *, + str: str, + datetime: datetime.datetime, +) -> SelectArgsResult: + return await client.query_single( + """\ + select { + Str := $str, + DateTime := $datetime, + }\ + """, + str=str, + datetime=datetime, + ) + + +async def select_object( + client: edgedb.AsyncIOClient, +) -> SelectObjectResult | None: + return await client.query_single( + """\ + select schema::Function { + Name := .name, + Language := .language, + Params := .params { + Name := .name, + Default := .default, + } + } + limit 1;\ + """, + ) + + +async def select_objects( + client: edgedb.AsyncIOClient, +) -> list[SelectObjectResult]: + return await client.query( + """\ + select schema::Function { + Name := .name, + Language := .language, + Params := .params { + Name := .name, + Default := .default, + } + }\ + """, + ) + + +async def select_scalar( + client: edgedb.AsyncIOClient, +) -> int: + return await client.query_single( + """\ + select 1;\ + """, + ) + + +async def select_scalars( + client: edgedb.AsyncIOClient, +) -> list[edgedb.ConfigMemory]: + return await client.query( + """\ + select {1, 2, 3};\ + """, + ) diff --git a/tests/codegen/test-project2/object/select_object.edgeql b/tests/codegen/test-project2/object/select_object.edgeql new file mode 100644 index 00000000..839f6b7b --- /dev/null +++ b/tests/codegen/test-project2/object/select_object.edgeql @@ -0,0 +1,9 @@ +select schema::Function { + Name := .name, + Language := .language, + Params := .params { + Name := .name, + Default := .default, + } +} +limit 1; diff --git a/tests/codegen/test-project2/object/select_object_async_edgeql.py.assert b/tests/codegen/test-project2/object/select_object_async_edgeql.py.assert new file mode 100644 index 00000000..a3c75670 --- /dev/null +++ b/tests/codegen/test-project2/object/select_object_async_edgeql.py.assert @@ -0,0 +1,51 @@ +# AUTOGENERATED FROM 'object/select_object.edgeql' WITH: +# $ edgedb-py + + +from __future__ import annotations +import dataclasses +import edgedb +import typing +import uuid + + +class NoPydanticValidation: + @classmethod + def __get_validators__(cls): + from pydantic.dataclasses import dataclass as pydantic_dataclass + pydantic_dataclass(cls) + cls.__pydantic_model__.__get_validators__ = lambda: [] + return [] + + +@dataclasses.dataclass +class SelectObjectResult(NoPydanticValidation): + id: uuid.UUID + Name: str + Language: str + Params: typing.List[SelectObjectResultParamsItem] + + +@dataclasses.dataclass +class SelectObjectResultParamsItem(NoPydanticValidation): + id: uuid.UUID + Name: str + Default: typing.Optional[str] + + +async def select_object( + client: edgedb.AsyncIOClient, +) -> typing.Optional[SelectObjectResult]: + return await client.query_single( + """\ + select schema::Function { + Name := .name, + Language := .language, + Params := .params { + Name := .name, + Default := .default, + } + } + limit 1;\ + """, + ) diff --git a/tests/codegen/test-project2/object/select_object_edgeql.py.assert b/tests/codegen/test-project2/object/select_object_edgeql.py.assert new file mode 100644 index 00000000..9bda7ddb --- /dev/null +++ b/tests/codegen/test-project2/object/select_object_edgeql.py.assert @@ -0,0 +1,42 @@ +# AUTOGENERATED FROM 'object/select_object.edgeql' WITH: +# $ edgedb-py --target blocking + + +from __future__ import annotations +import dataclasses +import edgedb +import typing +import uuid + + +@dataclasses.dataclass +class SelectObjectResult: + id: uuid.UUID + Name: str + Language: str + Params: list[SelectObjectResultParamsItem] + + +@dataclasses.dataclass +class SelectObjectResultParamsItem: + id: uuid.UUID + Name: str + Default: typing.Optional[str] + + +def select_object( + client: edgedb.Client, +) -> typing.Optional[SelectObjectResult]: + return client.query_single( + """\ + select schema::Function { + Name := .name, + Language := .language, + Params := .params { + Name := .name, + Default := .default, + } + } + limit 1;\ + """, + ) diff --git a/tests/codegen/test-project2/object/select_objects.edgeql b/tests/codegen/test-project2/object/select_objects.edgeql new file mode 100644 index 00000000..cea3bc36 --- /dev/null +++ b/tests/codegen/test-project2/object/select_objects.edgeql @@ -0,0 +1,8 @@ +select schema::Function { + Name := .name, + Language := .language, + Params := .params { + Name := .name, + Default := .default, + } +} diff --git a/tests/codegen/test-project2/object/select_objects_async_edgeql.py.assert b/tests/codegen/test-project2/object/select_objects_async_edgeql.py.assert new file mode 100644 index 00000000..3742d198 --- /dev/null +++ b/tests/codegen/test-project2/object/select_objects_async_edgeql.py.assert @@ -0,0 +1,50 @@ +# AUTOGENERATED FROM 'object/select_objects.edgeql' WITH: +# $ edgedb-py + + +from __future__ import annotations +import dataclasses +import edgedb +import typing +import uuid + + +class NoPydanticValidation: + @classmethod + def __get_validators__(cls): + from pydantic.dataclasses import dataclass as pydantic_dataclass + pydantic_dataclass(cls) + cls.__pydantic_model__.__get_validators__ = lambda: [] + return [] + + +@dataclasses.dataclass +class SelectObjectsResult(NoPydanticValidation): + id: uuid.UUID + Name: str + Language: str + Params: typing.List[SelectObjectsResultParamsItem] + + +@dataclasses.dataclass +class SelectObjectsResultParamsItem(NoPydanticValidation): + id: uuid.UUID + Name: str + Default: typing.Optional[str] + + +async def select_objects( + client: edgedb.AsyncIOClient, +) -> typing.List[SelectObjectsResult]: + return await client.query( + """\ + select schema::Function { + Name := .name, + Language := .language, + Params := .params { + Name := .name, + Default := .default, + } + }\ + """, + ) diff --git a/tests/codegen/test-project2/object/select_objects_edgeql.py.assert b/tests/codegen/test-project2/object/select_objects_edgeql.py.assert new file mode 100644 index 00000000..a1d1d483 --- /dev/null +++ b/tests/codegen/test-project2/object/select_objects_edgeql.py.assert @@ -0,0 +1,41 @@ +# AUTOGENERATED FROM 'object/select_objects.edgeql' WITH: +# $ edgedb-py --target blocking + + +from __future__ import annotations +import dataclasses +import edgedb +import typing +import uuid + + +@dataclasses.dataclass +class SelectObjectsResult: + id: uuid.UUID + Name: str + Language: str + Params: list[SelectObjectsResultParamsItem] + + +@dataclasses.dataclass +class SelectObjectsResultParamsItem: + id: uuid.UUID + Name: str + Default: typing.Optional[str] + + +def select_objects( + client: edgedb.Client, +) -> list[SelectObjectsResult]: + return client.query( + """\ + select schema::Function { + Name := .name, + Language := .language, + Params := .params { + Name := .name, + Default := .default, + } + }\ + """, + ) diff --git a/tests/codegen/test-project2/parpkg/select_args.edgeql b/tests/codegen/test-project2/parpkg/select_args.edgeql new file mode 100644 index 00000000..0e6294c0 --- /dev/null +++ b/tests/codegen/test-project2/parpkg/select_args.edgeql @@ -0,0 +1,4 @@ +select { + Str := $str, + DateTime := $datetime, +} diff --git a/tests/codegen/test-project2/parpkg/select_args_async_edgeql.py.assert b/tests/codegen/test-project2/parpkg/select_args_async_edgeql.py.assert new file mode 100644 index 00000000..17cb08e1 --- /dev/null +++ b/tests/codegen/test-project2/parpkg/select_args_async_edgeql.py.assert @@ -0,0 +1,43 @@ +# AUTOGENERATED FROM 'parpkg/select_args.edgeql' WITH: +# $ edgedb-py + + +from __future__ import annotations +import dataclasses +import datetime +import edgedb +import uuid + + +class NoPydanticValidation: + @classmethod + def __get_validators__(cls): + from pydantic.dataclasses import dataclass as pydantic_dataclass + pydantic_dataclass(cls) + cls.__pydantic_model__.__get_validators__ = lambda: [] + return [] + + +@dataclasses.dataclass +class SelectArgsResult(NoPydanticValidation): + id: uuid.UUID + Str: str + DateTime: datetime.datetime + + +async def select_args( + client: edgedb.AsyncIOClient, + *, + str: str, + datetime: datetime.datetime, +) -> SelectArgsResult: + return await client.query_single( + """\ + select { + Str := $str, + DateTime := $datetime, + }\ + """, + str=str, + datetime=datetime, + ) diff --git a/tests/codegen/test-project2/parpkg/select_args_edgeql.py.assert b/tests/codegen/test-project2/parpkg/select_args_edgeql.py.assert new file mode 100644 index 00000000..5f445d4c --- /dev/null +++ b/tests/codegen/test-project2/parpkg/select_args_edgeql.py.assert @@ -0,0 +1,34 @@ +# AUTOGENERATED FROM 'parpkg/select_args.edgeql' WITH: +# $ edgedb-py --target blocking + + +from __future__ import annotations +import dataclasses +import datetime +import edgedb +import uuid + + +@dataclasses.dataclass +class SelectArgsResult: + id: uuid.UUID + Str: str + DateTime: datetime.datetime + + +def select_args( + client: edgedb.Client, + *, + str: str, + datetime: datetime.datetime, +) -> SelectArgsResult: + return client.query_single( + """\ + select { + Str := $str, + DateTime := $datetime, + }\ + """, + str=str, + datetime=datetime, + ) diff --git a/tests/codegen/test-project2/parpkg/subpkg/my_query.edgeql b/tests/codegen/test-project2/parpkg/subpkg/my_query.edgeql new file mode 100644 index 00000000..2a9b2e49 --- /dev/null +++ b/tests/codegen/test-project2/parpkg/subpkg/my_query.edgeql @@ -0,0 +1,59 @@ +create scalar type MyScalar extending int64; +create scalar type MyEnum extending enum; + +select { + a := $a, + b := $b, + c := $c, + d := $d, + e := $e, + f := $f, + g := $g, + h := $h, + i := $i, + j := $j, + k := $k, + l := $l, + m := $m, + n := $n, + o := $o, + p := $p, + q := $q, + r := $r, + s := $s, + t := $t, + u := $u, + v := $v, + w := $w, + x := $x, + y := $y, + z := $z, + aa := $aa, + ab := $ab, + ac := $ac, + ad := $ad, + ae := $ae, + af := $af, + ag := $ag, + ah := $ah, + ai := $ai, + aj := $aj, + ak := >$ak, + al := >$al, + am := >$am, + an := >$an, + ao := >$ao, + ap := >$ap, + aq := >$aq, + ar := >$ar, + as_ := >$as_, + at := >$at, + au := >$au, + av := >$av, + aw := >$aw, + ax := >$ax, + ay := 1, + az := {}, + ba := MyEnum.This, + bb := {}, +} diff --git a/tests/codegen/test-project2/parpkg/subpkg/my_query_async_edgeql.py.assert b/tests/codegen/test-project2/parpkg/subpkg/my_query_async_edgeql.py.assert new file mode 100644 index 00000000..94b61522 --- /dev/null +++ b/tests/codegen/test-project2/parpkg/subpkg/my_query_async_edgeql.py.assert @@ -0,0 +1,256 @@ +# AUTOGENERATED FROM 'parpkg/subpkg/my_query.edgeql' WITH: +# $ edgedb-py + + +from __future__ import annotations +import dataclasses +import datetime +import edgedb +import enum +import typing +import uuid + + +MyScalar = int + + +class NoPydanticValidation: + @classmethod + def __get_validators__(cls): + from pydantic.dataclasses import dataclass as pydantic_dataclass + pydantic_dataclass(cls) + cls.__pydantic_model__.__get_validators__ = lambda: [] + return [] + + +class MyEnum(enum.Enum): + THIS = "This" + THAT = "That" + + +@dataclasses.dataclass +class MyQueryResult(NoPydanticValidation): + id: uuid.UUID + a: uuid.UUID + b: typing.Optional[uuid.UUID] + c: str + d: typing.Optional[str] + e: bytes + f: typing.Optional[bytes] + g: int + h: typing.Optional[int] + i: int + j: typing.Optional[int] + k: int + l: typing.Optional[int] + m: float + n: typing.Optional[float] + o: float + p: typing.Optional[float] + q: bool + r: typing.Optional[bool] + s: datetime.datetime + t: typing.Optional[datetime.datetime] + u: datetime.datetime + v: typing.Optional[datetime.datetime] + w: datetime.date + x: typing.Optional[datetime.date] + y: datetime.time + z: typing.Optional[datetime.time] + aa: datetime.timedelta + ab: typing.Optional[datetime.timedelta] + ac: int + ad: typing.Optional[int] + ae: edgedb.RelativeDuration + af: typing.Optional[edgedb.RelativeDuration] + ag: edgedb.DateDuration + ah: typing.Optional[edgedb.DateDuration] + ai: edgedb.ConfigMemory + aj: typing.Optional[edgedb.ConfigMemory] + ak: edgedb.Range[int] + al: typing.Optional[edgedb.Range[int]] + am: edgedb.Range[int] + an: typing.Optional[edgedb.Range[int]] + ao: edgedb.Range[float] + ap: typing.Optional[edgedb.Range[float]] + aq: edgedb.Range[float] + ar: typing.Optional[edgedb.Range[float]] + as_: edgedb.Range[datetime.datetime] + at: typing.Optional[edgedb.Range[datetime.datetime]] + au: edgedb.Range[datetime.datetime] + av: typing.Optional[edgedb.Range[datetime.datetime]] + aw: edgedb.Range[datetime.date] + ax: typing.Optional[edgedb.Range[datetime.date]] + ay: MyScalar + az: typing.Optional[MyScalar] + ba: MyEnum + bb: typing.Optional[MyEnum] + + +async def my_query( + client: edgedb.AsyncIOClient, + *, + a: uuid.UUID, + b: uuid.UUID, + c: str, + d: str, + e: bytes, + f: bytes, + g: int, + h: int, + i: int, + j: int, + k: int, + l: int, + m: float, + n: float, + o: float, + p: float, + q: bool, + r: bool, + s: datetime.datetime, + t: datetime.datetime, + u: datetime.datetime, + v: datetime.datetime, + w: datetime.date, + x: datetime.date, + y: datetime.time, + z: datetime.time, + aa: datetime.timedelta, + ab: datetime.timedelta, + ac: int, + ad: int, + ae: edgedb.RelativeDuration, + af: edgedb.RelativeDuration, + ag: edgedb.DateDuration, + ah: edgedb.DateDuration, + ai: edgedb.ConfigMemory, + aj: edgedb.ConfigMemory, + ak: edgedb.Range[int], + al: edgedb.Range[int], + am: edgedb.Range[int], + an: edgedb.Range[int], + ao: edgedb.Range[float], + ap: edgedb.Range[float], + aq: edgedb.Range[float], + ar: edgedb.Range[float], + as_: edgedb.Range[datetime.datetime], + at: edgedb.Range[datetime.datetime], + au: edgedb.Range[datetime.datetime], + av: edgedb.Range[datetime.datetime], + aw: edgedb.Range[datetime.date], + ax: edgedb.Range[datetime.date], +) -> MyQueryResult: + return await client.query_single( + """\ + create scalar type MyScalar extending int64; + create scalar type MyEnum extending enum; + + select { + a := $a, + b := $b, + c := $c, + d := $d, + e := $e, + f := $f, + g := $g, + h := $h, + i := $i, + j := $j, + k := $k, + l := $l, + m := $m, + n := $n, + o := $o, + p := $p, + q := $q, + r := $r, + s := $s, + t := $t, + u := $u, + v := $v, + w := $w, + x := $x, + y := $y, + z := $z, + aa := $aa, + ab := $ab, + ac := $ac, + ad := $ad, + ae := $ae, + af := $af, + ag := $ag, + ah := $ah, + ai := $ai, + aj := $aj, + ak := >$ak, + al := >$al, + am := >$am, + an := >$an, + ao := >$ao, + ap := >$ap, + aq := >$aq, + ar := >$ar, + as_ := >$as_, + at := >$at, + au := >$au, + av := >$av, + aw := >$aw, + ax := >$ax, + ay := 1, + az := {}, + ba := MyEnum.This, + bb := {}, + }\ + """, + a=a, + b=b, + c=c, + d=d, + e=e, + f=f, + g=g, + h=h, + i=i, + j=j, + k=k, + l=l, + m=m, + n=n, + o=o, + p=p, + q=q, + r=r, + s=s, + t=t, + u=u, + v=v, + w=w, + x=x, + y=y, + z=z, + aa=aa, + ab=ab, + ac=ac, + ad=ad, + ae=ae, + af=af, + ag=ag, + ah=ah, + ai=ai, + aj=aj, + ak=ak, + al=al, + am=am, + an=an, + ao=ao, + ap=ap, + aq=aq, + ar=ar, + as_=as_, + at=at, + au=au, + av=av, + aw=aw, + ax=ax, + ) diff --git a/tests/codegen/test-project2/parpkg/subpkg/my_query_edgeql.py.assert b/tests/codegen/test-project2/parpkg/subpkg/my_query_edgeql.py.assert new file mode 100644 index 00000000..f0d22935 --- /dev/null +++ b/tests/codegen/test-project2/parpkg/subpkg/my_query_edgeql.py.assert @@ -0,0 +1,247 @@ +# AUTOGENERATED FROM 'parpkg/subpkg/my_query.edgeql' WITH: +# $ edgedb-py --target blocking + + +from __future__ import annotations +import dataclasses +import datetime +import edgedb +import enum +import typing +import uuid + + +MyScalar = int + + +class MyEnum(enum.Enum): + THIS = "This" + THAT = "That" + + +@dataclasses.dataclass +class MyQueryResult: + id: uuid.UUID + a: uuid.UUID + b: typing.Optional[uuid.UUID] + c: str + d: typing.Optional[str] + e: bytes + f: typing.Optional[bytes] + g: int + h: typing.Optional[int] + i: int + j: typing.Optional[int] + k: int + l: typing.Optional[int] + m: float + n: typing.Optional[float] + o: float + p: typing.Optional[float] + q: bool + r: typing.Optional[bool] + s: datetime.datetime + t: typing.Optional[datetime.datetime] + u: datetime.datetime + v: typing.Optional[datetime.datetime] + w: datetime.date + x: typing.Optional[datetime.date] + y: datetime.time + z: typing.Optional[datetime.time] + aa: datetime.timedelta + ab: typing.Optional[datetime.timedelta] + ac: int + ad: typing.Optional[int] + ae: edgedb.RelativeDuration + af: typing.Optional[edgedb.RelativeDuration] + ag: edgedb.DateDuration + ah: typing.Optional[edgedb.DateDuration] + ai: edgedb.ConfigMemory + aj: typing.Optional[edgedb.ConfigMemory] + ak: edgedb.Range[int] + al: typing.Optional[edgedb.Range[int]] + am: edgedb.Range[int] + an: typing.Optional[edgedb.Range[int]] + ao: edgedb.Range[float] + ap: typing.Optional[edgedb.Range[float]] + aq: edgedb.Range[float] + ar: typing.Optional[edgedb.Range[float]] + as_: edgedb.Range[datetime.datetime] + at: typing.Optional[edgedb.Range[datetime.datetime]] + au: edgedb.Range[datetime.datetime] + av: typing.Optional[edgedb.Range[datetime.datetime]] + aw: edgedb.Range[datetime.date] + ax: typing.Optional[edgedb.Range[datetime.date]] + ay: MyScalar + az: typing.Optional[MyScalar] + ba: MyEnum + bb: typing.Optional[MyEnum] + + +def my_query( + client: edgedb.Client, + *, + a: uuid.UUID, + b: uuid.UUID, + c: str, + d: str, + e: bytes, + f: bytes, + g: int, + h: int, + i: int, + j: int, + k: int, + l: int, + m: float, + n: float, + o: float, + p: float, + q: bool, + r: bool, + s: datetime.datetime, + t: datetime.datetime, + u: datetime.datetime, + v: datetime.datetime, + w: datetime.date, + x: datetime.date, + y: datetime.time, + z: datetime.time, + aa: datetime.timedelta, + ab: datetime.timedelta, + ac: int, + ad: int, + ae: edgedb.RelativeDuration, + af: edgedb.RelativeDuration, + ag: edgedb.DateDuration, + ah: edgedb.DateDuration, + ai: edgedb.ConfigMemory, + aj: edgedb.ConfigMemory, + ak: edgedb.Range[int], + al: edgedb.Range[int], + am: edgedb.Range[int], + an: edgedb.Range[int], + ao: edgedb.Range[float], + ap: edgedb.Range[float], + aq: edgedb.Range[float], + ar: edgedb.Range[float], + as_: edgedb.Range[datetime.datetime], + at: edgedb.Range[datetime.datetime], + au: edgedb.Range[datetime.datetime], + av: edgedb.Range[datetime.datetime], + aw: edgedb.Range[datetime.date], + ax: edgedb.Range[datetime.date], +) -> MyQueryResult: + return client.query_single( + """\ + create scalar type MyScalar extending int64; + create scalar type MyEnum extending enum; + + select { + a := $a, + b := $b, + c := $c, + d := $d, + e := $e, + f := $f, + g := $g, + h := $h, + i := $i, + j := $j, + k := $k, + l := $l, + m := $m, + n := $n, + o := $o, + p := $p, + q := $q, + r := $r, + s := $s, + t := $t, + u := $u, + v := $v, + w := $w, + x := $x, + y := $y, + z := $z, + aa := $aa, + ab := $ab, + ac := $ac, + ad := $ad, + ae := $ae, + af := $af, + ag := $ag, + ah := $ah, + ai := $ai, + aj := $aj, + ak := >$ak, + al := >$al, + am := >$am, + an := >$an, + ao := >$ao, + ap := >$ap, + aq := >$aq, + ar := >$ar, + as_ := >$as_, + at := >$at, + au := >$au, + av := >$av, + aw := >$aw, + ax := >$ax, + ay := 1, + az := {}, + ba := MyEnum.This, + bb := {}, + }\ + """, + a=a, + b=b, + c=c, + d=d, + e=e, + f=f, + g=g, + h=h, + i=i, + j=j, + k=k, + l=l, + m=m, + n=n, + o=o, + p=p, + q=q, + r=r, + s=s, + t=t, + u=u, + v=v, + w=w, + x=x, + y=y, + z=z, + aa=aa, + ab=ab, + ac=ac, + ad=ad, + ae=ae, + af=af, + ag=ag, + ah=ah, + ai=ai, + aj=aj, + ak=ak, + al=al, + am=am, + an=an, + ao=ao, + ap=ap, + aq=aq, + ar=ar, + as_=as_, + at=at, + au=au, + av=av, + aw=aw, + ax=ax, + ) diff --git a/tests/codegen/test-project2/scalar/select_scalar.edgeql b/tests/codegen/test-project2/scalar/select_scalar.edgeql new file mode 100644 index 00000000..ab290eb4 --- /dev/null +++ b/tests/codegen/test-project2/scalar/select_scalar.edgeql @@ -0,0 +1 @@ +select 1; diff --git a/tests/codegen/test-project2/scalar/select_scalar_async_edgeql.py.assert b/tests/codegen/test-project2/scalar/select_scalar_async_edgeql.py.assert new file mode 100644 index 00000000..299fcff6 --- /dev/null +++ b/tests/codegen/test-project2/scalar/select_scalar_async_edgeql.py.assert @@ -0,0 +1,25 @@ +# AUTOGENERATED FROM 'scalar/select_scalar.edgeql' WITH: +# $ edgedb-py + + +from __future__ import annotations +import edgedb + + +class NoPydanticValidation: + @classmethod + def __get_validators__(cls): + from pydantic.dataclasses import dataclass as pydantic_dataclass + pydantic_dataclass(cls) + cls.__pydantic_model__.__get_validators__ = lambda: [] + return [] + + +async def select_scalar( + client: edgedb.AsyncIOClient, +) -> int: + return await client.query_single( + """\ + select 1;\ + """, + ) diff --git a/tests/codegen/test-project2/scalar/select_scalar_edgeql.py.assert b/tests/codegen/test-project2/scalar/select_scalar_edgeql.py.assert new file mode 100644 index 00000000..673b004f --- /dev/null +++ b/tests/codegen/test-project2/scalar/select_scalar_edgeql.py.assert @@ -0,0 +1,16 @@ +# AUTOGENERATED FROM 'scalar/select_scalar.edgeql' WITH: +# $ edgedb-py --target blocking + + +from __future__ import annotations +import edgedb + + +def select_scalar( + client: edgedb.Client, +) -> int: + return client.query_single( + """\ + select 1;\ + """, + ) diff --git a/tests/codegen/test-project2/scalar/select_scalars.edgeql b/tests/codegen/test-project2/scalar/select_scalars.edgeql new file mode 100644 index 00000000..43621c46 --- /dev/null +++ b/tests/codegen/test-project2/scalar/select_scalars.edgeql @@ -0,0 +1 @@ +select {1, 2, 3}; diff --git a/tests/codegen/test-project2/scalar/select_scalars_async_edgeql.py.assert b/tests/codegen/test-project2/scalar/select_scalars_async_edgeql.py.assert new file mode 100644 index 00000000..ece03d9a --- /dev/null +++ b/tests/codegen/test-project2/scalar/select_scalars_async_edgeql.py.assert @@ -0,0 +1,26 @@ +# AUTOGENERATED FROM 'scalar/select_scalars.edgeql' WITH: +# $ edgedb-py + + +from __future__ import annotations +import edgedb +import typing + + +class NoPydanticValidation: + @classmethod + def __get_validators__(cls): + from pydantic.dataclasses import dataclass as pydantic_dataclass + pydantic_dataclass(cls) + cls.__pydantic_model__.__get_validators__ = lambda: [] + return [] + + +async def select_scalars( + client: edgedb.AsyncIOClient, +) -> typing.List[edgedb.ConfigMemory]: + return await client.query( + """\ + select {1, 2, 3};\ + """, + ) diff --git a/tests/codegen/test-project2/scalar/select_scalars_edgeql.py.assert b/tests/codegen/test-project2/scalar/select_scalars_edgeql.py.assert new file mode 100644 index 00000000..62e138f1 --- /dev/null +++ b/tests/codegen/test-project2/scalar/select_scalars_edgeql.py.assert @@ -0,0 +1,16 @@ +# AUTOGENERATED FROM 'scalar/select_scalars.edgeql' WITH: +# $ edgedb-py --target blocking + + +from __future__ import annotations +import edgedb + + +def select_scalars( + client: edgedb.Client, +) -> list[edgedb.ConfigMemory]: + return client.query( + """\ + select {1, 2, 3};\ + """, + ) diff --git a/tests/test_codegen.py b/tests/test_codegen.py new file mode 100644 index 00000000..cb651965 --- /dev/null +++ b/tests/test_codegen.py @@ -0,0 +1,90 @@ +# +# This source file is part of the EdgeDB open source project. +# +# Copyright 2019-present MagicStack Inc. and the EdgeDB authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +import asyncio +import pathlib +import shutil +import subprocess +import os +import tempfile + +from edgedb import _testbase as tb + + +class TestCodegen(tb.AsyncQueryTestCase): + async def test_codegen(self): + env = os.environ.copy() + env.update( + { + f"EDGEDB_{k.upper()}": str(v) + for k, v in self.get_connect_args().items() + } + ) + container = pathlib.Path(__file__).absolute().parent / "codegen" + with tempfile.TemporaryDirectory() as td: + td_path = pathlib.Path(td) + for project in container.iterdir(): + cwd = td_path / project.name + shutil.copytree(project, cwd) + await self._test_codegen(env, cwd) + + async def _test_codegen(self, env, cwd: pathlib.Path): + async def run(*args, extra_env=None): + if extra_env is None: + env_ = env + else: + env_ = env.copy() + env_.update(extra_env) + p = await asyncio.create_subprocess_exec( + *args, + cwd=cwd, + env=env_, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + ) + try: + await asyncio.wait_for(p.wait(), 10) + except asyncio.TimeoutError: + p.terminate() + await p.wait() + raise + + await run( + "edgedb-py", extra_env={"EDGEDB_PYTHON_CODEGEN_PY_VER": "3.8.5"} + ) + await run( + "edgedb-py", + "--target", + "blocking", + extra_env={"EDGEDB_PYTHON_CODEGEN_PY_VER": "3.9.2"}, + ) + await run( + "edgedb-py", + "--target", + "async", + "--file", + extra_env={"EDGEDB_PYTHON_CODEGEN_PY_VER": "3.10.3"}, + ) + + for f in cwd.rglob("*.py"): + a = f.with_suffix(".py.assert") + self.assertEqual(f.read_text(), a.read_text()) + for a in cwd.rglob("*.py.assert"): + f = a.with_suffix("") + self.assertTrue(f.exists(), f"{f} doesn't exist")