From 6a129fed34d2bf8fbc7338e39a9e17d23e6accd1 Mon Sep 17 00:00:00 2001 From: Kelsey Hawley Date: Fri, 20 Dec 2013 13:51:34 -0800 Subject: [PATCH] corrected the import of python 3 modules. Updated print statements to function form to work correctly with python 2 & 3. Also decoded the subprocess output into unicode string for splicing and processing of keys --- tests/test_dump-anydbm.py | 48 +++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/test_dump-anydbm.py b/tests/test_dump-anydbm.py index c8fc8a5..b23fc44 100644 --- a/tests/test_dump-anydbm.py +++ b/tests/test_dump-anydbm.py @@ -7,14 +7,14 @@ import subprocess # to access the script from shell # will try as python 3 then default to python 2 modules try: import dbm - ndbm = dbm.ndbm - gdbm = dbm.gdbm - dumb = dbm.dumb + from dbm import ndbm + from dbm import gnu as gdbm + from dbm import dumb whichdb = dbm.whichdb ndbm_type = "dbm.ndbm" - gdbm_type = "dbm.gdbm" + gdbm_type = "dbm.gnu" dumb_type = "dbm.dumb" except: @@ -33,17 +33,18 @@ key1 = 'very first key' key2 = 'second key' val1 = 'very first value' val2 = 'second value' +dump_anydbm = "dump-anydbm" @pytest.fixture(scope = "function") def make_gdbm_test_db(request): db_name ="test_gdbm" - print "creating", db_name + print("creating", db_name) test_db = gdbm.open(db_name, "n") test_db[key1] = val1 test_db[key2] = val2 test_db.close() def delete_test_dumbdbm(): - print "deleting", db_name + print("deleting", db_name) os.remove(db_name) request.addfinalizer(delete_test_dumbdbm) @@ -52,13 +53,13 @@ def make_gdbm_test_db(request): @pytest.fixture(scope = "function") def make_ndbm_test_db(request): db_name = "test_ndbm" - print "creating", db_name + print("creating", db_name) test_db = ndbm.open(db_name, "n") test_db[key1] = val1 test_db[key2] = val2 test_db.close() def delete_test_ndbm(): - print "deleting", db_name + print("deleting", db_name) os.remove(db_name+".db") request.addfinalizer(delete_test_ndbm) @@ -67,13 +68,13 @@ def make_ndbm_test_db(request): @pytest.fixture(scope = "function") def make_dumbdbm_test_db(request): db_name ="test_dumbdbm" - print "creating", db_name + print("creating", db_name) test_db = dumb.open(db_name, "n") test_db[key1] = val1 test_db[key2] = val2 test_db.close() def delete_test_dumbdbm(): - print "deleting", db_name + print("deleting", db_name) os.remove(db_name+".dir") os.remove(db_name+".bak") os.remove(db_name+".dat") @@ -82,14 +83,14 @@ def make_dumbdbm_test_db(request): return db_name def test_dumpanydbm_identify_gdbm(make_gdbm_test_db): - print "running test_dumpanydbm_identify_gdbm" - output = subprocess.check_output(["dump-anydbm", make_gdbm_test_db]) - output = output.strip().split("\n") + print("running test_dumpanydbm_identify_gdbm") + output = subprocess.check_output([dump_anydbm, make_gdbm_test_db]) + output = output.decode(encoding = 'UTF-8').strip().split("\n") assert len(output) == 3 # 2 keys plus whichdb line # split on space, then grab 4th word, which is db type which = output[0].split(' ')[3] - print which + print(which) assert which == gdbm_type #split remaining lines on ':' that separates key & value @@ -102,15 +103,15 @@ def test_dumpanydbm_identify_gdbm(make_gdbm_test_db): assert db_dump_second_pair[1] == val2 def test_dumpanydbm_identify_ndbm(make_ndbm_test_db): - print "running test_dumpanydbm_identify_ndbm" - output = subprocess.check_output(["dump-anydbm", make_ndbm_test_db]) - output = output.strip().split("\n") + print("running test_dumpanydbm_identify_ndbm") + output = subprocess.check_output([dump_anydbm, make_ndbm_test_db]) + output = output.decode(encoding = 'UTF-8').strip().split("\n") assert len(output) == 3 # 2 keys plus whichdb line # split on space, then grab 4th word, which is db type which = output[0].split(' ')[3] - print which + print(which) assert which == ndbm_type #split remaining lines on ':' that separates key & value @@ -123,14 +124,15 @@ def test_dumpanydbm_identify_ndbm(make_ndbm_test_db): assert db_dump_second_pair[1] == val2 def test_dumpanydbm_identify_dumbdbm(make_dumbdbm_test_db): - print "running test_dumpanydbm_identify_dumbdbm" - output = subprocess.check_output(["dump-anydbm", make_dumbdbm_test_db]) - output = output.strip().split("\n") + print("running test_dumpanydbm_identify_dumbdbm") + output = subprocess.check_output([dump_anydbm, make_dumbdbm_test_db]) + output = output.decode(encoding = 'UTF-8').strip().split("\n") assert len(output) == 3 # 2 keys plus whichdb line + print(output) # split on space, then grab 4th word, which is db type which = output[0].split(' ')[3] - print which + print(which) assert which == dumb_type #split remaining lines on ':' that separates key & value @@ -141,5 +143,3 @@ def test_dumpanydbm_identify_dumbdbm(make_dumbdbm_test_db): db_dump_second_pair = output[2].split(':') assert db_dump_second_pair[0] == key2 assert db_dump_second_pair[1] == val2 - -