Lines Matching refs:self

43         def wrapper(self, *args, **kwargs):
46 with check_tracebacks(self, cm, exc, _regex, name):
47 func(self, *args, **kwargs)
50 func(self, *args, **kwargs)
56 def check_tracebacks(self, cm, exc, regex, obj_name):
64 self.assertEqual(cm.unraisable.exc_type, exc)
67 self.assertIsNotNone(regex.search(msg))
69 self.assertEqual(cm.unraisable.object.__name__, obj_name)
98 def __init__(self):
101 def finalize(self):
105 def __init__(self):
108 def step(self, x):
112 def __init__(self):
115 def step(self, x):
118 def finalize(self):
122 def __init__(self):
125 def step(self, x):
128 def finalize(self):
132 def __init__(self):
135 def step(self, x):
138 def finalize(self):
142 def __init__(self):
143 self.val = None
145 def step(self, whichType, val):
148 self.val = int(theType[whichType] is type(val))
150 def finalize(self):
151 return self.val
154 def __init__(self):
155 self.val = 0
157 def step(self, whichType, *vals):
161 self.val += int(theType[whichType] is type(val))
163 def finalize(self):
164 return self.val
167 def __init__(self):
168 self.val = 0.0
170 def step(self, val):
171 self.val += val
173 def finalize(self):
174 return self.val
177 def __init__(self):
178 self.txt = ""
179 def step(self, txt):
180 self.txt = self.txt + txt
181 def finalize(self):
182 return self.txt
186 def setUp(self):
187 self.con = sqlite.connect(":memory:")
189 self.con.create_function("returntext", 0, func_returntext)
190 self.con.create_function("returntextwithnull", 0, func_returntextwithnull)
191 self.con.create_function("returnunicode", 0, func_returnunicode)
192 self.con.create_function("returnint", 0, func_returnint)
193 self.con.create_function("returnfloat", 0, func_returnfloat)
194 self.con.create_function("returnnull", 0, func_returnnull)
195 self.con.create_function("returnblob", 0, func_returnblob)
196 self.con.create_function("returnlonglong", 0, func_returnlonglong)
197 self.con.create_function("returnnan", 0, lambda: float("nan"))
198 self.con.create_function("returntoolargeint", 0, lambda: 1 << 65)
199 self.con.create_function("return_noncont_blob", 0,
201 self.con.create_function("raiseexception", 0, func_raiseexception)
202 self.con.create_function("memoryerror", 0, func_memoryerror)
203 self.con.create_function("overflowerror", 0, func_overflowerror)
205 self.con.create_function("isblob", 1, lambda x: isinstance(x, bytes))
206 self.con.create_function("isnone", 1, lambda x: x is None)
207 self.con.create_function("spam", -1, lambda *x: len(x))
208 self.con.execute("create table test(t text)")
210 def tearDown(self):
211 self.con.close()
213 def test_func_error_on_create(self):
214 with self.assertRaises(sqlite.OperationalError):
215 self.con.create_function("bla", -100, lambda x: 2*x)
217 def test_func_too_many_args(self):
220 with cx_limit(self.con, category=category, limit=1):
221 self.con.execute("select abs(-1)");
222 with self.assertRaisesRegex(sqlite.OperationalError, msg):
223 self.con.execute("select max(1, 2)");
225 def test_func_ref_count(self):
232 # self.con.create_function("reftest", 0, getfunc())
233 self.con.create_function("reftest", 0, f)
234 cur = self.con.cursor()
237 def test_func_return_text(self):
238 cur = self.con.cursor()
241 self.assertEqual(type(val), str)
242 self.assertEqual(val, "foo")
244 def test_func_return_text_with_null_char(self):
245 cur = self.con.cursor()
247 self.assertEqual(type(res), str)
248 self.assertEqual(res, "1\x002")
250 def test_func_return_unicode(self):
251 cur = self.con.cursor()
254 self.assertEqual(type(val), str)
255 self.assertEqual(val, "bar")
257 def test_func_return_int(self):
258 cur = self.con.cursor()
261 self.assertEqual(type(val), int)
262 self.assertEqual(val, 42)
264 def test_func_return_float(self):
265 cur = self.con.cursor()
268 self.assertEqual(type(val), float)
270 self.fail("wrong value")
272 def test_func_return_null(self):
273 cur = self.con.cursor()
276 self.assertEqual(type(val), type(None))
277 self.assertEqual(val, None)
279 def test_func_return_blob(self):
280 cur = self.con.cursor()
283 self.assertEqual(type(val), bytes)
284 self.assertEqual(val, b"blob")
286 def test_func_return_long_long(self):
287 cur = self.con.cursor()
290 self.assertEqual(val, 1<<31)
292 def test_func_return_nan(self):
293 cur = self.con.cursor()
295 self.assertIsNone(cur.fetchone()[0])
297 def test_func_return_too_large_int(self):
298 cur = self.con.cursor()
299 self.assertRaisesRegex(sqlite.DataError, "string or blob too big",
300 self.con.execute, "select returntoolargeint()")
303 def test_func_exception(self):
304 cur = self.con.cursor()
305 with self.assertRaises(sqlite.OperationalError) as cm:
308 self.assertEqual(str(cm.exception), 'user-defined function raised exception')
311 def test_func_memory_error(self):
312 cur = self.con.cursor()
313 with self.assertRaises(MemoryError):
318 def test_func_overflow_error(self):
319 cur = self.con.cursor()
320 with self.assertRaises(sqlite.DataError):
324 def test_any_arguments(self):
325 cur = self.con.cursor()
328 self.assertEqual(val, 2)
330 def test_empty_blob(self):
331 cur = self.con.execute("select isblob(x'')")
332 self.assertTrue(cur.fetchone()[0])
334 def test_nan_float(self):
335 cur = self.con.execute("select isnone(?)", (float("nan"),))
337 self.assertTrue(cur.fetchone()[0])
339 def test_too_large_int(self):
341 self.assertRaisesRegex(OverflowError, err, self.con.execute,
344 def test_non_contiguous_blob(self):
345 self.assertRaisesRegex(BufferError,
347 self.con.execute, "select spam(?)",
351 def test_return_non_contiguous_blob(self):
352 with self.assertRaises(sqlite.OperationalError):
353 cur = self.con.execute("select return_noncont_blob()")
356 def test_param_surrogates(self):
357 self.assertRaisesRegex(UnicodeEncodeError, "surrogates not allowed",
358 self.con.execute, "select spam(?)",
361 def test_func_params(self):
365 self.con.create_function("test_params", 1, append_result)
383 cur = self.con.execute("select test_params(?)", (val,))
385 self.assertEqual(dataset, results)
395 def test_func_non_deterministic(self):
397 self.con.create_function("nondeterministic", 0, mock, deterministic=False)
399 self.con.execute("select nondeterministic() = nondeterministic()")
400 self.assertEqual(mock.call_count, 2)
402 with self.assertRaises(sqlite.OperationalError):
403 self.con.execute("create index t on test(t) where nondeterministic() is not null")
406 def test_func_deterministic(self):
408 self.con.create_function("deterministic", 0, mock, deterministic=True)
410 self.con.execute("select deterministic() = deterministic()")
411 self.assertEqual(mock.call_count, 1)
414 self.con.execute("create index t on test(t) where deterministic() is not null")
416 self.fail("Unexpected failure while creating partial index")
419 def test_func_deterministic_not_supported(self):
420 with self.assertRaises(sqlite.NotSupportedError):
421 self.con.create_function("deterministic", 0, int, deterministic=True)
423 def test_func_deterministic_keyword_only(self):
424 with self.assertRaises(TypeError):
425 self.con.create_function("deterministic", 0, int, True)
427 def test_function_destructor_via_gc(self):
445 def test_func_return_too_large_int(self):
446 cur = self.con.cursor()
448 self.con.create_function("largeint", 0, lambda value=value: value)
449 with self.assertRaises(sqlite.DataError):
453 def test_func_return_text_with_surrogates(self):
454 cur = self.con.cursor()
455 self.con.create_function("pychr", 1, chr)
457 with self.assertRaises(sqlite.OperationalError):
462 def test_func_return_too_large_text(self, size):
463 cur = self.con.cursor()
465 self.con.create_function("largetext", 0, lambda size=size: "b" * size)
466 with self.assertRaises(sqlite.DataError):
471 def test_func_return_too_large_blob(self, size):
472 cur = self.con.cursor()
474 self.con.create_function("largeblob", 0, lambda size=size: b"b" * size)
475 with self.assertRaises(sqlite.DataError):
478 def test_func_return_illegal_value(self):
479 self.con.create_function("badreturn", 0, lambda: self)
481 self.assertRaisesRegex(sqlite.OperationalError, msg,
482 self.con.execute, "select badreturn()")
486 def __init__(self):
487 self.count = 0
489 def step(self, value):
490 self.count += value
492 def value(self):
493 return self.count
495 def inverse(self, value):
496 self.count -= value
498 def finalize(self):
499 return self.count
508 def setUp(self):
509 self.con = sqlite.connect(":memory:")
510 self.cur = self.con.cursor()
520 with self.con:
521 self.con.execute("create table test(x, y)")
522 self.con.executemany("insert into test values(?, ?)", values)
523 self.expected = [
530 self.query = """
536 self.con.create_window_function("sumint", 1, WindowSumInt)
538 def test_win_sum_int(self):
539 self.cur.execute(self.query % "sumint")
540 self.assertEqual(self.cur.fetchall(), self.expected)
542 def test_win_error_on_create(self):
543 self.assertRaises(sqlite.ProgrammingError,
544 self.con.create_window_function,
548 def test_win_exception_in_method(self):
550 with self.subTest(meth=meth):
553 self.con.create_window_function(name, 1, WindowSumInt)
555 with self.assertRaisesRegex(sqlite.OperationalError, msg):
556 self.cur.execute(self.query % name)
557 self.cur.fetchall()
560 def test_win_exception_in_finalize(self):
566 self.con.create_window_function(name, 1, WindowSumInt)
567 self.cur.execute(self.query % name)
568 self.cur.fetchall()
571 def test_win_missing_method(self):
573 def step(self, x): pass
574 def inverse(self, x): pass
575 def finalize(self): return 42
578 def step(self, x): pass
579 def value(self): return 42
580 def finalize(self): return 42
583 def value(self): return 42
584 def inverse(self, x): pass
585 def finalize(self): return 42
593 with self.subTest(meth=meth, cls=cls):
595 self.con.create_window_function(name, 1, cls)
596 with self.assertRaisesRegex(sqlite.OperationalError,
598 self.cur.execute(self.query % name)
599 self.cur.fetchall()
602 def test_win_missing_finalize(self):
607 def step(self, x): pass
608 def value(self): return 42
609 def inverse(self, x): pass
612 self.con.create_window_function(name, 1, MissingFinalize)
613 self.cur.execute(self.query % name)
614 self.cur.fetchall()
616 def test_win_clear_function(self):
617 self.con.create_window_function("sumint", 1, None)
618 self.assertRaises(sqlite.OperationalError, self.cur.execute,
619 self.query % "sumint")
621 def test_win_redefine_function(self):
624 def step(self, value): self.count += value * 2
625 def inverse(self, value): self.count -= value * 2
626 expected = [(v[0], v[1]*2) for v in self.expected]
628 self.con.create_window_function("sumint", 1, Redefined)
629 self.cur.execute(self.query % "sumint")
630 self.assertEqual(self.cur.fetchall(), expected)
632 def test_win_error_value_return(self):
634 def __init__(self): pass
635 def step(self, x): pass
636 def value(self): return 1 << 65
638 self.con.create_window_function("err_val_ret", 1, ErrorValueReturn)
639 self.assertRaisesRegex(sqlite.DataError, "string or blob too big",
640 self.cur.execute, self.query % "err_val_ret")
644 def setUp(self):
645 self.con = sqlite.connect(":memory:")
646 cur = self.con.cursor()
659 self.con.create_aggregate("nostep", 1, AggrNoStep)
660 self.con.create_aggregate("nofinalize", 1, AggrNoFinalize)
661 self.con.create_aggregate("excInit", 1, AggrExceptionInInit)
662 self.con.create_aggregate("excStep", 1, AggrExceptionInStep)
663 self.con.create_aggregate("excFinalize", 1, AggrExceptionInFinalize)
664 self.con.create_aggregate("checkType", 2, AggrCheckType)
665 self.con.create_aggregate("checkTypes", -1, AggrCheckTypes)
666 self.con.create_aggregate("mysum", 1, AggrSum)
667 self.con.create_aggregate("aggtxt", 1, AggrText)
669 def tearDown(self):
670 #self.cur.close()
671 #self.con.close()
674 def test_aggr_error_on_create(self):
675 with self.assertRaises(sqlite.OperationalError):
676 self.con.create_function("bla", -100, AggrSum)
679 def test_aggr_no_step(self):
680 cur = self.con.cursor()
681 with self.assertRaises(sqlite.OperationalError) as cm:
683 self.assertEqual(str(cm.exception),
686 def test_aggr_no_finalize(self):
687 cur = self.con.cursor()
689 with self.assertRaisesRegex(sqlite.OperationalError, msg):
694 def test_aggr_exception_in_init(self):
695 cur = self.con.cursor()
696 with self.assertRaises(sqlite.OperationalError) as cm:
699 self.assertEqual(str(cm.exception), "user-defined aggregate's '__init__' method raised error")
702 def test_aggr_exception_in_step(self):
703 cur = self.con.cursor()
704 with self.assertRaises(sqlite.OperationalError) as cm:
707 self.assertEqual(str(cm.exception), "user-defined aggregate's 'step' method raised error")
710 def test_aggr_exception_in_finalize(self):
711 cur = self.con.cursor()
712 with self.assertRaises(sqlite.OperationalError) as cm:
715 self.assertEqual(str(cm.exception), "user-defined aggregate's 'finalize' method raised error")
717 def test_aggr_check_param_str(self):
718 cur = self.con.cursor()
721 self.assertEqual(val, 2)
723 def test_aggr_check_param_int(self):
724 cur = self.con.cursor()
727 self.assertEqual(val, 1)
729 def test_aggr_check_params_int(self):
730 cur = self.con.cursor()
733 self.assertEqual(val, 2)
735 def test_aggr_check_param_float(self):
736 cur = self.con.cursor()
739 self.assertEqual(val, 1)
741 def test_aggr_check_param_none(self):
742 cur = self.con.cursor()
745 self.assertEqual(val, 1)
747 def test_aggr_check_param_blob(self):
748 cur = self.con.cursor()
751 self.assertEqual(val, 1)
753 def test_aggr_check_aggr_sum(self):
754 cur = self.con.cursor()
759 self.assertEqual(val, 60)
761 def test_aggr_no_match(self):
762 cur = self.con.execute("select mysum(i) from (select 1 as i) where i == 0")
764 self.assertIsNone(val)
766 def test_aggr_text(self):
767 cur = self.con.cursor()
769 with self.subTest(txt=txt):
772 self.assertEqual(val, txt)
784 def setUp(self):
785 self.con = sqlite.connect(":memory:")
786 self.con.executescript("""
794 self.con.execute("select c2 from t2")
796 self.con.set_authorizer(self.authorizer_cb)
798 def tearDown(self):
801 def test_table_access(self):
802 with self.assertRaises(sqlite.DatabaseError) as cm:
803 self.con.execute("select * from t2")
804 self.assertIn('prohibited', str(cm.exception))
806 def test_column_access(self):
807 with self.assertRaises(sqlite.DatabaseError) as cm:
808 self.con.execute("select c2 from t1")
809 self.assertIn('prohibited', str(cm.exception))
811 def test_clear_authorizer(self):
812 self.con.set_authorizer(None)
813 self.con.execute("select * from t2")
814 self.con.execute("select c2 from t1")
827 def test_table_access(self):
831 def test_column_access(self):