Fix unittest if run from non-unicode shell
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 11 Feb 2019 10:54:50 +0000 (11:54 +0100)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 11 Feb 2019 12:17:33 +0000 (13:17 +0100)
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

test/test_cnfvar.py

index 2f5355a..046f56a 100755 (executable)
@@ -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):