mirror of
https://github.com/internetarchive/warcprox.git
synced 2025-01-18 13:22:09 +01:00
still having trouble gettting the ndbm module to correctly make an ndbm instead of bsd db. this fixture setup seems to work, tho bogglingly. It creates 2 files, one ndbm & the other bsd db. requires further investigation
This commit is contained in:
parent
c6cbda1187
commit
99d077b89c
@ -50,6 +50,22 @@ def make_gdbm_test_db(request):
|
|||||||
request.addfinalizer(delete_test_dumbdbm)
|
request.addfinalizer(delete_test_dumbdbm)
|
||||||
return db_name
|
return db_name
|
||||||
|
|
||||||
|
@pytest.fixture(scope = "function")
|
||||||
|
def make_ndbm_test_db(request):
|
||||||
|
db_name = "test_ndbm"
|
||||||
|
print "creating", db_name
|
||||||
|
open(db_name+".db", 'a').close()
|
||||||
|
test_db = ndbm.open(db_name+".db", "n")
|
||||||
|
test_db['very first key'] = 'very first value'
|
||||||
|
test_db['second key'] = 'second value'
|
||||||
|
test_db.close()
|
||||||
|
def delete_test_ndbm():
|
||||||
|
print "deleting", db_name
|
||||||
|
# os.remove(db_name+".db")
|
||||||
|
|
||||||
|
request.addfinalizer(delete_test_ndbm)
|
||||||
|
return db_name+".db"
|
||||||
|
|
||||||
@pytest.fixture(scope = "function")
|
@pytest.fixture(scope = "function")
|
||||||
def make_dumbdbm_test_db(request):
|
def make_dumbdbm_test_db(request):
|
||||||
db_name ="test_dumbdbm"
|
db_name ="test_dumbdbm"
|
||||||
@ -67,9 +83,11 @@ def make_dumbdbm_test_db(request):
|
|||||||
request.addfinalizer(delete_test_dumbdbm)
|
request.addfinalizer(delete_test_dumbdbm)
|
||||||
return db_name
|
return db_name
|
||||||
|
|
||||||
# def test_fixture(make_ndbm_test_db):
|
|
||||||
# print "runing test_fixture with"
|
|
||||||
# assert whichdb(make_ndbm_test_db) == "dbm"
|
def test_fixture(make_ndbm_test_db):
|
||||||
|
print "runing test_fixture with"
|
||||||
|
assert whichdb(make_ndbm_test_db) == ndbm_type
|
||||||
|
|
||||||
def test_assert_gdbm_db_is_created_and_correctly_identified(make_gdbm_test_db):
|
def test_assert_gdbm_db_is_created_and_correctly_identified(make_gdbm_test_db):
|
||||||
print "runing assert_gdbm_db_is_created_and_correctly_identified with gdbm test file"
|
print "runing assert_gdbm_db_is_created_and_correctly_identified with gdbm test file"
|
||||||
@ -93,6 +111,9 @@ def test_assert_reading_dumbdbm_correctly(make_dumbdbm_test_db):
|
|||||||
assert db.has_key(key1)
|
assert db.has_key(key1)
|
||||||
assert db[key1] == val1
|
assert db[key1] == val1
|
||||||
|
|
||||||
|
|
||||||
|
#########################
|
||||||
|
|
||||||
def test_dumpanydbm_identify_gdbm(make_gdbm_test_db):
|
def test_dumpanydbm_identify_gdbm(make_gdbm_test_db):
|
||||||
print "running test_dumpanydbm_identify_gdbm"
|
print "running test_dumpanydbm_identify_gdbm"
|
||||||
output = subprocess.check_output(["dump-anydbm", make_gdbm_test_db])
|
output = subprocess.check_output(["dump-anydbm", make_gdbm_test_db])
|
||||||
@ -113,6 +134,29 @@ def test_dumpanydbm_identify_gdbm(make_gdbm_test_db):
|
|||||||
assert db_dump_second_pair[0] == key2
|
assert db_dump_second_pair[0] == key2
|
||||||
assert db_dump_second_pair[1] == val2
|
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 output
|
||||||
|
|
||||||
|
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
|
||||||
|
assert which == ndbm_type
|
||||||
|
|
||||||
|
#split remaining lines on ':' that separates key & value
|
||||||
|
db_dump_first_pair = output[1].split(':')
|
||||||
|
assert db_dump_first_pair[0] == key1
|
||||||
|
assert db_dump_first_pair[1] == val1
|
||||||
|
|
||||||
|
db_dump_second_pair = output[2].split(':')
|
||||||
|
assert db_dump_second_pair[0] == key2
|
||||||
|
assert db_dump_second_pair[1] == val2
|
||||||
|
|
||||||
def test_dumpanydbm_identify_dumbdbm(make_dumbdbm_test_db):
|
def test_dumpanydbm_identify_dumbdbm(make_dumbdbm_test_db):
|
||||||
print "running test_dumpanydbm_identify_dumbdbm"
|
print "running test_dumpanydbm_identify_dumbdbm"
|
||||||
output = subprocess.call(["dump-anydbm", make_dumbdbm_test_db])
|
output = subprocess.call(["dump-anydbm", make_dumbdbm_test_db])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user