diff --git a/changelog.md b/changelog.md index 13c486b..d64f6be 100644 --- a/changelog.md +++ b/changelog.md @@ -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)) diff --git a/pubs/commands/note_cmd.py b/pubs/commands/note_cmd.py index cb0ddee..9466566 100644 --- a/pubs/commands/note_cmd.py +++ b/pubs/commands/note_cmd.py @@ -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() diff --git a/readme.md b/readme.md index 44210b9..e42b9bc 100644 --- a/readme.md +++ b/readme.md @@ -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) diff --git a/tests/fake_env.py b/tests/fake_env.py index dad816d..6d790a3 100644 --- a/tests/fake_env.py +++ b/tests/fake_env.py @@ -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): diff --git a/tests/test_note_append.py b/tests/test_note_append.py index f50843c..c3009f2 100644 --- a/tests/test_note_append.py +++ b/tests/test_note_append.py @@ -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):