From: Christian Herdtweck Date: Mon, 11 Feb 2019 10:54:50 +0000 (+0100) Subject: Fix unittest if run from non-unicode shell X-Git-Tag: v1.4~3^2~1 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=5465e48c373b1e65be396696c18c527b342e9de1;p=pyi2ncommon Fix unittest if run from non-unicode shell When opening files (like os.devnull) in text mode, python uses the shell's default encoding. In case LANG=C or when redirecting (for example), that is just 'ascii', so writing non-ascii strings to /dev/null fails with UnicodeError --- diff --git a/test/test_cnfvar.py b/test/test_cnfvar.py index 2f5355a..046f56a 100755 --- a/test/test_cnfvar.py +++ b/test/test_cnfvar.py @@ -412,7 +412,7 @@ class CnfVarUnittest(unittest.TestCase): def test_read_json_nonascii(self): cnf = cnfvar.read_cnf_json(demo_latin1crap) - with open(os.devnull, "w") as devnull: + with open(os.devnull, "wb") as devnull: cnfvar.print_cnf(cnf, out=devnull) def test_parse_cnf_quotes(self):