|
|
@ -17,6 +17,7 @@ import dotdot
|
|
|
|
import fake_env
|
|
|
|
import fake_env
|
|
|
|
import mock_requests
|
|
|
|
import mock_requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from pubs import pubs_cmd, color, content, uis, p3, endecoder
|
|
|
|
from pubs import pubs_cmd, color, content, uis, p3, endecoder
|
|
|
|
from pubs.config import conf
|
|
|
|
from pubs.config import conf
|
|
|
|
|
|
|
|
|
|
|
@ -118,14 +119,12 @@ class CommandTestCase(fake_env.TestFakeFs):
|
|
|
|
input.as_global()
|
|
|
|
input.as_global()
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if capture_output:
|
|
|
|
if capture_output:
|
|
|
|
actual_out = self.execute_cmdsplit(
|
|
|
|
actual_out = self.execute_cmd_capture(actual_cmd.split(), expected_out, expected_err)
|
|
|
|
actual_cmd.split(), expected_out, expected_err)
|
|
|
|
|
|
|
|
outs.append(color.undye(actual_out))
|
|
|
|
outs.append(color.undye(actual_out))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
pubs_cmd.execute(actual_cmd.split())
|
|
|
|
pubs_cmd.execute(actual_cmd.split())
|
|
|
|
except fake_env.FakeInput.UnexpectedInput:
|
|
|
|
except fake_env.FakeInput.UnexpectedInput:
|
|
|
|
self.fail('Unexpected input asked by command: {}.'.format(
|
|
|
|
self.fail('Unexpected input asked by command: {}.'.format(actual_cmd))
|
|
|
|
actual_cmd))
|
|
|
|
|
|
|
|
return outs
|
|
|
|
return outs
|
|
|
|
except SystemExit as exc:
|
|
|
|
except SystemExit as exc:
|
|
|
|
exc_class, exc, tb = sys.exc_info()
|
|
|
|
exc_class, exc, tb = sys.exc_info()
|
|
|
@ -145,21 +144,25 @@ class CommandTestCase(fake_env.TestFakeFs):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
return s
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
|
|
|
def execute_cmdsplit(self, actual_cmdlist, expected_out, expected_err):
|
|
|
|
def execute_cmd_capture(self, cmd, expected_out, expected_err):
|
|
|
|
"""Run a single command, which has been split into a list containing cmd and args"""
|
|
|
|
"""Run a single command, captures the output and and stderr and compare it to the expected ones"""
|
|
|
|
capture_wrap = fake_env.capture(pubs_cmd.execute,
|
|
|
|
sys_stdout, sys_stderr = sys.stdout, sys.stderr
|
|
|
|
verbose=PRINT_OUTPUT)
|
|
|
|
sys.stdout = p3._fake_stdio(additional_out=sys_stdout if PRINT_OUTPUT else None)
|
|
|
|
_, stdout, stderr = capture_wrap(actual_cmdlist)
|
|
|
|
sys.stderr = p3._fake_stdio(additional_out=sys_stderr if PRINT_OUTPUT else None)
|
|
|
|
actual_out = self.normalize(stdout)
|
|
|
|
|
|
|
|
actual_err = self.normalize(stderr)
|
|
|
|
try:
|
|
|
|
|
|
|
|
pubs_cmd.execute(cmd)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
|
|
|
# capturing output even if exception was raised.
|
|
|
|
|
|
|
|
self.captured_stdout = self.normalize(p3._get_fake_stdio_ucontent(sys.stdout))
|
|
|
|
|
|
|
|
self.captured_stderr = self.normalize(p3._get_fake_stdio_ucontent(sys.stderr))
|
|
|
|
|
|
|
|
sys.stderr, sys.stdout = sys_stderr, sys_stdout
|
|
|
|
|
|
|
|
|
|
|
|
if expected_out is not None:
|
|
|
|
if expected_out is not None:
|
|
|
|
self.assertEqual(p3.u_maybe(actual_out), p3.u_maybe(expected_out))
|
|
|
|
self.assertEqual(p3.u_maybe(self.captured_stdout), p3.u_maybe(expected_out))
|
|
|
|
if expected_err is not None:
|
|
|
|
if expected_err is not None:
|
|
|
|
self.assertEqual(p3.u_maybe(actual_err), p3.u_maybe(expected_err))
|
|
|
|
self.assertEqual(p3.u_maybe(self.captured_stderr), p3.u_maybe(expected_err))
|
|
|
|
return actual_out
|
|
|
|
return self.captured_stdout
|
|
|
|
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_config(self, config_update, path=None):
|
|
|
|
def update_config(self, config_update, path=None):
|
|
|
|
"""Allow to set the config parameters. Must have done a `pubs init` beforehand."""
|
|
|
|
"""Allow to set the config parameters. Must have done a `pubs init` beforehand."""
|
|
|
@ -624,6 +627,7 @@ class TestTag(DataCommandTestCase):
|
|
|
|
with self.assertRaises(FakeSystemExit):
|
|
|
|
with self.assertRaises(FakeSystemExit):
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestURL(DataCommandTestCase):
|
|
|
|
class TestURL(DataCommandTestCase):
|
|
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
def setUp(self):
|
|
|
@ -1126,6 +1130,21 @@ class TestUsecase(DataCommandTestCase):
|
|
|
|
self.execute_cmds(cmds, capture_output=True)
|
|
|
|
self.execute_cmds(cmds, capture_output=True)
|
|
|
|
# self.assertEqual(correct, self.execute_cmds(cmds, capture_output=True))
|
|
|
|
# self.assertEqual(correct, self.execute_cmds(cmds, capture_output=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_ambiguous_citekey(self):
|
|
|
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
|
|
|
'pubs add data/pagerank.bib',
|
|
|
|
|
|
|
|
'pubs add data/pagerank.bib', # now we have Page99 and Page99a
|
|
|
|
|
|
|
|
'pubs edit Page',
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
output = '\n'.join(["error: Be more specific; 'Page' matches multiples citekeys:",
|
|
|
|
|
|
|
|
" [Page99] Page, Lawrence et al. \"The PageRank Citation Ranking: Bringing Order to the Web.\" (1999) ",
|
|
|
|
|
|
|
|
" [Page99a] Page, Lawrence et al. \"The PageRank Citation Ranking: Bringing Order to the Web.\" (1999) \n"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(FakeSystemExit):
|
|
|
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.captured_stderr, output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ddt.ddt
|
|
|
|
@ddt.ddt
|
|
|
|