From ca0d1bc7aaaaf35f39d8a3bcdd41872964849167 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 18 Jan 2011 19:09:04 -0800 Subject: [PATCH] fix unicode issue with manual search prompt (#113) --- NEWS | 2 ++ beets/ui/commands.py | 5 +++-- test/test_ui.py | 13 +++++++++++++ test/testall.py | 3 +-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index fd4e7a925..4c22bfb28 100644 --- a/NEWS +++ b/NEWS @@ -29,6 +29,8 @@ * When copying read-only files, the importer now tries to make the copy writable. (Previously, this would just crash the import.) * Fixed an UnboundLocalError when no matches are found during autotag. +* Fixed a Unicode encoding error when entering special characters into + the "manual search" prompt. 1.0b5 ----- diff --git a/beets/ui/commands.py b/beets/ui/commands.py index e056c7744..438f769cc 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -19,6 +19,7 @@ from __future__ import with_statement # Python 2.5 import os import logging import pickle +import sys from beets import ui from beets.ui import print_ @@ -186,8 +187,8 @@ def choose_candidate(cur_artist, cur_album, candidates, rec, color=True): def manual_search(): """Input an artist and album for manual search.""" - artist = raw_input('Artist: ') - album = raw_input('Album: ') + artist = raw_input('Artist: ').decode(sys.stdin.encoding) + album = raw_input('Album: ').decode(sys.stdin.encoding) return artist.strip(), album.strip() def tag_log(logfile, status, path): diff --git a/test/test_ui.py b/test/test_ui.py index f28ed48b1..0ddecfa65 100644 --- a/test/test_ui.py +++ b/test/test_ui.py @@ -102,6 +102,19 @@ class PrintTest(unittest.TestCase): else: del os.environ['LC_CTYPE'] +class InputTest(unittest.TestCase): + def setUp(self): + def my_input(prompt=None): + return '\xc3\x82me' + commands.raw_input = my_input + def tearDown(self): + commands.raw_input = raw_input + + def test_manual_search_gets_unicode(self): + artist, album = commands.manual_search() + self.assertEqual(artist, u'\xc2me') + self.assertEqual(album, u'\xc2me') + def suite(): return unittest.TestLoader().loadTestsFromName(__name__) diff --git a/test/testall.py b/test/testall.py index 1cabde503..136c510fe 100755 --- a/test/testall.py +++ b/test/testall.py @@ -19,7 +19,7 @@ import os import re import sys -pkgpath = os.path.dirname(__file__) +pkgpath = os.path.dirname(__file__) or '.' sys.path.append(pkgpath) os.chdir(pkgpath) @@ -35,4 +35,3 @@ def suite(): if __name__ == '__main__': unittest.main(defaultTest='suite') -