diff options
author | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-02-13 00:23:56 -0500 |
---|---|---|
committer | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-02-13 00:23:56 -0500 |
commit | c57e798b5d92d27d0ad80bf068c09942f8cc052a (patch) | |
tree | 3f6b3a56c295f23108e6560b517f158adc5e14f8 /tests/silo_test.py | |
parent | ef3c1cf874e4eb85e9c22dbf127b9d13c7e8fb77 (diff) |
tests/silo_test.py: re-wrote it.
Now the test is in a Test class with proper setup and teardown methods.
Diffstat (limited to 'tests/silo_test.py')
-rw-r--r-- | tests/silo_test.py | 103 |
1 files changed, 58 insertions, 45 deletions
diff --git a/tests/silo_test.py b/tests/silo_test.py index 0f1558f..24ac5d9 100644 --- a/tests/silo_test.py +++ b/tests/silo_test.py @@ -24,64 +24,77 @@ from os import path, remove from combox.silo import ComboxSilo from combox.file import read_file, write_file -CONFIG_DIR = path.join('tests', 'test-config') +from tests.utils import get_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) +class TestSilo(object): + """ + Class that tests the silo.py module. + """ + @classmethod + def setup_class(self): + """Set things up.""" -FILES_DIR = path.abspath(config['combox_dir']) -LOREM = path.join(FILES_DIR,'lorem.txt') -LOREM_IPSUM = path.join(FILES_DIR,'lorem-ipsum.txt') -IPSUM = path.join(FILES_DIR,'ipsum.txt') + self.config = get_config() + self.FILES_DIR = self.config['combox_dir'] + self.LOREM = path.join(self.FILES_DIR,'lorem.txt') + self.IPSUM = path.join(self.FILES_DIR,'ipsum.txt') + self.LOREM_IPSUM = path.join(self.FILES_DIR,'lorem-ipsum.txt') -def test_csilo(): - """ - Tests the ComboxSilo class. - """ - csilo = ComboxSilo(config) + def test_csilo(self): + """ + Tests the ComboxSilo class. + """ + csilo = ComboxSilo(self.config) + + # Test - update + csilo.update(self.LOREM) + lorem_content = read_file(self.LOREM) + lorem_hash = csilo.db.get(self.LOREM) + assert lorem_hash + + csilo.update(self.IPSUM) + ipsum_content = read_file(self.IPSUM) + ipsum_hash = csilo.db.get(self.IPSUM) + assert ipsum_hash - # Test - update - csilo.update(LOREM) - lorem_content = read_file(LOREM) - lorem_hash = csilo.db.get(LOREM) - assert lorem_hash + lorem_ipsum_content = "%s\n%s" % (lorem_content, + ipsum_content) + write_file(self.LOREM_IPSUM, lorem_ipsum_content) - csilo.update(IPSUM) - ispum_content = read_file(IPSUM) - ipsum_hash = csilo.db.get(IPSUM) - assert ipsum_hash + csilo.update(self.LOREM_IPSUM) + lorem_ipsum_hash = csilo.db.get(self.LOREM_IPSUM) + assert lorem_ipsum_hash - lorem_ipsum_content = "%s\n%s" % (LOREM, IPSUM) - write_file(LOREM_IPSUM, lorem_ipsum_content) + assert lorem_ipsum_hash != lorem_hash + assert lorem_ipsum_hash != ipsum_hash - csilo.update(LOREM_IPSUM) - lorem_ipsum_hash = csilo.db.get(LOREM_IPSUM) - assert lorem_ipsum_hash + # Test - stale + lorem_ipsum_content = "%s\n%s" % (lorem_ipsum_content, + ipsum_content) + write_file(self.LOREM_IPSUM, lorem_ipsum_content) - assert lorem_ipsum_hash != lorem_hash - assert lorem_ipsum_hash != ipsum_hash + assert csilo.stale(self.LOREM_IPSUM) + csilo.update(self.LOREM_IPSUM) + assert csilo.stale(self.LOREM_IPSUM) is False - # Test - stale - lorem_ipsum_content = "%s\n%s" % (lorem_ipsum_content, IPSUM) - write_file(LOREM_IPSUM, lorem_ipsum_content) + lorem_ipsum_hash_new = csilo.db.get(self.LOREM_IPSUM) + assert lorem_ipsum_hash_new + assert lorem_ipsum_hash_new != lorem_ipsum_hash - assert csilo.stale(LOREM_IPSUM) - csilo.update(LOREM_IPSUM) - assert csilo.stale(LOREM_IPSUM) is False + # Test - remove + remove(self.LOREM_IPSUM) + csilo.remove(self.LOREM_IPSUM) - lorem_ipsum_hash_new = csilo.db.get(LOREM_IPSUM) - assert lorem_ipsum_hash_new - assert lorem_ipsum_hash_new != lorem_ipsum_hash + # Test - exists + assert not csilo.exists(self.LOREM_IPSUM) - # Test - remove - remove(LOREM_IPSUM) - csilo.remove(LOREM_IPSUM) - # Test - exists - assert not csilo.exists(LOREM_IPSUM) + @classmethod + def teardown_class(self): + """Purge the mess created by this test""" + csilo = ComboxSilo(self.config) + csilo.remove(self.LOREM) + csilo.remove(self.IPSUM) |