mirror of
https://github.com/internetarchive/warcprox.git
synced 2025-01-18 13:22:09 +01:00
updated file to PEP 8, as editor was complaining, and tabs are generally bad
This commit is contained in:
parent
39fb1c75ba
commit
4b0ab0ff72
@ -5,28 +5,28 @@ import os
|
|||||||
import subprocess # to access the script from shell
|
import subprocess # to access the script from shell
|
||||||
|
|
||||||
# will try as python 3 then default to python 2 modules
|
# will try as python 3 then default to python 2 modules
|
||||||
try:
|
try:
|
||||||
import dbm
|
import dbm
|
||||||
from dbm import ndbm
|
from dbm import ndbm
|
||||||
from dbm import gnu as gdbm
|
from dbm import gnu as gdbm
|
||||||
from dbm import dumb
|
from dbm import dumb
|
||||||
|
|
||||||
whichdb = dbm.whichdb
|
whichdb = dbm.whichdb
|
||||||
|
|
||||||
ndbm_type = "dbm.ndbm"
|
ndbm_type = "dbm.ndbm"
|
||||||
gdbm_type = "dbm.gnu"
|
gdbm_type = "dbm.gnu"
|
||||||
dumb_type = "dbm.dumb"
|
dumb_type = "dbm.dumb"
|
||||||
|
|
||||||
except:
|
except:
|
||||||
import dbm as ndbm
|
import dbm as ndbm
|
||||||
import gdbm
|
import gdbm
|
||||||
import dumbdbm as dumb
|
import dumbdbm as dumb
|
||||||
|
|
||||||
from whichdb import whichdb
|
from whichdb import whichdb
|
||||||
|
|
||||||
ndbm_type = "dbm"
|
ndbm_type = "dbm"
|
||||||
gdbm_type = "gdbm"
|
gdbm_type = "gdbm"
|
||||||
dumb_type = "dumbdbm"
|
dumb_type = "dumbdbm"
|
||||||
|
|
||||||
#global settings
|
#global settings
|
||||||
key1 = 'very first key'
|
key1 = 'very first key'
|
||||||
@ -35,111 +35,120 @@ val1 = 'very first value'
|
|||||||
val2 = 'second value'
|
val2 = 'second value'
|
||||||
dump_anydbm = "dump-anydbm"
|
dump_anydbm = "dump-anydbm"
|
||||||
|
|
||||||
@pytest.fixture(scope = "function")
|
|
||||||
|
@pytest.fixture(scope="function")
|
||||||
def make_gdbm_test_db(request):
|
def make_gdbm_test_db(request):
|
||||||
db_name ="test_gdbm"
|
db_name = "test_gdbm"
|
||||||
print("creating", db_name)
|
print("creating", db_name)
|
||||||
test_db = gdbm.open(db_name, "n")
|
test_db = gdbm.open(db_name, "n")
|
||||||
test_db[key1] = val1
|
test_db[key1] = val1
|
||||||
test_db[key2] = val2
|
test_db[key2] = val2
|
||||||
test_db.close()
|
test_db.close()
|
||||||
def delete_test_dumbdbm():
|
|
||||||
print("deleting", db_name)
|
|
||||||
os.remove(db_name)
|
|
||||||
|
|
||||||
request.addfinalizer(delete_test_dumbdbm)
|
def delete_test_dumbdbm():
|
||||||
return db_name
|
print("deleting", db_name)
|
||||||
|
os.remove(db_name)
|
||||||
|
|
||||||
@pytest.fixture(scope = "function")
|
request.addfinalizer(delete_test_dumbdbm)
|
||||||
|
return db_name
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="function")
|
||||||
def make_ndbm_test_db(request):
|
def make_ndbm_test_db(request):
|
||||||
db_name = "test_ndbm"
|
db_name = "test_ndbm"
|
||||||
print("creating", db_name)
|
print("creating", db_name)
|
||||||
test_db = ndbm.open(db_name, "n")
|
test_db = ndbm.open(db_name, "n")
|
||||||
test_db[key1] = val1
|
test_db[key1] = val1
|
||||||
test_db[key2] = val2
|
test_db[key2] = val2
|
||||||
test_db.close()
|
test_db.close()
|
||||||
def delete_test_ndbm():
|
|
||||||
print("deleting", db_name)
|
|
||||||
os.remove(db_name+".db")
|
|
||||||
|
|
||||||
request.addfinalizer(delete_test_ndbm)
|
def delete_test_ndbm():
|
||||||
return db_name
|
print("deleting", db_name)
|
||||||
|
os.remove(db_name + ".db")
|
||||||
|
|
||||||
@pytest.fixture(scope = "function")
|
request.addfinalizer(delete_test_ndbm)
|
||||||
|
return db_name
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="function")
|
||||||
def make_dumbdbm_test_db(request):
|
def make_dumbdbm_test_db(request):
|
||||||
db_name ="test_dumbdbm"
|
db_name = "test_dumbdbm"
|
||||||
print("creating", db_name)
|
print("creating", db_name)
|
||||||
test_db = dumb.open(db_name, "n")
|
test_db = dumb.open(db_name, "n")
|
||||||
test_db[key1] = val1
|
test_db[key1] = val1
|
||||||
test_db[key2] = val2
|
test_db[key2] = val2
|
||||||
test_db.close()
|
test_db.close()
|
||||||
def delete_test_dumbdbm():
|
|
||||||
print("deleting", db_name)
|
def delete_test_dumbdbm():
|
||||||
os.remove(db_name+".dir")
|
print("deleting", db_name)
|
||||||
os.remove(db_name+".bak")
|
os.remove(db_name + ".dir")
|
||||||
os.remove(db_name+".dat")
|
os.remove(db_name + ".bak")
|
||||||
|
os.remove(db_name + ".dat")
|
||||||
|
|
||||||
|
request.addfinalizer(delete_test_dumbdbm)
|
||||||
|
return db_name
|
||||||
|
|
||||||
request.addfinalizer(delete_test_dumbdbm)
|
|
||||||
return db_name
|
|
||||||
|
|
||||||
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])
|
||||||
output = output.decode(encoding = 'UTF-8').strip().split("\n")
|
output = output.decode(encoding='UTF-8').strip().split("\n")
|
||||||
assert len(output) == 3 # 2 keys plus whichdb line
|
assert len(output) == 3 # 2 keys plus whichdb line
|
||||||
|
|
||||||
# split on space, then grab 4th word, which is db type
|
# split on space, then grab 4th word, which is db type
|
||||||
which = output[0].split(' ')[3]
|
which = output[0].split(' ')[3]
|
||||||
print(which)
|
print(which)
|
||||||
assert which == gdbm_type
|
assert which == gdbm_type
|
||||||
|
|
||||||
#split remaining lines on ':' that separates key & value
|
#split remaining lines on ':' that separates key & value
|
||||||
db_dump_first_pair = output[1].split(':')
|
db_dump_first_pair = output[1].split(':')
|
||||||
assert db_dump_first_pair[0] == key1
|
assert db_dump_first_pair[0] == key1
|
||||||
assert db_dump_first_pair[1] == val1
|
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
|
||||||
|
|
||||||
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_ndbm(make_ndbm_test_db):
|
def test_dumpanydbm_identify_ndbm(make_ndbm_test_db):
|
||||||
print("running test_dumpanydbm_identify_ndbm")
|
print("running test_dumpanydbm_identify_ndbm")
|
||||||
output = subprocess.check_output([dump_anydbm, make_ndbm_test_db])
|
output = subprocess.check_output([dump_anydbm, make_ndbm_test_db])
|
||||||
output = output.decode(encoding = 'UTF-8').strip().split("\n")
|
output = output.decode(encoding='UTF-8').strip().split("\n")
|
||||||
|
|
||||||
assert len(output) == 3 # 2 keys plus whichdb line
|
assert len(output) == 3 # 2 keys plus whichdb line
|
||||||
|
|
||||||
# split on space, then grab 4th word, which is db type
|
# split on space, then grab 4th word, which is db type
|
||||||
which = output[0].split(' ')[3]
|
which = output[0].split(' ')[3]
|
||||||
print(which)
|
print(which)
|
||||||
assert which == ndbm_type
|
assert which == ndbm_type
|
||||||
|
|
||||||
#split remaining lines on ':' that separates key & value
|
#split remaining lines on ':' that separates key & value
|
||||||
db_dump_first_pair = output[1].split(':')
|
db_dump_first_pair = output[1].split(':')
|
||||||
assert db_dump_first_pair[0] == key1
|
assert db_dump_first_pair[0] == key1
|
||||||
assert db_dump_first_pair[1] == val1
|
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
|
||||||
|
|
||||||
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.check_output([dump_anydbm, make_dumbdbm_test_db])
|
output = subprocess.check_output([dump_anydbm, make_dumbdbm_test_db])
|
||||||
output = output.decode(encoding = 'UTF-8').strip().split("\n")
|
output = output.decode(encoding='UTF-8').strip().split("\n")
|
||||||
assert len(output) == 3 # 2 keys plus whichdb line
|
assert len(output) == 3 # 2 keys plus whichdb line
|
||||||
print(output)
|
print(output)
|
||||||
|
|
||||||
# split on space, then grab 4th word, which is db type
|
# split on space, then grab 4th word, which is db type
|
||||||
which = output[0].split(' ')[3]
|
which = output[0].split(' ')[3]
|
||||||
print(which)
|
print(which)
|
||||||
assert which == dumb_type
|
assert which == dumb_type
|
||||||
|
|
||||||
#split remaining lines on ':' that separates key & value
|
#split remaining lines on ':' that separates key & value
|
||||||
db_dump_first_pair = output[1].split(':')
|
db_dump_first_pair = output[1].split(':')
|
||||||
assert db_dump_first_pair[0] == key1
|
assert db_dump_first_pair[0] == key1
|
||||||
assert db_dump_first_pair[1] == val1
|
assert db_dump_first_pair[1] == val1
|
||||||
|
|
||||||
db_dump_second_pair = output[2].split(':')
|
db_dump_second_pair = output[2].split(':')
|
||||||
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user