mirror of
				https://github.com/psycopg/psycopg2.git
				synced 2025-10-30 15:27:28 +03:00 
			
		
		
		
	more useful error message when comparing ranges with non-ranges
This commit is contained in:
		
							parent
							
								
									bbe0bf955c
								
							
						
					
					
						commit
						8bb44f3444
					
				|  | @ -121,6 +121,8 @@ class Range(object): | ||||||
|         return self._bounds is not None |         return self._bounds is not None | ||||||
| 
 | 
 | ||||||
|     def __eq__(self, other): |     def __eq__(self, other): | ||||||
|  |         if not isinstance(other, self.__class__): | ||||||
|  |             raise TypeError('Cannot compare %r with %r' % (self, other)) | ||||||
|         return (self._lower == other._lower |         return (self._lower == other._lower | ||||||
|             and self._upper == other._upper |             and self._upper == other._upper | ||||||
|             and self._bounds == other._bounds) |             and self._bounds == other._bounds) | ||||||
|  |  | ||||||
|  | @ -1212,6 +1212,16 @@ class RangeTestCase(unittest.TestCase): | ||||||
|         assert_not_equal(Range(10, 20), Range(11, 20)) |         assert_not_equal(Range(10, 20), Range(11, 20)) | ||||||
|         assert_not_equal(Range(10, 20, '[)'), Range(10, 20, '[]')) |         assert_not_equal(Range(10, 20, '[)'), Range(10, 20, '[]')) | ||||||
| 
 | 
 | ||||||
|  |     def test_eq_wrong_type(self): | ||||||
|  |         from psycopg2.extras import Range | ||||||
|  |         try: | ||||||
|  |             Range(10, 20)==() | ||||||
|  |         except TypeError, e: | ||||||
|  |             self.assertEqual( | ||||||
|  |                 str(e), "Cannot compare Range(10, 20, '[)') with ()") | ||||||
|  |         else: | ||||||
|  |             self.fail('No exception raised') | ||||||
|  | 
 | ||||||
|     def test_not_ordered(self): |     def test_not_ordered(self): | ||||||
|         from psycopg2.extras import Range |         from psycopg2.extras import Range | ||||||
|         self.assertRaises(TypeError, lambda: Range(empty=True) < Range(0,4)) |         self.assertRaises(TypeError, lambda: Range(empty=True) < Range(0,4)) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user