OLD | NEW |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 # | 2 # |
3 # Copyright (c) 2011-2013, Cédric Krier | 3 # Copyright (c) 2011-2013, Cédric Krier |
4 # Copyright (c) 2011-2013, B2CK | 4 # Copyright (c) 2011-2013, B2CK |
5 # All rights reserved. | 5 # All rights reserved. |
6 # | 6 # |
7 # Redistribution and use in source and binary forms, with or without | 7 # Redistribution and use in source and binary forms, with or without |
8 # modification, are permitted provided that the following conditions are met: | 8 # modification, are permitted provided that the following conditions are met: |
9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
11 # * Redistributions in binary form must reproduce the above copyright | 11 # * Redistributions in binary form must reproduce the above copyright |
12 # notice, this list of conditions and the following disclaimer in the | 12 # notice, this list of conditions and the following disclaimer in the |
13 # documentation and/or other materials provided with the distribution. | 13 # documentation and/or other materials provided with the distribution. |
14 # * Neither the name of the <organization> nor the | 14 # * Neither the name of the <organization> nor the |
15 # names of its contributors may be used to endorse or promote products | 15 # names of its contributors may be used to endorse or promote products |
16 # derived from this software without specific prior written permission. | 16 # derived from this software without specific prior written permission. |
17 # | 17 # |
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 19 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 # ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY | 21 # ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY |
22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
23 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 23 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
24 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 24 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
25 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
27 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 |
29 import unittest | 29 import unittest |
| 30 import warnings |
30 from array import array | 31 from array import array |
31 | 32 |
32 from sql import Table, Literal | 33 from sql import Table, Literal |
33 from sql.operators import And, Not, Less, Equal, NotEqual, In | 34 from sql.operators import And, Not, Less, Equal, NotEqual, In, FloorDiv |
34 | 35 |
35 | 36 |
36 class TestOperators(unittest.TestCase): | 37 class TestOperators(unittest.TestCase): |
37 table = Table('t') | 38 table = Table('t') |
38 | 39 |
39 def test_and(self): | 40 def test_and(self): |
40 and_ = And((self.table.c1, self.table.c2)) | 41 and_ = And((self.table.c1, self.table.c2)) |
41 self.assertEqual(str(and_), '("c1" AND "c2")') | 42 self.assertEqual(str(and_), '("c1" AND "c2")') |
42 self.assertEqual(and_.params, ()) | 43 self.assertEqual(and_.params, ()) |
43 | 44 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 in_ = In(self.table.c1, t2.select(t2.c2) | t2.select(t2.c3)) | 116 in_ = In(self.table.c1, t2.select(t2.c2) | t2.select(t2.c3)) |
116 self.assertEqual(str(in_), | 117 self.assertEqual(str(in_), |
117 '("c1" IN (SELECT "a"."c2" FROM "t2" AS "a" ' | 118 '("c1" IN (SELECT "a"."c2" FROM "t2" AS "a" ' |
118 'UNION SELECT "a"."c3" FROM "t2" AS "a"))') | 119 'UNION SELECT "a"."c3" FROM "t2" AS "a"))') |
119 self.assertEqual(in_.params, ()) | 120 self.assertEqual(in_.params, ()) |
120 | 121 |
121 in_ = In(self.table.c1, array('l', range(10))) | 122 in_ = In(self.table.c1, array('l', range(10))) |
122 self.assertEqual(str(in_), | 123 self.assertEqual(str(in_), |
123 '("c1" IN (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s))') | 124 '("c1" IN (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s))') |
124 self.assertEqual(in_.params, tuple(range(10))) | 125 self.assertEqual(in_.params, tuple(range(10))) |
| 126 |
| 127 def test_floordiv(self): |
| 128 with warnings.catch_warnings(record=True) as w: |
| 129 warnings.simplefilter("always") |
| 130 FloorDiv(4, 2) |
| 131 self.assertEqual(len(w), 1) |
| 132 self.assertTrue(issubclass(w[-1].category, DeprecationWarning)) |
| 133 self.assertIn('FloorDiv operator is deprecated, use Div function', |
| 134 str(w[-1].message)) |
OLD | NEW |