tests can be run from root dir

main
Fabien Benureau 12 years ago
parent 3b7900a3a4
commit 04fcb42338

@ -65,13 +65,15 @@ def _create_fake_fs():
def _copy_data(fs): def _copy_data(fs):
"""Copy all the data directory into the fake fs""" """Copy all the data directory into the fake fs"""
for filename in real_os.listdir('data/'): datadir = real_os.path.join(real_os.path.dirname(__file__), 'data')
filepath = 'data/' + filename for filename in real_os.listdir(datadir):
if real_os.path.isfile(filepath): real_path = real_os.path.join(datadir, filename)
with real_open(filepath, 'r') as f: fake_path = fake_os.path.join('data', filename)
fs.CreateFile(filepath, contents = f.read()) if real_os.path.isfile(real_path):
if real_os.path.isdir(filepath): with real_open(real_path, 'r') as f:
fs.CreateDirectory(filepath) fs.CreateFile(fake_path, contents = f.read())
if real_os.path.isdir(real_path):
fs.CreateDirectory(fake_path)
# redirecting output # redirecting output
@ -142,6 +144,7 @@ def _execute_cmds(cmds, fs = None):
fs = _create_fake_fs() fs = _create_fake_fs()
_copy_data(fs) _copy_data(fs)
outs = [] outs = []
for cmd in cmds: for cmd in cmds:
if hasattr(cmd, '__iter__'): if hasattr(cmd, '__iter__'):
@ -287,7 +290,7 @@ class TestUsecase(unittest.TestCase):
_execute_cmds(cmds) _execute_cmds(cmds)
def test_editor(self): def test_editor_abort(self):
with self.assertRaises(SystemExit): with self.assertRaises(SystemExit):
cmds = ['papers init', cmds = ['papers init',
@ -296,10 +299,11 @@ class TestUsecase(unittest.TestCase):
_execute_cmds(cmds) _execute_cmds(cmds)
# def test_editor_success(self):
# if __name__ == "__main__": # with real_open('data/', 'r')
# cmds = ['papers init', #
# 'papers add', ['', 'n']] # cmds = ['papers init',
# # ('papers add', ['abc', 'n'])
# _execute_cmds(cmds) # ]
#
# _execute_cmds(cmds)

Loading…
Cancel
Save