python-sql 1.5.1__py3-none-any.whl → 1.5.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sql/tests/test_merge.py CHANGED
@@ -4,8 +4,8 @@
4
4
  import unittest
5
5
 
6
6
  from sql import (
7
- Matched, MatchedDelete, MatchedUpdate, NotMatched, NotMatchedInsert, Table,
8
- With)
7
+ Literal, Matched, MatchedDelete, MatchedUpdate, Merge, NotMatched,
8
+ NotMatchedInsert, Table, With)
9
9
 
10
10
 
11
11
  class TestMerge(unittest.TestCase):
@@ -22,6 +22,22 @@ class TestMerge(unittest.TestCase):
22
22
  'WHEN MATCHED THEN DO NOTHING')
23
23
  self.assertEqual(query.params, ())
24
24
 
25
+ def test_merge_invalid_target(self):
26
+ with self.assertRaises(ValueError):
27
+ Merge('foo', self.source, Literal(True))
28
+
29
+ def test_merge_invalid_source(self):
30
+ with self.assertRaises(ValueError):
31
+ self.target.merge('foo', Literal(True))
32
+
33
+ def test_merge_invalid_condition(self):
34
+ with self.assertRaises(ValueError):
35
+ self.target.merge(self.source, 'foo')
36
+
37
+ def test_merge_invalid_whens(self):
38
+ with self.assertRaises(ValueError):
39
+ self.target.merge(self.source, Literal(True), 'foo')
40
+
25
41
  def test_condition(self):
26
42
  query = self.target.merge(
27
43
  self.source,
@@ -51,14 +67,16 @@ class TestMerge(unittest.TestCase):
51
67
  def test_matched_update(self):
52
68
  query = self.target.merge(
53
69
  self.source, self.target.c1 == self.source.c2,
54
- MatchedUpdate([self.target.c1], [self.target.c1 + self.source.c2]))
70
+ MatchedUpdate(
71
+ [self.target.c1, self.target.c2],
72
+ [self.target.c1 + self.source.c2, 42]))
55
73
  self.assertEqual(
56
74
  str(query),
57
75
  'MERGE INTO "t" AS "a" USING "s" AS "b" '
58
76
  'ON ("a"."c1" = "b"."c2") '
59
77
  'WHEN MATCHED THEN '
60
- 'UPDATE SET "c1" = ("a"."c1" + "b"."c2")')
61
- self.assertEqual(query.params, ())
78
+ 'UPDATE SET "c1" = ("a"."c1" + "b"."c2"), "c2" = %s')
79
+ self.assertEqual(query.params, (42,))
62
80
 
63
81
  def test_matched_delete(self):
64
82
  query = self.target.merge(
@@ -94,6 +112,26 @@ class TestMerge(unittest.TestCase):
94
112
  'INSERT ("c1", "c2") VALUES ("b"."c3", "b"."c4")')
95
113
  self.assertEqual(query.params, ())
96
114
 
115
+ def test_not_matched_insert_default(self):
116
+ query = self.target.merge(
117
+ self.source, self.target.c1 == self.source.c2,
118
+ NotMatchedInsert([self.target.c1, self.target.c2], None))
119
+ self.assertEqual(
120
+ str(query),
121
+ 'MERGE INTO "t" AS "a" USING "s" AS "b" '
122
+ 'ON ("a"."c1" = "b"."c2") '
123
+ 'WHEN NOT MATCHED THEN '
124
+ 'INSERT ("c1", "c2") DEFAULT VALUES')
125
+ self.assertEqual(query.params, ())
126
+
127
+ def test_matched_invalid_condition(self):
128
+ with self.assertRaises(ValueError):
129
+ Matched('foo')
130
+
131
+ def test_matched_values_invalid_columns(self):
132
+ with self.assertRaises(ValueError):
133
+ MatchedUpdate('foo', [])
134
+
97
135
  def test_with(self):
98
136
  t1 = Table('t1')
99
137
  w = With(query=t1.select(where=t1.c2 == 42))
@@ -9,12 +9,19 @@ from sql.operators import (
9
9
  Abs, And, Between, Div, Equal, Exists, FloorDiv, Greater, GreaterEqual,
10
10
  ILike, In, Is, IsDistinct, IsNot, IsNotDistinct, Less, LessEqual, Like,
11
11
  LShift, Mod, Mul, Neg, Not, NotBetween, NotEqual, NotILike, NotIn, NotLike,
12
- Or, Pos, Pow, RShift, Sub)
12
+ Operator, Or, Pos, Pow, RShift, Sub)
13
13
 
14
14
 
15
15
  class TestOperators(unittest.TestCase):
16
16
  table = Table('t')
17
17
 
18
+ def test_operator_operands(self):
19
+ self.assertEqual(Operator()._operands, ())
20
+
21
+ def test_operator_str(self):
22
+ with self.assertRaises(NotImplementedError):
23
+ str(Operator())
24
+
18
25
  def test_and(self):
19
26
  for and_ in [And((self.table.c1, self.table.c2)),
20
27
  self.table.c1 & self.table.c2]:
@@ -25,6 +32,10 @@ class TestOperators(unittest.TestCase):
25
32
  self.assertEqual(str(and_), '(%s AND "c2")')
26
33
  self.assertEqual(and_.params, (True,))
27
34
 
35
+ and_ = And((Literal(True), 'foo'))
36
+ self.assertEqual(str(and_), '(%s AND %s)')
37
+ self.assertEqual(and_.params, (True, 'foo'))
38
+
28
39
  def test_operator_operators(self):
29
40
  and_ = And((Literal(True), self.table.c1))
30
41
  and2 = and_ & And((Literal(True), self.table.c2))
@@ -200,6 +211,10 @@ class TestOperators(unittest.TestCase):
200
211
  self.assertEqual(str(is_), '("c1" IS FALSE)')
201
212
  self.assertEqual(is_.params, ())
202
213
 
214
+ def test_is_invalid_right(self):
215
+ with self.assertRaises(ValueError):
216
+ Is(self.table.c, 'foo')
217
+
203
218
  def test_is_not(self):
204
219
  for is_ in [IsNot(self.table.c1, None),
205
220
  ~Is(self.table.c1, None)]:
@@ -315,6 +330,10 @@ class TestOperators(unittest.TestCase):
315
330
  finally:
316
331
  Flavor.set(Flavor())
317
332
 
333
+ def test_like_invalid_escape(self):
334
+ with self.assertRaises(ValueError):
335
+ Like(self.table.c, 'test', escape='fo')
336
+
318
337
  def test_ilike(self):
319
338
  flavor = Flavor(ilike=True)
320
339
  Flavor.set(flavor)
sql/tests/test_order.py CHANGED
@@ -3,28 +3,33 @@
3
3
  import unittest
4
4
 
5
5
  from sql import (
6
- Asc, Column, Desc, Flavor, Literal, NullsFirst, NullsLast, Table)
6
+ Asc, Column, Desc, Flavor, Literal, NullOrder, NullsFirst, NullsLast,
7
+ Order, Table)
7
8
 
8
9
 
9
10
  class TestOrder(unittest.TestCase):
10
11
  column = Column(Table('t'), 'c')
11
12
 
12
13
  def test_asc(self):
13
- self.assertEqual(str(Asc(self.column)), '"c" ASC')
14
+ self.assertEqual(str(self.column.asc), '"c" ASC')
14
15
 
15
16
  def test_desc(self):
16
- self.assertEqual(str(Desc(self.column)), '"c" DESC')
17
+ self.assertEqual(str(self.column.desc), '"c" DESC')
17
18
 
18
19
  def test_nulls_first(self):
19
- self.assertEqual(str(NullsFirst(self.column)), '"c" NULLS FIRST')
20
- self.assertEqual(str(NullsFirst(Asc(self.column))),
20
+ self.assertEqual(str(self.column.nulls_first), '"c" NULLS FIRST')
21
+ self.assertEqual(str(Asc(self.column).nulls_first),
21
22
  '"c" ASC NULLS FIRST')
22
23
 
23
24
  def test_nulls_last(self):
24
- self.assertEqual(str(NullsLast(self.column)), '"c" NULLS LAST')
25
- self.assertEqual(str(NullsLast(Asc(self.column))),
25
+ self.assertEqual(str(self.column.nulls_last), '"c" NULLS LAST')
26
+ self.assertEqual(str(Asc(self.column).nulls_last),
26
27
  '"c" ASC NULLS LAST')
27
28
 
29
+ def test_null_order_case_values(self):
30
+ with self.assertRaises(NotImplementedError):
31
+ NullOrder(self.column)._case_values()
32
+
28
33
  def test_no_null_ordering(self):
29
34
  try:
30
35
  Flavor.set(Flavor(null_ordering=False))
@@ -54,3 +59,7 @@ class TestOrder(unittest.TestCase):
54
59
  '(SELECT "a"."c" FROM "t" AS "a") ASC')
55
60
  self.assertEqual(str(Desc(query)),
56
61
  '(SELECT "a"."c" FROM "t" AS "a") DESC')
62
+
63
+ def test_invalid_expression(self):
64
+ with self.assertRaises(ValueError):
65
+ Order('foo')
@@ -0,0 +1,13 @@
1
+ # This file is part of python-sql. The COPYRIGHT file at the top level of
2
+ # this repository contains the full copyright notices and license terms.
3
+
4
+ import unittest
5
+
6
+ from sql import Rollup
7
+
8
+
9
+ class TestRollup(unittest.TestCase):
10
+
11
+ def test_invalid_expressions(self):
12
+ with self.assertRaises(ValueError):
13
+ Rollup('foo')
sql/tests/test_select.py CHANGED
@@ -34,6 +34,12 @@ class TestSelect(unittest.TestCase):
34
34
  'SELECT * FROM "t" AS "a" WHERE ("a"."c" = %s)')
35
35
  self.assertEqual(tuple(query.params), ('foo',))
36
36
 
37
+ def test_select_iter(self):
38
+ query = self.table.select()
39
+ self.assertEqual(
40
+ tuple(query),
41
+ ('SELECT * FROM "t" AS "a"', ()))
42
+
37
43
  def test_select_without_from(self):
38
44
  query = Select([Literal(1)])
39
45
  self.assertEqual(str(query), 'SELECT %s')
@@ -49,6 +55,14 @@ class TestSelect(unittest.TestCase):
49
55
  self.assertEqual(str(query), 'SELECT (SELECT %s) AS "foo"')
50
56
  self.assertEqual(tuple(query.params), (1,))
51
57
 
58
+ def test_select_invalid_column(self):
59
+ with self.assertRaises(ValueError):
60
+ Select(['foo'])
61
+
62
+ def test_select_invalid_where(self):
63
+ with self.assertRaises(ValueError):
64
+ self.table.select(where='foo')
65
+
52
66
  def test_select_distinct(self):
53
67
  query = self.table.select(self.table.c, distinct=True)
54
68
  self.assertEqual(
@@ -68,6 +82,10 @@ class TestSelect(unittest.TestCase):
68
82
  'SELECT DISTINCT ON ("a"."a", "a"."b") "a"."c" FROM "t" AS "a"')
69
83
  self.assertEqual(tuple(query.params), ())
70
84
 
85
+ def test_select_invalid_distinct_on(self):
86
+ with self.assertRaises(ValueError):
87
+ self.table.select(self.table.c, distinct_on='foo')
88
+
71
89
  def test_select_from_list(self):
72
90
  t2 = Table('t2')
73
91
  t3 = Table('t3')
@@ -231,6 +249,10 @@ class TestSelect(unittest.TestCase):
231
249
  'GROUP BY CUBE ("a"."a", "a"."b")')
232
250
  self.assertEqual(tuple(query.params), ('*',))
233
251
 
252
+ def test_select_invalid_group_by(self):
253
+ with self.assertRaises(ValueError):
254
+ self.table.select(group_by=['foo'])
255
+
234
256
  def test_select_having(self):
235
257
  col1 = self.table.col1
236
258
  col2 = self.table.col2
@@ -241,6 +263,10 @@ class TestSelect(unittest.TestCase):
241
263
  'HAVING (MIN("a"."col2") > %s)')
242
264
  self.assertEqual(tuple(query.params), (3,))
243
265
 
266
+ def test_select_invalid_having(self):
267
+ with self.assertRaises(ValueError):
268
+ self.table.select(having='foo')
269
+
244
270
  def test_select_order(self):
245
271
  c = self.table.c
246
272
  query = self.table.select(c, order_by=Literal(1))
@@ -248,6 +274,10 @@ class TestSelect(unittest.TestCase):
248
274
  'SELECT "a"."c" FROM "t" AS "a" ORDER BY %s')
249
275
  self.assertEqual(tuple(query.params), (1,))
250
276
 
277
+ def test_select_invalid_order(self):
278
+ with self.assertRaises(ValueError):
279
+ self.table.select(order_by='foo')
280
+
251
281
  def test_select_limit_offset(self):
252
282
  try:
253
283
  Flavor.set(Flavor(limitstyle='limit'))
@@ -285,6 +315,14 @@ class TestSelect(unittest.TestCase):
285
315
  finally:
286
316
  Flavor.set(Flavor())
287
317
 
318
+ def test_select_invalid_limit(self):
319
+ with self.assertRaises(ValueError):
320
+ self.table.select(limit='foo')
321
+
322
+ def test_select_invalid_offset(self):
323
+ with self.assertRaises(ValueError):
324
+ self.table.select(offset='foo')
325
+
288
326
  def test_select_offset_fetch(self):
289
327
  try:
290
328
  Flavor.set(Flavor(limitstyle='fetch'))
@@ -390,6 +428,10 @@ class TestSelect(unittest.TestCase):
390
428
  'SELECT "a"."c" FROM "t" AS "a" FOR UPDATE')
391
429
  self.assertEqual(tuple(query.params), ())
392
430
 
431
+ def test_select_invalid_for(self):
432
+ with self.assertRaises(ValueError):
433
+ self.table.select(for_=['foo'])
434
+
393
435
  def test_copy(self):
394
436
  query = self.table.select()
395
437
  copy_query = deepcopy(query)
@@ -472,6 +514,20 @@ class TestSelect(unittest.TestCase):
472
514
  'WINDOW "b" AS (PARTITION BY "a"."c2")')
473
515
  self.assertEqual(tuple(query.params), (1,))
474
516
 
517
+ def test_window_with_alias(self):
518
+ query = self.table.select(
519
+ Min(self.table.c1, window=Window([self.table.c2])).as_('min'))
520
+
521
+ self.assertEqual(
522
+ str(query),
523
+ 'SELECT MIN("a"."c1") OVER "b" AS "min" FROM "t" AS "a" '
524
+ 'WINDOW "b" AS (PARTITION BY "a"."c2")')
525
+ self.assertEqual(query.params, ())
526
+
527
+ def test_select_invalid_window(self):
528
+ with self.assertRaises(ValueError):
529
+ self.table.select(windows=['foo'])
530
+
475
531
  def test_order_params(self):
476
532
  with_ = With(query=self.table.select(self.table.c,
477
533
  where=(self.table.c > 1)))
sql/tests/test_update.py CHANGED
@@ -27,6 +27,14 @@ class TestUpdate(unittest.TestCase):
27
27
  'WHERE ("b"."c" = "a"."c")')
28
28
  self.assertEqual(query.params, ('foo',))
29
29
 
30
+ def test_update_invalid_values(self):
31
+ with self.assertRaises(ValueError):
32
+ self.table.update([self.table.c], 'foo')
33
+
34
+ def test_update_invalid_where(self):
35
+ with self.assertRaises(ValueError):
36
+ self.table.update([self.table.c], ['foo'], where='foo')
37
+
30
38
  def test_update_subselect(self):
31
39
  t1 = Table('t1')
32
40
  t2 = Table('t2')
sql/tests/test_window.py CHANGED
@@ -14,6 +14,10 @@ class TestWindow(unittest.TestCase):
14
14
  self.assertEqual(str(window), 'PARTITION BY "c1", "c2"')
15
15
  self.assertEqual(window.params, ())
16
16
 
17
+ def test_window_invalid_partition(self):
18
+ with self.assertRaises(ValueError):
19
+ Window(['foo'])
20
+
17
21
  def test_window_order(self):
18
22
  t = Table('t')
19
23
  window = Window([t.c], order_by=t.c)
@@ -21,6 +25,10 @@ class TestWindow(unittest.TestCase):
21
25
  self.assertEqual(str(window), 'PARTITION BY "c" ORDER BY "c"')
22
26
  self.assertEqual(window.params, ())
23
27
 
28
+ def test_window_invalid_order(self):
29
+ with self.assertRaises(ValueError):
30
+ Window([Table('t').c], order_by='foo')
31
+
24
32
  def test_window_range(self):
25
33
  t = Table('t')
26
34
  window = Window([t.c], frame='RANGE')
@@ -50,6 +58,18 @@ class TestWindow(unittest.TestCase):
50
58
  'BETWEEN %s FOLLOWING AND UNBOUNDED FOLLOWING')
51
59
  self.assertEqual(window.params, (1,))
52
60
 
61
+ def test_window_invalid_frame(self):
62
+ with self.assertRaises(ValueError):
63
+ Window([Table('t').c], frame='foo')
64
+
65
+ def test_window_invalid_start(self):
66
+ with self.assertRaises(ValueError):
67
+ Window([Table('t').c], start='foo')
68
+
69
+ def test_window_invalid_end(self):
70
+ with self.assertRaises(ValueError):
71
+ Window([Table('t').c], end='foo')
72
+
53
73
  def test_window_exclude(self):
54
74
  t = Table('t')
55
75
  window = Window([t.c], exclude='TIES')
@@ -58,6 +78,10 @@ class TestWindow(unittest.TestCase):
58
78
  'PARTITION BY "c" EXCLUDE TIES')
59
79
  self.assertEqual(window.params, ())
60
80
 
81
+ def test_window_invalid_exclude(self):
82
+ with self.assertRaises(ValueError):
83
+ Window([Table('t').c], exclude='foo')
84
+
61
85
  def test_window_rows(self):
62
86
  t = Table('t')
63
87
  window = Window([t.c], frame='ROWS')
sql/tests/test_with.py CHANGED
@@ -62,3 +62,7 @@ class TestWith(unittest.TestCase):
62
62
  'SELECT ("a"."n" + %s) FROM "a" AS "a" WHERE ("a"."n" < %s)'
63
63
  ') SELECT * FROM "a" AS "a"')
64
64
  self.assertEqual(tuple(q.params), (1, 1, 100))
65
+
66
+ def test_invalid_with(self):
67
+ with self.assertRaises(ValueError):
68
+ WithQuery(with_=['foo'])
@@ -1,34 +0,0 @@
1
- sql/__init__.py,sha256=gmmbZtl-Xz2V_wc5HDJMcTdjoXdfgYueu42AaAoha_Y,60610
2
- sql/aggregate.py,sha256=Dmog1JIuFZ8fFT8RjeGbWGU7kCdJcMrNlwTSO1HIwc8,5241
3
- sql/conditionals.py,sha256=xJY6ffEBeES6CiGKErXSa2dK2FXaEaR_QQl_CKILP30,2541
4
- sql/functions.py,sha256=qdmLZ5eoqIsc7erlPsdByecUey7rexhVdUTSB_RnOZ4,12373
5
- sql/operators.py,sha256=cuh2pvRDNbWbWwE4su9dwsuDxPlJ_S9gn3U-iVvrbKE,10788
6
- sql/tests/__init__.py,sha256=oHBEqcjoFLDwTiSIDwYNLS8Vj1lkq8-O5DsTKCh1BJw,675
7
- sql/tests/test_aggregate.py,sha256=7KDN81zxzkVjjoHHLpQMvB-yVqwkKdPoKuppqmWfDYI,2592
8
- sql/tests/test_alias.py,sha256=AcMrKVvFPsR84BRGc_dN6t3O5vAqNjBeWicb6I6EuBI,1884
9
- sql/tests/test_as.py,sha256=OfXDu0CnJ2paRKR29dMdx7q_Q9TFY60MWlvib6MR5LY,926
10
- sql/tests/test_cast.py,sha256=ejrqHQZwA3967UhszYR3caZYvH3waPcF6li4rnmxGi4,653
11
- sql/tests/test_collate.py,sha256=LWJhwcmVBsbJpEtaBRu-BUkBufXktUgCHS4XR7LbAYA,842
12
- sql/tests/test_column.py,sha256=_GkBkBzLW_fDoJy5yUWDtHTSyka1s5Drd4gDuvtIM_8,866
13
- sql/tests/test_combining_query.py,sha256=SyVHnIUiikGwc7ViAEalCKwgYRRfayNmsBD1NhCWoNM,2277
14
- sql/tests/test_conditionals.py,sha256=kNkgsjOatXpJnF9AED03ANNd0zWIwWTrnWdi4PWfl3E,2705
15
- sql/tests/test_delete.py,sha256=0xEllZmXVc9YH6lGJI0_DVXCpB1CTc-e62GK0_fnoM4,1591
16
- sql/tests/test_for.py,sha256=6e4n7NbKTdlEp_z6MrNT_eM8rwXR94gANtBmWzhxcjk,550
17
- sql/tests/test_functions.py,sha256=CM-a0c1ey9uEhw3wFL8PWETB3Kpl5wtkGNLt44r_0EE,5377
18
- sql/tests/test_insert.py,sha256=1jt2nNrNRdxH7VykkQCwjiVK-LJmmjaGiDaqUJWeh9U,7378
19
- sql/tests/test_join.py,sha256=OWFqe2Zbb-uDTzg9b0GcH2p2xzhinuvy6E_ANMCOD-Y,1891
20
- sql/tests/test_lateral.py,sha256=f6hlapGKJ-ZWobMPktN4mSNXgfyNr7O5ZwZASb_oo30,1046
21
- sql/tests/test_literal.py,sha256=ht-VLhGdpUm_rbtOzpQgbX3YQup_xp7F9va0RSWY0Ts,1010
22
- sql/tests/test_merge.py,sha256=CWF7grhpfqlgNUlafDr9Xbx-EY9uGMFbJRPGoLf5pd8,4074
23
- sql/tests/test_operators.py,sha256=6j6AEK5_xKJq-WC7Q9fXDE5YxDrwW7Z3LhJwkLo1tI8,15542
24
- sql/tests/test_order.py,sha256=VXfs5ZMQQiLqrSVFn-EykjJ3cHgJAiStiUELjlbZefY,1996
25
- sql/tests/test_select.py,sha256=MSwnN-JF5sxia_rxfWvVgtxApXSNJi7gEQaQ6eg7QTc,19903
26
- sql/tests/test_table.py,sha256=ZF6VzLcx54ulj69Qnt0hdQ7_XamAqpofyTKs0WiGB4E,758
27
- sql/tests/test_update.py,sha256=ki2O9PkLbAd5kX4TJkmttB7OicSWhlYbQQXKWHOR2gg,3490
28
- sql/tests/test_values.py,sha256=qKvaFSDEQmVWajWhMZgqD2-rQcWJeW_nsevVMsV3jD8,1053
29
- sql/tests/test_window.py,sha256=4WJCrdk0YeCujhZqu87UnXNhdJelOuXVJ-ttwSOR_S0,2392
30
- sql/tests/test_with.py,sha256=A8jwi8FctjFIKI3ppGv3sO9EV2rmJ9pcP3HFmhx7YiY,2256
31
- python_sql-1.5.1.dist-info/METADATA,sha256=XNgCKTalL5eVIhPQZzBfiCQsCyeL1uAsb0w67hWo9So,8514
32
- python_sql-1.5.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
33
- python_sql-1.5.1.dist-info/top_level.txt,sha256=hwJHmWfbRP5a_XNfqgHwi2zrjAAzAJk24QZoTocslow,4
34
- python_sql-1.5.1.dist-info/RECORD,,