275
275
self.assertEquals(expr.limit, 1)
276
276
self.assertEquals(expr.offset, 2)
278
def test_union_collapse(self):
279
expr = Union(Union(elem1, elem2), elem3)
280
self.assertEquals(expr.exprs, (elem1, elem2, elem3))
282
# Only first expression is collapsed.
283
expr = Union(elem1, Union(elem2, elem3))
284
self.assertEquals(expr.exprs[0], elem1)
285
self.assertTrue(isinstance(expr.exprs[1], Union))
287
# Don't collapse if all is different.
288
expr = Union(Union(elem1, elem2, all=True), elem3)
289
self.assertTrue(isinstance(expr.exprs[0], Union))
290
expr = Union(Union(elem1, elem2), elem3, all=True)
291
self.assertTrue(isinstance(expr.exprs[0], Union))
292
expr = Union(Union(elem1, elem2, all=True), elem3, all=True)
293
self.assertEquals(expr.exprs, (elem1, elem2, elem3))
295
# Don't collapse if limit or offset are set.
296
expr = Union(Union(elem1, elem2, limit=1), elem3)
297
self.assertTrue(isinstance(expr.exprs[0], Union))
298
expr = Union(Union(elem1, elem2, offset=3), elem3)
299
self.assertTrue(isinstance(expr.exprs[0], Union))
301
# Don't collapse other set expressions.
302
expr = Union(Except(elem1, elem2), elem3)
303
self.assertTrue(isinstance(expr.exprs[0], Except))
304
expr = Union(Intersect(elem1, elem2), elem3)
305
self.assertTrue(isinstance(expr.exprs[0], Intersect))
278
307
def test_except(self):
279
308
expr = Except(elem1, elem2, elem3)
280
309
self.assertEquals(expr.exprs, (elem1, elem2, elem3))
287
316
self.assertEquals(expr.limit, 1)
288
317
self.assertEquals(expr.offset, 2)
319
def test_except_collapse(self):
320
expr = Except(Except(elem1, elem2), elem3)
321
self.assertEquals(expr.exprs, (elem1, elem2, elem3))
323
# Only first expression is collapsed.
324
expr = Except(elem1, Except(elem2, elem3))
325
self.assertEquals(expr.exprs[0], elem1)
326
self.assertTrue(isinstance(expr.exprs[1], Except))
328
# Don't collapse if all is different.
329
expr = Except(Except(elem1, elem2, all=True), elem3)
330
self.assertTrue(isinstance(expr.exprs[0], Except))
331
expr = Except(Except(elem1, elem2), elem3, all=True)
332
self.assertTrue(isinstance(expr.exprs[0], Except))
333
expr = Except(Except(elem1, elem2, all=True), elem3, all=True)
334
self.assertEquals(expr.exprs, (elem1, elem2, elem3))
336
# Don't collapse if limit or offset are set.
337
expr = Except(Except(elem1, elem2, limit=1), elem3)
338
self.assertTrue(isinstance(expr.exprs[0], Except))
339
expr = Except(Except(elem1, elem2, offset=3), elem3)
340
self.assertTrue(isinstance(expr.exprs[0], Except))
342
# Don't collapse other set expressions.
343
expr = Except(Union(elem1, elem2), elem3)
344
self.assertTrue(isinstance(expr.exprs[0], Union))
345
expr = Except(Intersect(elem1, elem2), elem3)
346
self.assertTrue(isinstance(expr.exprs[0], Intersect))
290
348
def test_intersect(self):
291
349
expr = Intersect(elem1, elem2, elem3)
292
350
self.assertEquals(expr.exprs, (elem1, elem2, elem3))
300
358
self.assertEquals(expr.limit, 1)
301
359
self.assertEquals(expr.offset, 2)
361
def test_intersect_collapse(self):
362
expr = Intersect(Intersect(elem1, elem2), elem3)
363
self.assertEquals(expr.exprs, (elem1, elem2, elem3))
365
# Only first expression is collapsed.
366
expr = Intersect(elem1, Intersect(elem2, elem3))
367
self.assertEquals(expr.exprs[0], elem1)
368
self.assertTrue(isinstance(expr.exprs[1], Intersect))
370
# Don't collapse if all is different.
371
expr = Intersect(Intersect(elem1, elem2, all=True), elem3)
372
self.assertTrue(isinstance(expr.exprs[0], Intersect))
373
expr = Intersect(Intersect(elem1, elem2), elem3, all=True)
374
self.assertTrue(isinstance(expr.exprs[0], Intersect))
375
expr = Intersect(Intersect(elem1, elem2, all=True), elem3, all=True)
376
self.assertEquals(expr.exprs, (elem1, elem2, elem3))
378
# Don't collapse if limit or offset are set.
379
expr = Intersect(Intersect(elem1, elem2, limit=1), elem3)
380
self.assertTrue(isinstance(expr.exprs[0], Intersect))
381
expr = Intersect(Intersect(elem1, elem2, offset=3), elem3)
382
self.assertTrue(isinstance(expr.exprs[0], Intersect))
384
# Don't collapse other set expressions.
385
expr = Intersect(Union(elem1, elem2), elem3)
386
self.assertTrue(isinstance(expr.exprs[0], Union))
387
expr = Intersect(Except(elem1, elem2), elem3)
388
self.assertTrue(isinstance(expr.exprs[0], Except))
303
390
def test_auto_tables(self):
304
391
expr = AutoTables(elem1, [elem2])
305
392
self.assertEquals(expr.expr, elem1)