Anonymous avatar Anonymous committed 190be39

Fix encoding in config test and open configs in binary mode to warn for possible encoding errors

Comments (0)

Files changed (3)

-                    f = open(config_file, 'U')
+                    f = open(config_file, 'Ub')
                         code = compile(, config_file, 'exec')


 def test_errors_warnings(dir):
     # test the error for syntax errors in the config file
-    write_file(dir / '', 'project = \n')
+    write_file(dir / '', u'project = \n', 'ascii')
     raises_msg(ConfigError, '', Config, dir, '', {}, None)
     # test the warning for bytestrings with non-ascii content
-    write_file(dir / '', '# -*- coding: latin-1\nproject = "foo\xe4"\n')
+    write_file(dir / '',
+               u'# -*- coding: latin-1\nproject = "fooä"\n', 'latin-1')
     cfg = Config(dir, '', {}, None)
     warned = [False]
     def warn(msg):
 import StringIO
 import tempfile
 import shutil
+from codecs import open
     from functools import wraps
     return new_func
-def write_file(name, contents):
-    f = open(str(name), 'wb')
+def write_file(name, contents, encoding=None):
+    if encoding is None:
+        mode = 'wb'
+        if isinstance(contents, unicode):
+            contents = contents.encode('ascii')
+    else:
+        mode = 'w'
+    f = open(str(name), 'wb', encoding=encoding)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.