From 04fcb42338b008199dbe328335ee65a61af45a50 Mon Sep 17 00:00:00 2001 From: Fabien Benureau Date: Thu, 4 Jul 2013 18:31:21 +0100 Subject: [PATCH] tests can be run from root dir --- tests/test_usecase.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/tests/test_usecase.py b/tests/test_usecase.py index 8226a3b..213fbf1 100644 --- a/tests/test_usecase.py +++ b/tests/test_usecase.py @@ -65,13 +65,15 @@ def _create_fake_fs(): def _copy_data(fs): """Copy all the data directory into the fake fs""" - for filename in real_os.listdir('data/'): - filepath = 'data/' + filename - if real_os.path.isfile(filepath): - with real_open(filepath, 'r') as f: - fs.CreateFile(filepath, contents = f.read()) - if real_os.path.isdir(filepath): - fs.CreateDirectory(filepath) + datadir = real_os.path.join(real_os.path.dirname(__file__), 'data') + for filename in real_os.listdir(datadir): + real_path = real_os.path.join(datadir, filename) + fake_path = fake_os.path.join('data', filename) + if real_os.path.isfile(real_path): + with real_open(real_path, 'r') as f: + fs.CreateFile(fake_path, contents = f.read()) + if real_os.path.isdir(real_path): + fs.CreateDirectory(fake_path) # redirecting output @@ -142,6 +144,7 @@ def _execute_cmds(cmds, fs = None): fs = _create_fake_fs() _copy_data(fs) + outs = [] for cmd in cmds: if hasattr(cmd, '__iter__'): @@ -287,19 +290,20 @@ class TestUsecase(unittest.TestCase): _execute_cmds(cmds) - def test_editor(self): + def test_editor_abort(self): with self.assertRaises(SystemExit): cmds = ['papers init', ('papers add', ['abc', 'n']) ] - - _execute_cmds(cmds) + _execute_cmds(cmds) -# if __name__ == "__main__": -# cmds = ['papers init', -# 'papers add', ['', 'n']] -# -# _execute_cmds(cmds) - + # def test_editor_success(self): + # with real_open('data/', 'r') + # + # cmds = ['papers init', + # ('papers add', ['abc', 'n']) + # ] + # + # _execute_cmds(cmds)