summaryrefslogtreecommitdiffstats
path: root/tests/file_test.py
diff options
context:
space:
mode:
authorSiddharth Ravikumar <sravik@bgsu.edu>2015-01-13 14:05:56 -0500
committerSiddharth Ravikumar <sravik@bgsu.edu>2015-01-13 14:05:56 -0500
commit8d68bf0c360161e8813b3a7187628274d2d9ed3f (patch)
tree309ae9fb69c68eb71fb91188149ec17fd4706f0b /tests/file_test.py
parent60fe856e6fd0aeb4c8b8936c59bdf7434adf4b41 (diff)
rewrote the read_shards() and write_shards() function in combox/file.py.
Tests were accordingly modded and now use the test config.yaml to split and write shards to dirs. modified: combox/file.py modified: tests/crypto_test.py modified: tests/file_test.py
Diffstat (limited to 'tests/file_test.py')
-rw-r--r--tests/file_test.py35
1 files changed, 23 insertions, 12 deletions
diff --git a/tests/file_test.py b/tests/file_test.py
index e418dfc..321533b 100644
--- a/tests/file_test.py
+++ b/tests/file_test.py
@@ -16,6 +16,8 @@
# along with Combox (see COPYING). If not, see
# <http://www.gnu.org/licenses/>.
+import yaml
+
from glob import glob
from nose.tools import *
from os import path, remove
@@ -23,7 +25,16 @@ from os import path, remove
from combox.file import (split_data, glue_data, write_file,
read_file, write_shards, read_shards)
-FILES_DIR = path.join('tests','files')
+CONFIG_DIR = path.join('tests', 'test-config')
+
+config_file = path.join(CONFIG_DIR, 'config.yaml')
+try:
+ config = yaml.load(file(config_file, 'r'))
+except yaml.YAMLError, exc:
+ raise AssertionError("Error in configuration file:", exc)
+
+
+FILES_DIR = config['combox_dir']
TEST_FILE = path.join(FILES_DIR,'the-red-star.jpg')
def test_split():
@@ -47,26 +58,26 @@ def test_shards():
and check if they're the same as the orginal file.
"""
- SHARDS = 5
+ # no. of shards = no. of nodes
+ SHARDS = len(config['nodes_info'].keys())
+
f = path.abspath(TEST_FILE)
f_content = read_file(f)
f_shards = split_data(f_content, SHARDS)
- f_path = FILES_DIR
+
f_basename = path.basename(f)
- write_shards(f_shards, f_path, f_basename)
+ nodes = [path.abspath(node['path']) for node in config['nodes_info'].itervalues()]
+ write_shards(f_shards, nodes, f_basename)
# check if the shards have been created.
- for i in range(0,SHARDS):
- shard = "%s.shard%s" % (TEST_FILE, i)
+ i = 0
+ for node in nodes:
+ shard = "%s.shard%s" % (path.join(node, f_basename), i)
+ i += 1
assert path.isfile(shard)
- f_shards = read_shards(f_path, f_basename)
+ f_shards = read_shards(nodes, f_basename)
f_content_glued = glue_data(f_shards)
assert f_content == f_content_glued
-
- # remove shards from disk.
- shards = glob("%s.shard*" % TEST_FILE)
- for shard in shards:
- remove(shard)