fix note append of under python 2 with unicode

main
Fabien C. Y. Benureau 6 years ago
parent 2b408fe7ea
commit fe014bc0a5
No known key found for this signature in database
GPG Key ID: C3FB5E831A249A9A

@ -7,6 +7,7 @@
### Implemented enhancements
- Added append functionality to the note command ([#201](https://github.com/pubs/pubs/pull/201) by [DV Klopfenstein](http://github.com/dvklopfenstein))
- New git plugin to commit changes to the repository ([#191](https://github.com/pubs/pubs/pull/191) by [Amlesh Sivanantham](http://github.com/zamlz))
- The import command now warn, rather than fail on existing citekeys. ([#198](https://github.com/pubs/pubs/pull/198) by [Kyle Sunden](https://github.com/ksunden))
- Add `citekey` filter to `query` ([#193](https://github.com/pubs/pubs/pull/193) by [Shane Stone](https://github.com/shanewstone))

@ -1,3 +1,6 @@
from __future__ import unicode_literals
from .. import p3
from .. import repo
from ..uis import get_ui
from ..utils import resolve_citekey
@ -25,7 +28,7 @@ def command(conf, args):
if args.append is None:
ui.edit_file(notepath, temporary=False)
else:
latestnote = '{txt}\n'.format(txt=args.append)
latestnote = '{txt}\n'.format(txt=p3.u_maybe(args.append))
write_file(notepath, latestnote, 'a')
NoteEvent(citekey).send()
rp.close()

@ -156,3 +156,4 @@ You can access the self-documented configuration by using `pubs conf`, and all t
- [Kyle Sunden](https://github.com/ksunden)
- [Shane Stone](https://github.com/shanewstone)
- [Amlesh Sivanantham](http://github.com/zamlz)
- [DV Klopfenstein](http://github.com/dvklopfenstein)

@ -3,6 +3,7 @@ import io
import os
import shutil
import glob
import locale
import dotdot
@ -23,6 +24,11 @@ real_io = io
original_exception_handler = uis.InputUI.handle_exception
# needed to get locale.getpreferredencoding(False) (invoked by pyfakefs)
# to work properly
locale.setlocale(locale.LC_ALL, '')
# capture output
def capture(f, verbose=False):

@ -45,23 +45,24 @@ class TestNoteAppend(DataCommandTestCase):
# Test multiword line.
# * Pass the command split into a command and its args to
# execute_cmdsplit, which is called by execute_cmds:
#cmds = [('pubs note Page99 -a "xxx yyy"')]
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
# # Test adding Chinese characters
# cmds = [('pubs note Page99 -a \347\350\346\345')]
# self.execute_cmds(cmds)
# note_lines.append('\347\350\346\345')
# self.assertFileContentEqual(fin_notes, self._get_note_content(note_lines))
# # Test adding Japanese character
# cmds = [('pubs note Page99 -a ソ')]
# self.execute_cmds(cmds)
# note_lines.append('ソ')
# self.assertFileContentEqual(fin_notes, self._get_note_content(note_lines))
def test_note_append_unicode(self):
fin_notes = os.path.join(self.note_dir, 'Page99.txt')
# https://github.com/pubs/pubs/pull/201#discussion_r305274071
# Test adding Chinese characters
cmds = [('pubs note Page99 -a \347\350\346\345')]
self.execute_cmds(cmds)
note_lines = ['\347\350\346\345']
self.assertFileContentEqual(fin_notes, self._get_note_content(note_lines))
# Test adding Japanese character
cmds = [('pubs note Page99 -a ソ')]
self.execute_cmds(cmds)
note_lines.append('')
self.assertFileContentEqual(fin_notes, self._get_note_content(note_lines))
@staticmethod
def _get_note_content(note_lines):

Loading…
Cancel
Save