cleaned up tests and removed unnecessary testing of fixtures. Only test of dump-anydbm remain

This commit is contained in:
Kelsey Hawley 2013-12-18 21:17:41 -08:00
parent 43158fdce2
commit f8549f69cc

View File

@ -1,6 +1,5 @@
#!/usr/bin/env python
#from warcprox.bin import dump-anydbm
import pytest
import os
import subprocess # to access the script from shell
@ -55,8 +54,8 @@ def make_ndbm_test_db(request):
db_name = "test_ndbm"
print "creating", db_name
test_db = ndbm.open(db_name, "n")
test_db['very first key'] = 'very first value'
test_db['second key'] = 'second value'
test_db[key1] = val1
test_db[key2] = val2
test_db.close()
def delete_test_ndbm():
print "deleting", db_name
@ -82,37 +81,6 @@ def make_dumbdbm_test_db(request):
request.addfinalizer(delete_test_dumbdbm)
return db_name
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):
print "runing assert_gdbm_db_is_created_and_correctly_identified with gdbm test file"
assert whichdb(make_gdbm_test_db) == gdbm_type
def test_assert_reading_gdbm_correctly(make_gdbm_test_db):
print "running assert_reading_gdbm_correctly with gdbm test db"
db = gdbm.open(make_gdbm_test_db, "r")
assert len(db.keys()) == 2
assert db.has_key(key1)
assert db[key1] == val1
def test_assert_dumbdbm_db_is_created_and_correctly_identified(make_dumbdbm_test_db):
print "runing assert_dumbdbm_db_is_created_and_correctly_identified with gdbm test file"
assert whichdb(make_dumbdbm_test_db) == dumb_type
def test_assert_reading_dumbdbm_correctly(make_dumbdbm_test_db):
print "running assert_reading_dumbdbm_correctly with dumbdbm test db"
db = dumb.open(make_dumbdbm_test_db, "r")
assert len(db.keys()) == 2
assert db.has_key(key1)
assert db[key1] == val1
#########################
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])
@ -138,8 +106,6 @@ def test_dumpanydbm_identify_ndbm(make_ndbm_test_db):
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
@ -158,9 +124,22 @@ def test_dumpanydbm_identify_ndbm(make_ndbm_test_db):
def test_dumpanydbm_identify_dumbdbm(make_dumbdbm_test_db):
print "running test_dumpanydbm_identify_dumbdbm"
output = subprocess.call(["dump-anydbm", make_dumbdbm_test_db])
# output = output.strip().split("\n")
assert output != 0 # unable to read dumbdbm, so dump-anydbm exits with error
output = subprocess.check_output(["dump-anydbm", make_dumbdbm_test_db])
output = output.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
assert which == dumb_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