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_execute(self): cur = self.conn.cursor() cur.execute(""" create table test_compose ( id serial primary key, foo text, bar text, "ba'z" text) """) cur.execute( sql.SQL("insert into {0} (id, {1}) values (%s, {2})").format( sql.Identifier('test_compose'), sql.SQL(', ').join(map(sql.Identifier, ['foo', 'bar', "ba'z"])), (sql.Placeholder() * 3).join(', ')), (10, 'a', 'b', 'c')) cur.execute("select * from test_compose") self.assertEqual(cur.fetchall(), [(10, 'a', 'b', 'c')])
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')
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')
def test_name(self): self.assertEqual(sql.Placeholder().name, None) self.assertEqual(sql.Placeholder('foo').name, 'foo')