Test appending a multi-word line into a bib note.

https://github.com/pubs/pubs/pull/201#discussion_r305274762
main
dvklopfenstein 6 years ago
parent 5b8eb48cdc
commit b75d77bf24

@ -5,6 +5,8 @@
# set this prior to running this test: # set this prior to running this test:
# export PUBSCONF=~/.pubsrc # export PUBSCONF=~/.pubsrc
# vim -p tests/test_note_append.py tests/test_usecase.py
from __future__ import print_function, unicode_literals from __future__ import print_function, unicode_literals
import unittest import unittest
@ -39,12 +41,15 @@ class TestNoteAppend(DataCommandTestCase):
note_lines.append('bbb') note_lines.append('bbb')
self.assertFileContentEqual(fin_notes, self._get_note_content(note_lines)) self.assertFileContentEqual(fin_notes, self._get_note_content(note_lines))
# # https://github.com/pubs/pubs/pull/201#discussion_r307499310 # https://github.com/pubs/pubs/pull/201#discussion_r307499310
# # Test multiword line # Test multiword line.
# cmds = [('pubs', 'note', 'Page99', '-a', 'xxx yyy',)] # * Pass the command split into a command and its args to
# self.execute_cmds(cmds) # execute_cmdsplit, which is called by execute_cmds:
# note_lines.append('xxx yyy') #cmds = [('pubs note Page99 -a "xxx yyy"')]
# self.assertFileContentEqual(fin_notes, self._get_note_content(note_lines)) cmd_split = ['pubs', 'note', 'Page99', '-a', 'xxx yyy']
self.execute_cmdsplit(cmd_split, expected_out=None, expected_err=None)
note_lines.append('xxx yyy')
self.assertFileContentEqual(fin_notes, self._get_note_content(note_lines))
# # https://github.com/pubs/pubs/pull/201#discussion_r305274071 # # https://github.com/pubs/pubs/pull/201#discussion_r305274071
# # Test adding Chinese characters # # Test adding Chinese characters

@ -97,14 +97,6 @@ class CommandTestCase(fake_env.TestFakeFs):
3. the expected output on stdout, verified with assertEqual. 3. the expected output on stdout, verified with assertEqual.
4. the expected output on stderr, verified with assertEqual. 4. the expected output on stderr, verified with assertEqual.
""" """
def normalize(s):
s = color.undye(s)
try:
s = s.decode('utf-8')
except AttributeError:
pass
return s
try: try:
outs = [] outs = []
for cmd in cmds: for cmd in cmds:
@ -126,15 +118,8 @@ class CommandTestCase(fake_env.TestFakeFs):
input.as_global() input.as_global()
try: try:
if capture_output: if capture_output:
capture_wrap = fake_env.capture(pubs_cmd.execute, actual_out = self.execute_cmdsplit(
verbose=PRINT_OUTPUT) actual_cmd.split(), expected_out, expected_err)
_, stdout, stderr = capture_wrap(actual_cmd.split())
actual_out = normalize(stdout)
actual_err = normalize(stderr)
if expected_out is not None:
self.assertEqual(p3.u_maybe(actual_out), p3.u_maybe(expected_out))
if expected_err is not None:
self.assertEqual(p3.u_maybe(actual_err), p3.u_maybe(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())
@ -150,6 +135,29 @@ class CommandTestCase(fake_env.TestFakeFs):
else: else:
raise FakeSystemExit(*exc.args).with_traceback(tb) raise FakeSystemExit(*exc.args).with_traceback(tb)
@staticmethod
def normalize(s):
"""Remove color from a string, adjusting for a decode method needed in Python2"""
s = color.undye(s)
try:
s = s.decode('utf-8')
except AttributeError:
pass
return s
def execute_cmdsplit(self, actual_cmdlist, expected_out, expected_err):
"""Run a single command, which has been split into a list containing cmd and args"""
capture_wrap = fake_env.capture(pubs_cmd.execute,
verbose=PRINT_OUTPUT)
_, stdout, stderr = capture_wrap(actual_cmdlist)
actual_out = self.normalize(stdout)
actual_err = self.normalize(stderr)
if expected_out is not None:
self.assertEqual(p3.u_maybe(actual_out), p3.u_maybe(expected_out))
if expected_err is not None:
self.assertEqual(p3.u_maybe(actual_err), p3.u_maybe(expected_err))
return actual_out
def tearDown(self): def tearDown(self):
pass pass

Loading…
Cancel
Save