Skip to content

Commit b8afbef

Browse files
1st1dnwpark
authored andcommitted
Refactor tests to namespace generated schema into models.{schema}
1 parent 6824f20 commit b8afbef

File tree

8 files changed

+1276
-1015
lines changed

8 files changed

+1276
-1015
lines changed

gel/_testbase.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,10 @@ def setUpClass(cls):
754754
td_kwargs["delete"] = not cls.orm_debug
755755

756756
cls.tmp_model_dir = tempfile.TemporaryDirectory(**td_kwargs)
757+
758+
assert isinstance(cls.SCHEMA, str)
759+
short_name = pathlib.Path(cls.SCHEMA).stem
760+
757761
if cls.orm_debug:
758762
print(cls.tmp_model_dir.name)
759763

@@ -766,7 +770,15 @@ def setUpClass(cls):
766770
try:
767771
gen_client.ensure_connected()
768772
cls.gen = PydanticModelsGenerator(
769-
argparse.Namespace(no_cache=True, quiet=True, output=None),
773+
argparse.Namespace(
774+
no_cache=True,
775+
quiet=True,
776+
output=(
777+
pathlib.Path(cls.tmp_model_dir.name)
778+
/ "models"
779+
/ short_name
780+
).absolute(),
781+
),
770782
project_dir=pathlib.Path(cls.tmp_model_dir.name),
771783
client=gen_client,
772784
interactive=False,

tests/dbsetup/empty.gel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# keep this file empty!

tests/test_async_model.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class TestAsyncModelGenerator(tb.AsyncModelTestCase):
2020

2121
@tb.must_fail # this test ensures that @typecheck is working
2222
async def test_async_modelgen__smoke_test_01(self):
23-
from models import default
23+
from models.orm import default
2424

2525
self.assertEqual(reveal_type(default.User.groups), "this must fail")
2626

@@ -30,7 +30,7 @@ async def test_async_modelgen__smoke_test_02(self):
3030
raise AssertionError("this must fail")
3131

3232
async def test_async_modelgen_01(self):
33-
from models import default
33+
from models.orm import default
3434

3535
alice = await self.client.query_required_single(
3636
default.User.select(
@@ -50,7 +50,7 @@ async def test_async_modelgen_01(self):
5050
async def test_async_modelgen_02(self):
5151
import uuid
5252

53-
from models import default
53+
from models.orm import default
5454
# insert an object with a required multi: no link props, one object
5555
# added to the link
5656

@@ -80,7 +80,7 @@ async def test_async_modelgen_02(self):
8080
self.assertEqual(m.nickname, "Hannibal")
8181

8282
async def test_async_modelgen_save_refetch_modes(self):
83-
from models import default
83+
from models.orm import default
8484

8585
u1 = default.User(name="Al")
8686
await self.client.sync(u1)
@@ -94,7 +94,7 @@ async def test_async_modelgen_save_reload_links_07(self):
9494
# This is a copy if test_async_modelgen_save_reload_links_07
9595
# ensuring the sync() is fully supported in async mode.
9696

97-
from models import default
97+
from models.orm import default
9898

9999
# Test backlink invalidation when adding a user to a different group
100100
# Fetch red and blue groups with nested user data and their groups
@@ -153,7 +153,7 @@ async def test_async_modelgen_save_reload_links_07(self):
153153
self.assertEqual({u.id for u in blue.users}, {alice.id})
154154

155155
async def test_async_modelgen_sync_warning(self):
156-
from models import default
156+
from models.orm import default
157157

158158
g = default.UserGroup(
159159
name="Pickle Pirates",

0 commit comments

Comments
 (0)