Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7066445
D1955.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Subscribers
None
D1955.id.diff
View Options
diff --git a/swh/storage/tests/test_storage.py b/swh/storage/tests/test_storage.py
--- a/swh/storage/tests/test_storage.py
+++ b/swh/storage/tests/test_storage.py
@@ -11,7 +11,7 @@
from collections import defaultdict
from unittest.mock import Mock, patch
-import psycopg2.errors
+import psycopg2
import pytest
from hypothesis import given, strategies, settings, HealthCheck
@@ -604,10 +604,13 @@
self.storage.content_add([{**cont, 'length': -2}])
with self.assertRaisesRegex(
- (ValueError, psycopg2.errors.NotNullViolation),
- "reason"):
+ (ValueError, psycopg2.IntegrityError), 'reason') as cm:
self.storage.content_add([{**cont, 'status': 'absent'}])
+ if type(cm.exception) == psycopg2.IntegrityError:
+ self.assertEqual(cm.exception.pgcode,
+ psycopg2.errorcodes.NOT_NULL_VIOLATION)
+
with self.assertRaisesRegex(
ValueError,
"^Must not provide a reason if content is not absent.$"):
@@ -1018,9 +1021,13 @@
del dir_['entries'][0]['target']
with self.assertRaisesRegex(
- (TypeError, psycopg2.errors.NotNullViolation), 'target'):
+ (TypeError, psycopg2.IntegrityError), 'target') as cm:
self.storage.directory_add([dir_])
+ if type(cm.exception) == psycopg2.IntegrityError:
+ self.assertEqual(cm.exception.pgcode,
+ psycopg2.errorcodes.NOT_NULL_VIOLATION)
+
def test_directory_get_recursive(self):
init_missing = list(self.storage.directory_missing([self.dir['id']]))
self.assertEqual([self.dir['id']], init_missing)
@@ -1178,26 +1185,35 @@
rev['date']['offset'] = 2**16
with self.assertRaisesRegex(
- (ValueError, psycopg2.errors.NumericValueOutOfRange),
- 'offset'):
+ (ValueError, psycopg2.DataError), 'offset') as cm:
self.storage.revision_add([rev])
+ if type(cm.exception) == psycopg2.DataError:
+ self.assertEqual(cm.exception.pgcode,
+ psycopg2.errorcodes.NUMERIC_VALUE_OUT_OF_RANGE)
+
rev = copy.deepcopy(self.revision)
rev['committer_date']['offset'] = 2**16
with self.assertRaisesRegex(
- (ValueError, psycopg2.errors.NumericValueOutOfRange),
- 'offset'):
+ (ValueError, psycopg2.DataError), 'offset') as cm:
self.storage.revision_add([rev])
+ if type(cm.exception) == psycopg2.DataError:
+ self.assertEqual(cm.exception.pgcode,
+ psycopg2.errorcodes.NUMERIC_VALUE_OUT_OF_RANGE)
+
rev = copy.deepcopy(self.revision)
rev['type'] = 'foobar'
with self.assertRaisesRegex(
- (ValueError, psycopg2.errors.InvalidTextRepresentation),
- '(?i)type'):
+ (ValueError, psycopg2.DataError), '(?i)type') as cm:
self.storage.revision_add([rev])
+ if type(cm.exception) == psycopg2.DataError:
+ self.assertEqual(cm.exception.pgcode,
+ psycopg2.errorcodes.INVALID_TEXT_REPRESENTATION)
+
def test_revision_add_name_clash(self):
revision1 = self.revision.copy()
revision2 = self.revision2.copy()
@@ -1360,18 +1376,24 @@
rel['date']['offset'] = 2**16
with self.assertRaisesRegex(
- (ValueError, psycopg2.errors.NumericValueOutOfRange),
- 'offset'):
+ (ValueError, psycopg2.DataError), 'offset') as cm:
self.storage.release_add([rel])
+ if type(cm.exception) == psycopg2.DataError:
+ self.assertEqual(cm.exception.pgcode,
+ psycopg2.errorcodes.NUMERIC_VALUE_OUT_OF_RANGE)
+
rel = copy.deepcopy(self.release)
rel['author'] = None
with self.assertRaisesRegex(
- (ValueError, psycopg2.errors.CheckViolation),
- 'date'):
+ (ValueError, psycopg2.IntegrityError), 'date') as cm:
self.storage.release_add([rel])
+ if type(cm.exception) == psycopg2.IntegrityError:
+ self.assertEqual(cm.exception.pgcode,
+ psycopg2.errorcodes.CHECK_VIOLATION)
+
def test_release_add_name_clash(self):
release1 = self.release.copy()
release2 = self.release2.copy()
@@ -1772,9 +1794,13 @@
def test_origin_visit_add_validation(self):
origin_id_or_url = self.storage.origin_add_one(self.origin2)
- with self.assertRaises((TypeError, psycopg2.errors.UndefinedFunction)):
+ with self.assertRaises((TypeError, psycopg2.ProgrammingError)) as cm:
self.storage.origin_visit_add(origin_id_or_url, date=[b'foo'])
+ if type(cm.exception) == psycopg2.ProgrammingError:
+ self.assertEqual(cm.exception.pgcode,
+ psycopg2.errorcodes.UNDEFINED_FUNCTION)
+
@given(strategies.booleans())
def test_origin_visit_update(self, use_url):
if not self._test_origin_ids and not use_url:
@@ -1937,12 +1963,15 @@
origin_id,
date=self.date_visit2)
- with self.assertRaisesRegexp(
- (ValueError, psycopg2.errors.InvalidTextRepresentation),
- 'status'):
+ with self.assertRaisesRegex(
+ (ValueError, psycopg2.DataError), 'status') as cm:
self.storage.origin_visit_update(
origin_id, visit['visit'], status='foobar')
+ if type(cm.exception) == psycopg2.DataError:
+ self.assertEqual(cm.exception.pgcode,
+ psycopg2.errorcodes.INVALID_TEXT_REPRESENTATION)
+
def test_origin_visit_find_by_date(self):
# given
self.storage.origin_add_one(self.origin)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Nov 5 2024, 9:30 AM (11 w, 17 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3216304
Attached To
D1955: tests/test_storage: Fix tests execution with psycopg2 < 2.8
Event Timeline
Log In to Comment