@@ -23,12 +23,28 @@ def test_exceptions_exported(self):
23
23
self .assertIsNone (asyncpg .PostgresError .schema_name )
24
24
25
25
async def test_exceptions_unpacking (self ):
26
- with self .assertRaises (asyncpg .UndefinedTableError ):
27
- try :
28
- await self .con .execute ('SELECT * FROM _nonexistent_' )
29
- except asyncpg .UndefinedTableError as e :
30
- self .assertEqual (e .sqlstate , '42P01' )
31
- self .assertEqual (e .position , '15' )
32
- self .assertEqual (e .query , 'SELECT * FROM _nonexistent_' )
33
- self .assertIsNotNone (e .severity )
34
- raise
26
+ try :
27
+ await self .con .execute ('SELECT * FROM _nonexistent_' )
28
+ except asyncpg .UndefinedTableError as e :
29
+ self .assertEqual (e .sqlstate , '42P01' )
30
+ self .assertEqual (e .position , '15' )
31
+ self .assertEqual (e .query , 'SELECT * FROM _nonexistent_' )
32
+ self .assertIsNotNone (e .severity )
33
+ else :
34
+ self .fail ('UndefinedTableError not raised' )
35
+
36
+ async def test_exceptions_str (self ):
37
+ try :
38
+ await self .con .execute ('''
39
+ CREATE FUNCTION foo() RETURNS bool AS $$ $$ LANGUAGE SQL;
40
+ ''' )
41
+ except asyncpg .InvalidFunctionDefinitionError as e :
42
+ self .assertEqual (
43
+ e .detail ,
44
+ "Function's final statement must be SELECT or "
45
+ "INSERT/UPDATE/DELETE RETURNING." )
46
+ self .assertIn (
47
+ 'DETAIL: Function' , str (e )
48
+ )
49
+ else :
50
+ self .fail ('InvalidFunctionDefinitionError not raised' )
0 commit comments