184
184
expr = Like(elem1, elem2, elem3, False)
185
185
self.assertEquals(expr.case_sensitive, False)
187
def test_startswith(self):
189
self.assertRaises(ExprError, expr.startswith, "not a unicode string")
191
like_expr = expr.startswith(u"abc!!_%")
192
self.assertTrue(isinstance(like_expr, Like))
193
self.assertTrue(like_expr.expr1 is expr)
194
self.assertEquals(like_expr.expr2, u"abc!!!!!_!%%")
195
self.assertEquals(like_expr.escape, u"!")
197
def test_endswith(self):
199
self.assertRaises(ExprError, expr.startswith, "not a unicode string")
201
like_expr = expr.endswith(u"abc!!_%")
202
self.assertTrue(isinstance(like_expr, Like))
203
self.assertTrue(like_expr.expr1 is expr)
204
self.assertEquals(like_expr.expr2, u"%abc!!!!!_!%")
205
self.assertEquals(like_expr.escape, u"!")
207
def test_contains_string(self):
210
ExprError, expr.contains_string, "not a unicode string")
212
like_expr = expr.contains_string(u"abc!!_%")
213
self.assertTrue(isinstance(like_expr, Like))
214
self.assertTrue(like_expr.expr1 is expr)
215
self.assertEquals(like_expr.expr2, u"%abc!!!!!_!%%")
216
self.assertEquals(like_expr.escape, u"!")
187
218
def test_eq(self):
188
219
expr = Eq(elem1, elem2)
189
220
self.assertEquals(expr.expr1, elem1)
275
306
self.assertEquals(expr.limit, 1)
276
307
self.assertEquals(expr.offset, 2)
309
def test_union_collapse(self):
310
expr = Union(Union(elem1, elem2), elem3)
311
self.assertEquals(expr.exprs, (elem1, elem2, elem3))
313
# Only first expression is collapsed.
314
expr = Union(elem1, Union(elem2, elem3))
315
self.assertEquals(expr.exprs[0], elem1)
316
self.assertTrue(isinstance(expr.exprs[1], Union))
318
# Don't collapse if all is different.
319
expr = Union(Union(elem1, elem2, all=True), elem3)
320
self.assertTrue(isinstance(expr.exprs[0], Union))
321
expr = Union(Union(elem1, elem2), elem3, all=True)
322
self.assertTrue(isinstance(expr.exprs[0], Union))
323
expr = Union(Union(elem1, elem2, all=True), elem3, all=True)
324
self.assertEquals(expr.exprs, (elem1, elem2, elem3))
326
# Don't collapse if limit or offset are set.
327
expr = Union(Union(elem1, elem2, limit=1), elem3)
328
self.assertTrue(isinstance(expr.exprs[0], Union))
329
expr = Union(Union(elem1, elem2, offset=3), elem3)
330
self.assertTrue(isinstance(expr.exprs[0], Union))
332
# Don't collapse other set expressions.
333
expr = Union(Except(elem1, elem2), elem3)
334
self.assertTrue(isinstance(expr.exprs[0], Except))
335
expr = Union(Intersect(elem1, elem2), elem3)
336
self.assertTrue(isinstance(expr.exprs[0], Intersect))
278
338
def test_except(self):
279
339
expr = Except(elem1, elem2, elem3)
280
340
self.assertEquals(expr.exprs, (elem1, elem2, elem3))
287
347
self.assertEquals(expr.limit, 1)
288
348
self.assertEquals(expr.offset, 2)
350
def test_except_collapse(self):
351
expr = Except(Except(elem1, elem2), elem3)
352
self.assertEquals(expr.exprs, (elem1, elem2, elem3))
354
# Only first expression is collapsed.
355
expr = Except(elem1, Except(elem2, elem3))
356
self.assertEquals(expr.exprs[0], elem1)
357
self.assertTrue(isinstance(expr.exprs[1], Except))
359
# Don't collapse if all is different.
360
expr = Except(Except(elem1, elem2, all=True), elem3)
361
self.assertTrue(isinstance(expr.exprs[0], Except))
362
expr = Except(Except(elem1, elem2), elem3, all=True)
363
self.assertTrue(isinstance(expr.exprs[0], Except))
364
expr = Except(Except(elem1, elem2, all=True), elem3, all=True)
365
self.assertEquals(expr.exprs, (elem1, elem2, elem3))
367
# Don't collapse if limit or offset are set.
368
expr = Except(Except(elem1, elem2, limit=1), elem3)
369
self.assertTrue(isinstance(expr.exprs[0], Except))
370
expr = Except(Except(elem1, elem2, offset=3), elem3)
371
self.assertTrue(isinstance(expr.exprs[0], Except))
373
# Don't collapse other set expressions.
374
expr = Except(Union(elem1, elem2), elem3)
375
self.assertTrue(isinstance(expr.exprs[0], Union))
376
expr = Except(Intersect(elem1, elem2), elem3)
377
self.assertTrue(isinstance(expr.exprs[0], Intersect))
290
379
def test_intersect(self):
291
380
expr = Intersect(elem1, elem2, elem3)
292
381
self.assertEquals(expr.exprs, (elem1, elem2, elem3))
300
389
self.assertEquals(expr.limit, 1)
301
390
self.assertEquals(expr.offset, 2)
392
def test_intersect_collapse(self):
393
expr = Intersect(Intersect(elem1, elem2), elem3)
394
self.assertEquals(expr.exprs, (elem1, elem2, elem3))
396
# Only first expression is collapsed.
397
expr = Intersect(elem1, Intersect(elem2, elem3))
398
self.assertEquals(expr.exprs[0], elem1)
399
self.assertTrue(isinstance(expr.exprs[1], Intersect))
401
# Don't collapse if all is different.
402
expr = Intersect(Intersect(elem1, elem2, all=True), elem3)
403
self.assertTrue(isinstance(expr.exprs[0], Intersect))
404
expr = Intersect(Intersect(elem1, elem2), elem3, all=True)
405
self.assertTrue(isinstance(expr.exprs[0], Intersect))
406
expr = Intersect(Intersect(elem1, elem2, all=True), elem3, all=True)
407
self.assertEquals(expr.exprs, (elem1, elem2, elem3))
409
# Don't collapse if limit or offset are set.
410
expr = Intersect(Intersect(elem1, elem2, limit=1), elem3)
411
self.assertTrue(isinstance(expr.exprs[0], Intersect))
412
expr = Intersect(Intersect(elem1, elem2, offset=3), elem3)
413
self.assertTrue(isinstance(expr.exprs[0], Intersect))
415
# Don't collapse other set expressions.
416
expr = Intersect(Union(elem1, elem2), elem3)
417
self.assertTrue(isinstance(expr.exprs[0], Union))
418
expr = Intersect(Except(elem1, elem2), elem3)
419
self.assertTrue(isinstance(expr.exprs[0], Except))
303
421
def test_auto_tables(self):
304
422
expr = AutoTables(elem1, [elem2])
305
423
self.assertEquals(expr.expr, elem1)