From 8fdf995ff99e491816f9b2c163a06b5b80bd61b9 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 14 Apr 2015 10:14:35 -0700 Subject: [PATCH] Fallback encoding under test harness Now this works when capturing output for the tests. --- beets/ui/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index ff12a1d7b..7c94dced7 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -80,6 +80,11 @@ def _out_encoding(): if encoding: return encoding + # For testing: When sys.stdout is a StringIO under the test harness, + # it doesn't have an `encodiing` attribute. Just use UTF-8. + if not hasattr(sys.stdout, 'encoding'): + return 'utf8' + # Python's guessed output stream encoding, or UTF-8 as a fallback # (e.g., when piped to a file). return sys.stdout.encoding or 'utf8'