-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
import sys | ||
try: | ||
import unittest2 as unittest | ||
except ImportError: | ||
import unittest | ||
|
||
|
||
top_level = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) | ||
start_dir = os.path.join(top_level, 'tests') | ||
if not top_level in sys.path: | ||
sys.path.insert(0, top_level) | ||
|
||
|
||
sys.path.append(start_dir) | ||
|
||
|
||
class Program(unittest.TestProgram): | ||
def createTests(self): | ||
if self.testNames is None: | ||
self.test = self.testLoader.discover( | ||
start_dir=start_dir, | ||
pattern='test_*.py', | ||
top_level_dir=top_level) | ||
else: | ||
self.test = self.testLoader.loadTestsFromNames(self.testNames) | ||
|
||
Program() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import contextlib | ||
import os | ||
import shutil | ||
import tempfile | ||
|
||
try: | ||
import unittest2 as unittest | ||
except ImportError: | ||
import unittest | ||
|
||
from file_archive import FileStore | ||
from file_archive.errors import CreationError | ||
|
||
|
||
@contextlib.contextmanager | ||
def temp_dir(make=True): | ||
path = tempfile.mkdtemp(prefix='test_file_archive_') | ||
try: | ||
if make: | ||
yield path | ||
else: | ||
yield path + 'internal' | ||
finally: | ||
shutil.rmtree(path) | ||
|
||
|
||
class TestCreate(unittest.TestCase): | ||
"""Tests the creation of a new file store on disk. | ||
""" | ||
def test_create(self): | ||
with temp_dir(False) as d: | ||
FileStore.create_store(d) | ||
self.assertTrue(os.path.isdir(d)) | ||
self.assertTrue(os.path.isfile(os.path.join(d, 'database'))) | ||
with temp_dir(True) as d: | ||
FileStore.create_store(d) | ||
self.assertTrue(os.path.isfile(os.path.join(d, 'database'))) | ||
|
||
def test_create_nonempty(self): | ||
with temp_dir() as d: | ||
with open(os.path.join(d, 'somefile'), 'wb') as fp: | ||
fp.write("I'm not empty\n") | ||
with self.assertRaises(CreationError): | ||
FileStore.create_store(d) | ||
with temp_dir() as d: | ||
FileStore.create_store(d) | ||
with self.assertRaises(CreationError): | ||
FileStore.create_store(d) |