[PATCH 1 of 9 postgis] Fix tests with psycopg2 >= 2.8

Philippe Pepiot philippe.pepiot at logilab.fr
Thu Jun 27 16:56:39 CEST 2019


# HG changeset patch
# User Philippe Pepiot <philippe.pepiot at logilab.fr>
# Date 1561644449 -7200
#      Thu Jun 27 16:07:29 2019 +0200
# Node ID e2ab9ba928697a80ae52bf448ff3e697467b9e83
# Parent  f9d9de9ae834a6014336ee1d13cd3adb375a0846
# Available At https://hg.logilab.org/review/cubes/postgis
#              hg pull https://hg.logilab.org/review/cubes/postgis -r e2ab9ba92869
Fix tests with psycopg2 >= 2.8

Since 2.8, psycopg2 errors have been extended to support all postgresql
specifics errors:
http://initd.org/psycopg/docs/news.html#what-s-new-in-psycopg-2-8

Keep backward compatibility of tests with psycopg2<2.8 since we may want to run tests (e.g. debian packages) with older psycopg2.

diff --git a/test/test_postgis.py b/test/test_postgis.py
--- a/test/test_postgis.py
+++ b/test/test_postgis.py
@@ -41,7 +41,9 @@ class PostgisTC(testlib.CubicWebTC):
             # wrong srid
             with self.assertRaises(Exception) as ctx:
                 cnx.create_entity('City', name=u'Nantes', center_4326=(u'POINT(1.5 47.25)', -1))
-            self.assertEqual(ctx.exception.__class__.__name__, 'DataError')
+            # psycopg2 < 2.8 raises DataError
+            # psycopg2 >= 2.8 raises InvalidParameterValue
+            self.assertIn(ctx.exception.__class__.__name__, ('DataError', 'InvalidParameterValue'))
 
     def test_geometry_nosrid(self):
         with self.admin_access.repo_cnx() as cnx:



More information about the cubicweb-devel mailing list