Skip to content

Commit

Permalink
Adds tests for the remaining functions of pairtree.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ldko committed Apr 3, 2015
1 parent 2aa9c30 commit c561399
Showing 1 changed file with 81 additions and 6 deletions.
87 changes: 81 additions & 6 deletions tests/test_pairtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
TEST_DIR = os.path.dirname(__file__)


STATIC_DIR = os.path.join(TEST_DIR, 'static')


@pytest.mark.parametrize('expected', [
'co/da/pa/+/codapa+',
'co/da/pa/codapa',
Expand Down Expand Up @@ -77,17 +80,89 @@ def test_toPairTreePath():
assert path == 'co/da/^2/22/^3/c^/2b/=^/2c/^7/c/'


def test_create_paired_dir():
def test_create_paired_dir_even():
"""Checks for even directory created."""
static_dir = os.path.join(TEST_DIR, 'static')
os.mkdir(static_dir)
os.mkdir(STATIC_DIR)
try:
new_path = pairtree.create_paired_dir(static_dir,
new_path = pairtree.create_paired_dir(STATIC_DIR,
'coda246',
static=True,
needwebdir=False)
assert new_path == os.path.join(static_dir, 'even/co/da/24/6/coda246')
assert new_path == os.path.join(STATIC_DIR, 'even/co/da/24/6/coda246')
assert os.path.isdir(new_path)
finally:
# make sure we delete the directory created
rmtree(static_dir)
rmtree(STATIC_DIR)


def test_create_paired_dir_odd():
"""Checks for odd directory created."""
os.mkdir(STATIC_DIR)
try:
new_path = pairtree.create_paired_dir(STATIC_DIR,
'coda24a',
static=True,
needwebdir=False)
assert new_path == os.path.join(STATIC_DIR, 'odd/co/da/24/a/coda24a')
assert os.path.isdir(new_path)
finally:
rmtree(STATIC_DIR)


def test_create_paired_dir_web():
"""Checks for web directory created."""
os.mkdir(STATIC_DIR)
try:
new_path = pairtree.create_paired_dir(STATIC_DIR,
'coda242',
static=True,
needwebdir=True)
assert new_path == os.path.join(STATIC_DIR,
'even/co/da/24/2/coda242/web')
assert os.path.isdir(new_path)
finally:
rmtree(STATIC_DIR)


def test_create_paired_dir_meta():
"""Checks regular directory is created in a meta directory."""
meta_dir = os.path.join(TEST_DIR, 'meta')
os.mkdir(meta_dir)
try:
new_path = pairtree.create_paired_dir(meta_dir,
'coda24a',
static=False,
needwebdir=False)
assert new_path == os.path.join(meta_dir, 'co/da/24/a/coda24a')
assert os.path.isdir(new_path)
finally:
rmtree(meta_dir)


def test_add_to_pairtree_all_new():
"""Checks directories are created when all pieces are new."""
os.mkdir(STATIC_DIR)
try:
new_path = pairtree.add_to_pairtree(STATIC_DIR, 'coda253ba')
assert new_path == os.path.join(STATIC_DIR, 'co/da/25/3b/a/')
assert os.path.isdir(new_path)
finally:
rmtree(STATIC_DIR)


def test_add_to_pairtree_some_exist():
"""Checks directories are created when some pieces already exist."""
os.makedirs(os.path.join(STATIC_DIR, 'co/da'))
try:
new_path = pairtree.add_to_pairtree(STATIC_DIR, 'coda253ba')
assert new_path == os.path.join(STATIC_DIR, 'co/da/25/3b/a/')
assert os.path.isdir(new_path)
finally:
rmtree(STATIC_DIR)


def test_get_pairtree_prefix():
"""Checks for correct string from file."""
store_dir = os.path.join(TEST_DIR, 'store/')
prefix = pairtree.get_pairtree_prefix(store_dir)
assert prefix == 'ark:/67531/'

0 comments on commit c561399

Please sign in to comment.