예제 #1
0
    def test_sum_inplace(self):
        obj = sql.Composed([sql.SQL("foo ")])
        obj += sql.Literal("bar")
        self.assert_(isinstance(obj, sql.Composed))
        self.assertQuotedEqual(obj.as_string(self.conn), "foo 'bar'")

        obj = sql.Composed([sql.SQL("foo ")])
        obj += sql.Composed([sql.Literal("bar")])
        self.assert_(isinstance(obj, sql.Composed))
        self.assertQuotedEqual(obj.as_string(self.conn), "foo 'bar'")
예제 #2
0
 def test_iter(self):
     obj = sql.Composed([sql.SQL("foo"), sql.SQL('bar')])
     it = iter(obj)
     i = next(it)
     self.assertEqual(i, sql.SQL('foo'))
     i = next(it)
     self.assertEqual(i, sql.SQL('bar'))
     self.assertRaises(StopIteration, next, it)
예제 #3
0
    def test_join(self):
        obj = sql.SQL(", ").join(
            [sql.Identifier('foo'),
             sql.SQL('bar'),
             sql.Literal(42)])
        self.assert_(isinstance(obj, sql.Composed))
        self.assertEqual(obj.as_string(self.conn), '"foo", bar, 42')

        obj = sql.SQL(", ").join(
            sql.Composed(
                [sql.Identifier('foo'),
                 sql.SQL('bar'),
                 sql.Literal(42)]))
        self.assert_(isinstance(obj, sql.Composed))
        self.assertEqual(obj.as_string(self.conn), '"foo", bar, 42')

        obj = sql.SQL(", ").join([])
        self.assertEqual(obj, sql.Composed([]))
예제 #4
0
 def test_join(self):
     obj = sql.Composed([sql.Literal("foo"), sql.Identifier("b'ar")])
     obj = obj.join(", ")
     self.assert_(isinstance(obj, sql.Composed))
     self.assertQuotedEqual(obj.as_string(self.conn), "'foo', \"b'ar\"")
예제 #5
0
 def test_eq(self):
     l = [sql.Literal("foo"), sql.Identifier("b'ar")]
     l2 = [sql.Literal("foo"), sql.Literal("b'ar")]
     self.assert_(sql.Composed(l) == sql.Composed(list(l)))
     self.assert_(sql.Composed(l) != l)
     self.assert_(sql.Composed(l) != sql.Composed(l2))
예제 #6
0
 def test_seq(self):
     l = [sql.SQL('foo'), sql.Literal('bar'), sql.Identifier('baz')]
     self.assertEqual(sql.Composed(l).seq, l)
예제 #7
0
 def test_repr(self):
     obj = sql.Composed([sql.Literal("foo"), sql.Identifier("b'ar")])
     self.assertEqual(repr(obj),
                      """Composed([Literal('foo'), Identifier("b'ar")])""")
     self.assertEqual(str(obj), repr(obj))