Skip to content

Commit 1f20908

Browse files
authored
Merge pull request #20 from wey-gu/more_coverage
adding coverage of ut further more
2 parents 59cd8d0 + 16c5421 commit 1f20908

File tree

9 files changed

+2077
-10
lines changed

9 files changed

+2077
-10
lines changed

.coveragerc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[run]
2+
source = py_pglite
3+
4+
[report]
5+
# Exclude files that are not meant to be tested directly
6+
# We indeed cannot pytest pytest fixtures
7+
# because they are not meant to be tested directly.
8+
omit =
9+
py_pglite/fixtures.py
10+
py_pglite/django/fixtures.py
11+
py_pglite/sqlalchemy/fixtures.py

py_pglite/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
and Python test suites with support for SQLAlchemy, SQLModel, and Django.
55
"""
66

7-
__version__ = "0.4.1"
7+
__version__ = "0.5.0"
88

99
# Core exports (always available)
1010
# Database client exports (choose your preferred client)

py_pglite/clients.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,32 @@ def execute_query(
130130
"""Execute query using asyncpg (sync wrapper)."""
131131
loop = self._get_event_loop()
132132
try:
133-
return loop.run_until_complete(
134-
self._async_execute_query(connection, query, params)
135-
)
133+
# Check if we can use run_until_complete
134+
if loop.is_running():
135+
# If the loop is already running, we need to handle this differently
136+
# This can happen in testing environments like pytest
137+
import warnings
138+
139+
warnings.warn(
140+
"AsyncpgClient used in running event loop context. "
141+
"Consider using PsycopgClient for synchronous operations.",
142+
RuntimeWarning,
143+
stacklevel=2,
144+
)
145+
# For now, we'll try to execute synchronously by creating a new loop
146+
# in a thread, but this is not ideal
147+
import concurrent.futures
148+
149+
with concurrent.futures.ThreadPoolExecutor() as executor:
150+
future = executor.submit(
151+
self._asyncio.run,
152+
self._async_execute_query(connection, query, params),
153+
)
154+
return future.result()
155+
else:
156+
return loop.run_until_complete(
157+
self._async_execute_query(connection, query, params)
158+
)
136159
except Exception as e:
137160
# Ensure we don't leave any coroutines hanging
138161
logger.warning(f"AsyncpgClient execute_query failed: {e}")

py_pglite/django/backend/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ def __init__(self, settings_dict: dict[str, Any], alias: str = "default"):
235235
# Ensure we use the PGlite creation class
236236
settings_dict = settings_dict.copy()
237237

238+
# Set up parent class
239+
self.settings_dict = settings_dict
238240
super().__init__(settings_dict, alias) # type: ignore
239241
self.creation = PGliteDatabaseCreation(self) # type: ignore
240242

@@ -266,6 +268,7 @@ def get_new_connection(self, conn_params: dict[str, Any]) -> Any:
266268
}
267269
)
268270

271+
# Call parent class's method using super()
269272
return super().get_new_connection(conn_params) # type: ignore
270273

271274
def get_database_version(self):

0 commit comments

Comments
 (0)