Skip to content

Commit

Permalink
Raise RuntimeError when try to use with ... not async with... (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardtack authored and nhumrich committed Feb 13, 2018
1 parent e0e2fbe commit 06e5c7b
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion asyncpgsa/pgsingleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __init__(self, pool, query, args=None,
self._con = None

def __enter__(self):
raise SyntaxError('Must use "async with"')
raise RuntimeError('Must use "async with"')

def __exit__(self, exc_type, exc_val, exc_tb):
pass
Expand Down
2 changes: 1 addition & 1 deletion asyncpgsa/testing/mockpgsingleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, connection, query, args=None):
self.cursor = None

def __enter__(self):
raise SyntaxError('Must use "async with"')
raise RuntimeError('Must use "async with"')

def __exit__(self, exc_type, exc_val, exc_tb):
pass
Expand Down
2 changes: 1 addition & 1 deletion asyncpgsa/testing/mocktransactionmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def __init__(self, pool, connection):
self.connection = connection

def __enter__(self):
raise SyntaxError('Must use "async with" for a transaction')
raise RuntimeError('Must use "async with" for a transaction')

def __exit__(self, exc_type, exc_val, exc_tb):
pass
Expand Down
2 changes: 1 addition & 1 deletion asyncpgsa/transactionmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, pool, timeout=None, **kwargs):
self.trans_kwargs = kwargs

def __enter__(self):
raise SyntaxError('Must use "async with" for a transaction')
raise RuntimeError('Must use "async with" for a transaction')

def __exit__(self, exc_type, exc_val, exc_tb):
pass
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pgsingleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def test_pg_query_async_with_statement():
async def test_pg_query_with_bad_with_statement():
ps = pg.query(query)

with pytest.raises(SyntaxError) as exc_info:
with pytest.raises(RuntimeError) as exc_info:
with ps as cursor:
async for row in cursor:
assert row['a'] == 4.0
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ async def test_with_without_async_should_throw_exception(pool):
with pool.transaction() as conn:
result = await conn.fetch('SELECT * FROM sqrt(16)')

raise Exception('Should have thrown SyntaxError')
except SyntaxError as e:
raise Exception('Should have thrown RuntimeError')
except RuntimeError as e:
assert str(e) == 'Must use "async with" for a transaction'

async def test_falsyness_of_rows_on_fetch(pool):
Expand Down

0 comments on commit 06e5c7b

Please sign in to comment.