aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonan Lamy <ronan.lamy@gmail.com>2018-12-05 06:29:52 +0000
committerRonan Lamy <ronan.lamy@gmail.com>2018-12-05 06:29:52 +0000
commit348070a8ccc5000aae338af215a099216acce500 (patch)
treed389095524f6ce5ec8da226a90e668b2fb92dac5
parentMove test_cStringIO to extra_tests/ (diff)
downloadpypy-348070a8ccc5000aae338af215a099216acce500.tar.gz
pypy-348070a8ccc5000aae338af215a099216acce500.tar.bz2
pypy-348070a8ccc5000aae338af215a099216acce500.zip
Update and move test_dbm
-rw-r--r--extra_tests/test_dbm.py90
-rw-r--r--pypy/module/test_lib_pypy/test_dbm_extra.py81
2 files changed, 90 insertions, 81 deletions
diff --git a/extra_tests/test_dbm.py b/extra_tests/test_dbm.py
new file mode 100644
index 0000000000..6873c7c197
--- /dev/null
+++ b/extra_tests/test_dbm.py
@@ -0,0 +1,90 @@
+import pytest
+
+import os
+
+dbm = pytest.importorskip('dbm')
+
+
+def test_get(tmpdir):
+ path = str(tmpdir.join('test_dbm_extra.test_get'))
+ d = dbm.open(path, 'c')
+ x = d.get("42")
+ assert x is None
+ d.close()
+
+def test_delitem(tmpdir):
+ path = str(tmpdir.join('test_dbm_extra.test_delitem'))
+ d = dbm.open(path, 'c')
+ with pytest.raises(KeyError):
+ del d['xyz']
+
+def test_nonstring(tmpdir):
+ path = str(tmpdir.join('test_dbm_extra.test_nonstring'))
+ d = dbm.open(path, 'c')
+ with pytest.raises(TypeError):
+ d[123] = 'xyz'
+ with pytest.raises(TypeError):
+ d['xyz'] = 123
+ with pytest.raises(TypeError):
+ d['xyz'] = None
+ with pytest.raises(TypeError):
+ del d[123]
+ with pytest.raises(TypeError):
+ d[123]
+ with pytest.raises(TypeError):
+ 123 in d
+ with pytest.raises(TypeError):
+ d.has_key(123)
+ with pytest.raises(TypeError):
+ d.setdefault(123, 'xyz')
+ with pytest.raises(TypeError):
+ d.setdefault('xyz', 123)
+ with pytest.raises(TypeError):
+ d.get(123)
+ assert dict(d) == {}
+ d.setdefault('xyz', '123')
+ assert dict(d) == {'xyz': '123'}
+ d.close()
+
+def test_multiple_sets(tmpdir):
+ path = str(tmpdir.join('test_dbm_extra.test_multiple_sets'))
+ d = dbm.open(path, 'c')
+ d['xyz'] = '12'
+ d['xyz'] = '3'
+ d['xyz'] = '546'
+ assert dict(d) == {'xyz': '546'}
+ assert d['xyz'] == '546'
+
+@pytest.mark.skipif("'__pypy__' not in sys.modules")
+def test_extra():
+ with pytest.raises(TypeError):
+ dbm.datum(123)
+ with pytest.raises(TypeError):
+ dbm.datum(False)
+
+def test_null():
+ db = dbm.open('test', 'c')
+ db['1'] = 'a\x00b'
+ db.close()
+
+ db = dbm.open('test', 'r')
+ assert db['1'] == 'a\x00b'
+ db.close()
+
+def test_key_with_empty_value(tmpdir):
+ # this test fails on CPython too (at least on tannit), and the
+ # case shows up when gdbm is not installed and test_anydbm.py
+ # falls back dbm.
+ pytest.skip("test may fail on CPython too")
+ path = str(tmpdir.join('test_dbm_extra.test_key_with_empty_value'))
+ d = dbm.open(path, 'c')
+ assert 'key_with_empty_value' not in d
+ d['key_with_empty_value'] = ''
+ assert 'key_with_empty_value' in d
+ assert d['key_with_empty_value'] == ''
+ d.close()
+
+def test_unicode_filename(tmpdir):
+ path = str(tmpdir) + os.sep + u'test_dbm_extra.test_unicode_filename'
+ d = dbm.open(path, 'c')
+ d.close()
diff --git a/pypy/module/test_lib_pypy/test_dbm_extra.py b/pypy/module/test_lib_pypy/test_dbm_extra.py
deleted file mode 100644
index b81666f65a..0000000000
--- a/pypy/module/test_lib_pypy/test_dbm_extra.py
+++ /dev/null
@@ -1,81 +0,0 @@
-from __future__ import absolute_import
-import py, os
-from rpython.tool.udir import udir
-try:
- from lib_pypy import dbm
-except ImportError as e:
- py.test.skip(e)
-
-import sys
-if '__pypy__' not in sys.builtin_module_names:
- skip("lib_pypy.dbm requires PyPy's ctypes")
-
-def test_get():
- path = str(udir.join('test_dbm_extra.test_get'))
- d = dbm.open(path, 'c')
- x = d.get("42")
- assert x is None
- d.close()
-
-def test_delitem():
- path = str(udir.join('test_dbm_extra.test_delitem'))
- d = dbm.open(path, 'c')
- py.test.raises(KeyError, "del d['xyz']")
-
-def test_nonstring():
- path = str(udir.join('test_dbm_extra.test_nonstring'))
- d = dbm.open(path, 'c')
- py.test.raises(TypeError, "d[123] = 'xyz'")
- py.test.raises(TypeError, "d['xyz'] = 123")
- py.test.raises(TypeError, "d['xyz'] = None")
- py.test.raises(TypeError, "del d[123]")
- py.test.raises(TypeError, "d[123]")
- py.test.raises(TypeError, "123 in d")
- py.test.raises(TypeError, "d.has_key(123)")
- py.test.raises(TypeError, "d.setdefault(123, 'xyz')")
- py.test.raises(TypeError, "d.setdefault('xyz', 123)")
- py.test.raises(TypeError, "d.get(123)")
- assert dict(d) == {}
- d.setdefault('xyz', '123')
- assert dict(d) == {'xyz': '123'}
- d.close()
-
-def test_multiple_sets():
- path = str(udir.join('test_dbm_extra.test_multiple_sets'))
- d = dbm.open(path, 'c')
- d['xyz'] = '12'
- d['xyz'] = '3'
- d['xyz'] = '546'
- assert dict(d) == {'xyz': '546'}
- assert d['xyz'] == '546'
-
-def test_extra():
- py.test.raises(TypeError, dbm.datum, 123)
- py.test.raises(TypeError, dbm.datum, False)
-
-def test_null():
- db = dbm.open('test', 'c')
- db['1'] = 'a\x00b'
- db.close()
-
- db = dbm.open('test', 'r')
- assert db['1'] == 'a\x00b'
- db.close()
-
-def test_key_with_empty_value():
- # this test fails on CPython too (at least on tannit), and the
- # case shows up when gdbm is not installed and test_anydbm.py
- # falls back dbm.
- py.test.skip("test may fail on CPython too")
- path = str(udir.join('test_dbm_extra.test_key_with_empty_value'))
- d = dbm.open(path, 'c')
- assert 'key_with_empty_value' not in d
- d['key_with_empty_value'] = ''
- assert 'key_with_empty_value' in d
- assert d['key_with_empty_value'] == ''
- d.close()
-
-def test_unicode_filename():
- path = str(udir) + os.sep + u'test_dbm_extra.test_unicode_filename'
- d = dbm.open(path, 'c')
- d.close()