From 5e2f2be1dd75411c52016769c0ccac2ef7db7286 Mon Sep 17 00:00:00 2001 From: Siddharth Ravikumar Date: Mon, 12 Jan 2015 21:56:48 -0500 Subject: Added `nose' for combox/config.py, combox/crypto.py, combox/file.py new file: tests/config_test.py new file: tests/crypto_test.py new file: tests/file_test.py --- tests/config_test.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/config_test.py (limited to 'tests/config_test.py') diff --git a/tests/config_test.py b/tests/config_test.py new file mode 100644 index 0000000..7bc50c2 --- /dev/null +++ b/tests/config_test.py @@ -0,0 +1,58 @@ +# Copyright (C) 2014 Combox author(s). See AUTHORS. +# +# This file is part of Combox. +# +# Combox is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Combox is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Combox (see COPYING). If not, see +# . + +import yaml + +from nose.tools import * +from os import path, remove, rmdir + +from combox.config import (config_cb, get_secret, get_stdin) + + +CONFIG_DIR = path.join('tests', 'files', 'config') + +# sample config info. +CONFIG_INFO = [CONFIG_DIR, '2', + 'gdrive', 'gdrive/path', '1024', + 'dbox', 'dbox/path', '1024'] + +CONFIG_INFO_ITER = iter(CONFIG_INFO) + +def config_iter(dummy): + "Iterates through CONFIG_INFO" + return next(CONFIG_INFO_ITER) + +def test_config(): + "Tests the combox's config function." + + config_dir = CONFIG_DIR + pass_func = lambda: 'topsecret' + input_func = config_iter + + config_cb(config_dir, pass_func, input_func) + + # check if the config yaml file is valid + 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) + + # remove config dir + remove(config_file) + rmdir(CONFIG_DIR) -- cgit v1.2.3