mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-24 18:03:43 +03:00
Fix representation of sql.Placeholder
Fix also Placeholder tests, including an error which made an assert always true, which made us miss the regression in #1291.
This commit is contained in:
parent
2df79c5a5f
commit
b241def64b
|
@ -438,7 +438,10 @@ class Placeholder(Composable):
|
|||
return self._wrapped
|
||||
|
||||
def __repr__(self):
|
||||
return f"Placeholder({self._wrapped if self._wrapped is not None else ''!r})"
|
||||
if self._wrapped is None:
|
||||
return f"{self.__class__.__name__}()"
|
||||
else:
|
||||
return f"{self.__class__.__name__}({self._wrapped!r})"
|
||||
|
||||
def as_string(self, context):
|
||||
if self._wrapped is not None:
|
||||
|
|
|
@ -373,29 +373,25 @@ class PlaceholderTest(ConnectingTestCase):
|
|||
self.assertEqual(sql.Placeholder('foo').name, 'foo')
|
||||
|
||||
def test_repr(self):
|
||||
self.assert_(str(sql.Placeholder()), 'Placeholder()')
|
||||
self.assert_(repr(sql.Placeholder()), 'Placeholder()')
|
||||
self.assert_(sql.Placeholder().as_string(self.conn), '%s')
|
||||
self.assertEqual(str(sql.Placeholder()), 'Placeholder()')
|
||||
self.assertEqual(repr(sql.Placeholder()), 'Placeholder()')
|
||||
self.assertEqual(sql.Placeholder().as_string(self.conn), '%s')
|
||||
|
||||
def test_repr_name(self):
|
||||
self.assert_(str(sql.Placeholder('foo')), "Placeholder('foo')")
|
||||
self.assert_(repr(sql.Placeholder('foo')), "Placeholder('foo')")
|
||||
self.assert_(sql.Placeholder('foo').as_string(self.conn), '%(foo)s')
|
||||
self.assertEqual(str(sql.Placeholder('foo')), "Placeholder('foo')")
|
||||
self.assertEqual(repr(sql.Placeholder('foo')), "Placeholder('foo')")
|
||||
self.assertEqual(sql.Placeholder('foo').as_string(self.conn), '%(foo)s')
|
||||
|
||||
def test_bad_name(self):
|
||||
self.assertRaises(ValueError, sql.Placeholder, ')')
|
||||
|
||||
def test_eq(self):
|
||||
self.assert_(sql.Placeholder('foo') == sql.Placeholder('foo'))
|
||||
self.assert_(sql.Placeholder('foo') != sql.Placeholder('bar'))
|
||||
self.assert_(sql.Placeholder('foo') != 'foo')
|
||||
self.assert_(sql.Placeholder() == sql.Placeholder())
|
||||
self.assert_(sql.Placeholder('foo') != sql.Placeholder())
|
||||
self.assert_(sql.Placeholder('foo') != sql.Literal('foo'))
|
||||
|
||||
def test_as_string(self):
|
||||
self.assertEqual(sql.Placeholder().as_string(self.conn), "%s")
|
||||
self.assertEqual(sql.Placeholder('foo').as_string(self.conn), "%(foo)s")
|
||||
self.assertEqual(sql.Placeholder('foo'), sql.Placeholder('foo'))
|
||||
self.assertNotEqual(sql.Placeholder('foo'), sql.Placeholder('bar'))
|
||||
self.assertNotEqual(sql.Placeholder('foo'), 'foo')
|
||||
self.assertEqual(sql.Placeholder(), sql.Placeholder())
|
||||
self.assertNotEqual(sql.Placeholder('foo'), sql.Placeholder())
|
||||
self.assertNotEqual(sql.Placeholder('foo'), sql.Literal('foo'))
|
||||
|
||||
|
||||
class ValuesTest(ConnectingTestCase):
|
||||
|
|
Loading…
Reference in New Issue
Block a user