fake editor_input
This commit is contained in:
parent
e0fd19f9d8
commit
cc3928ef4b
@ -47,7 +47,7 @@ def command(args):
|
|||||||
question='Invalid bibfile. Edit again ?',
|
question='Invalid bibfile. Edit again ?',
|
||||||
default='y')
|
default='y')
|
||||||
if not cont:
|
if not cont:
|
||||||
ui.exit()
|
ui.exit(0)
|
||||||
p = Paper(bibentry=bib, citekey=key)
|
p = Paper(bibentry=bib, citekey=key)
|
||||||
else:
|
else:
|
||||||
p = Paper.load(bibfile)
|
p = Paper.load(bibfile)
|
||||||
|
@ -8,7 +8,7 @@ import fake_filesystem_shutil
|
|||||||
import fake_filesystem_glob
|
import fake_filesystem_glob
|
||||||
|
|
||||||
from papers import papers_cmd
|
from papers import papers_cmd
|
||||||
from papers import color
|
from papers import color, files
|
||||||
from papers.p3 import io, input
|
from papers.p3 import io, input
|
||||||
|
|
||||||
|
|
||||||
@ -43,8 +43,13 @@ def _create_fake_fs():
|
|||||||
fake_glob = fake_filesystem_glob.FakeGlobModule(fake_fs)
|
fake_glob = fake_filesystem_glob.FakeGlobModule(fake_fs)
|
||||||
|
|
||||||
fake_fs.CreateDirectory(fake_os.path.expanduser('~'))
|
fake_fs.CreateDirectory(fake_os.path.expanduser('~'))
|
||||||
__builtins__['open'] = fake_open
|
|
||||||
__builtins__['file'] = fake_open
|
try:
|
||||||
|
__builtins__.open = fake_open
|
||||||
|
__builtins__.file = fake_open
|
||||||
|
except AttributeError:
|
||||||
|
__builtins__['open'] = fake_open
|
||||||
|
__builtins__['file'] = fake_open
|
||||||
|
|
||||||
sys.modules['os'] = fake_os
|
sys.modules['os'] = fake_os
|
||||||
sys.modules['shutil'] = fake_shutil
|
sys.modules['shutil'] = fake_shutil
|
||||||
@ -53,6 +58,8 @@ def _create_fake_fs():
|
|||||||
for mdname, md in mod_list:
|
for mdname, md in mod_list:
|
||||||
md.os = fake_os
|
md.os = fake_os
|
||||||
md.shutil = fake_shutil
|
md.shutil = fake_shutil
|
||||||
|
md.open = fake_open
|
||||||
|
md.file = fake_open
|
||||||
|
|
||||||
return fake_fs
|
return fake_fs
|
||||||
|
|
||||||
@ -152,7 +159,7 @@ def _execute_cmds(cmds, fs = None):
|
|||||||
assert type(cmd) == str
|
assert type(cmd) == str
|
||||||
_, stdout, stderr = redirect(papers_cmd.execute)(cmd.split())
|
_, stdout, stderr = redirect(papers_cmd.execute)(cmd.split())
|
||||||
|
|
||||||
print stderr
|
assert(stderr.getvalue() == '')
|
||||||
outs.append(color.undye(stdout.getvalue()))
|
outs.append(color.undye(stdout.getvalue()))
|
||||||
|
|
||||||
return outs
|
return outs
|
||||||
@ -210,7 +217,7 @@ class TestInput(unittest.TestCase):
|
|||||||
with self.assertRaises(IndexError):
|
with self.assertRaises(IndexError):
|
||||||
input()
|
input()
|
||||||
|
|
||||||
def test_input(self):
|
def test_input2(self):
|
||||||
other_input = FakeInput(['yes', 'no'])
|
other_input = FakeInput(['yes', 'no'])
|
||||||
other_input.as_global()
|
other_input.as_global()
|
||||||
self.assertEqual(color.input(), 'yes')
|
self.assertEqual(color.input(), 'yes')
|
||||||
@ -218,6 +225,14 @@ class TestInput(unittest.TestCase):
|
|||||||
with self.assertRaises(IndexError):
|
with self.assertRaises(IndexError):
|
||||||
color.input()
|
color.input()
|
||||||
|
|
||||||
|
def test_editor_input(self):
|
||||||
|
other_input = FakeInput(['yes', 'no'])
|
||||||
|
other_input.as_global()
|
||||||
|
self.assertEqual(files.editor_input(), 'yes')
|
||||||
|
self.assertEqual(files.editor_input(), 'no')
|
||||||
|
with self.assertRaises(IndexError):
|
||||||
|
color.input()
|
||||||
|
|
||||||
|
|
||||||
class TestUsecase(unittest.TestCase):
|
class TestUsecase(unittest.TestCase):
|
||||||
|
|
||||||
@ -272,4 +287,19 @@ class TestUsecase(unittest.TestCase):
|
|||||||
|
|
||||||
_execute_cmds(cmds)
|
_execute_cmds(cmds)
|
||||||
|
|
||||||
|
def test_editor(self):
|
||||||
|
|
||||||
|
with self.assertRaises(SystemExit):
|
||||||
|
cmds = ['papers init',
|
||||||
|
('papers add', ['abc', 'n'])
|
||||||
|
]
|
||||||
|
|
||||||
|
_execute_cmds(cmds)
|
||||||
|
|
||||||
|
|
||||||
|
# if __name__ == "__main__":
|
||||||
|
# cmds = ['papers init',
|
||||||
|
# 'papers add', ['', 'n']]
|
||||||
|
#
|
||||||
|
# _execute_cmds(cmds)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user