diff options
author | Changaco <changaco@changaco.oy.lc> | 2019-06-04 13:44:40 +0200 |
---|---|---|
committer | Changaco <changaco@changaco.oy.lc> | 2019-06-04 13:45:37 +0200 |
commit | 527592a0a52b8c6a09535e785dac63c36cf25ada (patch) | |
tree | 1872d4ad79d8159d5ac8073111f97830cb94ccbb | |
parent | 668d507c34989bd7df97802d853e69c3b79cd128 (diff) | |
download | psycopg2-527592a0a52b8c6a09535e785dac63c36cf25ada.tar.gz |
improve the NamedTupleCursor cache test
-rwxr-xr-x | tests/test_extras_dictcursor.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/test_extras_dictcursor.py b/tests/test_extras_dictcursor.py index c7f09d5..a4f45c2 100755 --- a/tests/test_extras_dictcursor.py +++ b/tests/test_extras_dictcursor.py @@ -615,17 +615,27 @@ class NamedTupleCursorTest(ConnectingTestCase): self.assertEqual(i + 1, curs.rownumber) def test_cache(self): + NamedTupleCursor._cached_make_nt.cache_clear() + curs = self.conn.cursor() curs.execute("select 10 as a, 20 as b") r1 = curs.fetchone() curs.execute("select 10 as a, 20 as c") r2 = curs.fetchone() + + # Get a new cursor to check that the cache works across multiple ones + curs = self.conn.cursor() curs.execute("select 10 as a, 30 as b") r3 = curs.fetchone() self.assert_(type(r1) is type(r3)) self.assert_(type(r1) is not type(r2)) + cache_info = NamedTupleCursor._cached_make_nt.cache_info() + self.assertEqual(cache_info.hits, 1) + self.assertEqual(cache_info.misses, 2) + self.assertEqual(cache_info.currsize, 2) + def test_max_cache(self): old_func = NamedTupleCursor._cached_make_nt NamedTupleCursor._cached_make_nt = \ |