Skip to content

Commit

Permalink
more reset refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
meksor committed Aug 12, 2024
1 parent 9128792 commit 0182c7f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions ixmp4/data/backend/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def make_client(self, rest_url: str, auth: BaseAuth):
def close(self):
self.client.close()
self.executor.shutdown(cancel_futures=True)
self.db_backend.close()

def setup(self):
self.db_backend.setup()
Expand Down
12 changes: 8 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@ def __init__(self, postgres_dsn: str) -> None:
def rest_sqlite(self):
with self.sqlite() as backend:
rest = RestTestBackend(backend)
rest.setup()
yield rest
rest.teardown()
rest.close()

@contextmanager
def rest_postgresql(self):
with self.postgresql() as backend:
rest = RestTestBackend(backend)
rest.setup()
yield rest
rest.teardown()
rest.close()

@contextmanager
Expand All @@ -65,15 +69,19 @@ def postgresql(self):
dsn=self.postgres_dsn,
),
)
pgsql.setup()
yield pgsql
pgsql.teardown()
pgsql.close()

@contextmanager
def sqlite(self):
sqlite = SqliteTestBackend(
PlatformInfo(name="sqlite-test", dsn="sqlite:///:memory:")
)
sqlite.setup()
yield sqlite
sqlite.teardown()
sqlite.close()


Expand All @@ -97,9 +105,7 @@ def platform_fixture(request):
bctx = get_backend_context(type, postgres_dsn)

with bctx as backend:
backend.setup()
yield Platform(_backend=backend)
backend.teardown()


rest_platform = pytest.fixture(platform_fixture, name="rest_platform")
Expand All @@ -116,11 +122,9 @@ def platform_td_big(request):
bctx = get_backend_context(type, postgres_dsn)

with bctx as backend:
backend.setup()
platform = Platform(_backend=backend)
big.load_dataset(platform)
yield platform
backend.teardown()


db_platform_big = pytest.fixture(
Expand Down

0 comments on commit 0182c7f

Please sign in to comment.