From 8d68bf0c360161e8813b3a7187628274d2d9ed3f Mon Sep 17 00:00:00 2001 From: Siddharth Ravikumar Date: Tue, 13 Jan 2015 14:05:56 -0500 Subject: 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 --- tests/file_test.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'tests/file_test.py') 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 # . +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) -- cgit v1.2.3