Skip to content

Commit

Permalink
Add tests for index creation, open and format
Browse files Browse the repository at this point in the history
  • Loading branch information
emi80 committed Apr 24, 2014
1 parent 63d203e commit 4719e2f
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions test/test_index.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,69 @@
"""Unit test for the Index class"""
import pytest
import indexfile
from indexfile.index import Index


def test_create_empty():
"""Create empty index"""
i = Index()
assert i is not None
assert i.format == indexfile.default_format
assert len(i) == 0


def test_create_empty_w_format():
"""Create empty index with custom format"""
form = {
"id": "labExpId",
"colsep": "\t",
"fileinfo": [
"path",
"size",
"md5"
],
"kw_sep": " ",
"sep": "=",
"trail": ";"
}
i = Index(format=form)
assert i is not None
assert i.format != indexfile.default_format
assert len(i) == 0


def test_set_format_string():
"""Test set format with JSON string"""
form = '''{
"id": "labExpId",
"colsep": "\\t",
"fileinfo": [
"path",
"size",
"md5"
],
"kw_sep": " ",
"sep": "=",
"trail": ";"
}'''
i = Index()
assert i is not None
assert i.format == indexfile.default_format
i.set_format(form)
assert i.format
assert i.format != indexfile.default_format


def test_set_format_file():
"""Test set format with file path"""
i = Index()
assert i is not None
assert i.format == indexfile.default_format
i.set_format('test/data/format.json')
assert i.format
assert i.format != indexfile.default_format


def test_open_empty():
"""Open empty index"""
i = Index()
Expand All @@ -32,6 +86,26 @@ def test_load_existing():
assert len(i) == 36


def test_open_string():
"""Test open with string parameter"""
i = Index()
assert i is not None
i.set_format('test/data/format.json')
i.open('test/data/index.txt')
assert len(i) == 36


def test_open_file():
"""Test open with file parameter"""
i = Index()
assert i is not None
i.set_format('test/data/format.json')
f = open('test/data/index.txt','r')
i.open(f)
f.close()
assert len(i) == 36


def test_replicates():
"""Test merged datasets"""
i = Index('test/data/index.txt')
Expand Down

0 comments on commit 4719e2f

Please sign in to comment.