selftest: enable py3 for samba.tests.source
authorJoe Guo <joeg@catalyst.net.nz>
Thu, 5 Apr 2018 00:49:09 +0000 (12:49 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Fri, 13 Apr 2018 05:27:13 +0000 (07:27 +0200)
In py2, `open` has no `encoding` arg, python guesses file encoding from
locale. This could be wrong.

Use `io.open` to open a file, so we can specify encoding in both py2 and
py3.

Also, open file with `r` instead of `rb` for py3.

Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/tests/source.py
selftest/tests.py

index 3b18a91b5a20293123745e5719620f38a40ca26e..0e0bd5c37cfd6d1a335807612442066d388ec5b6 100644 (file)
@@ -19,6 +19,7 @@
 
 """Source level Python tests."""
 
+import io
 import errno
 import os
 import re
@@ -60,7 +61,7 @@ def get_source_file_contents():
     """Iterate over the contents of all python files."""
     for fname in get_python_source_files():
         try:
-            f = open(fname, 'rb')
+            f = io.open(fname, mode='r', encoding='utf-8')
         except IOError as e:
             if e.errno == errno.ENOENT:
                 warnings.warn("source file %s broken link?" % fname)
index d866ca9f97011c665a19b92957c61728d2d23d45..548e68b5c1b80a0bc0e909f4b3c7206a3a001947 100644 (file)
@@ -41,7 +41,7 @@ have_man_pages_support = ("XSLTPROC_MANPAGES" in config_hash)
 with_pam = ("WITH_PAM" in config_hash)
 pam_wrapper_so_path=config_hash["LIBPAM_WRAPPER_SO_PATH"]
 
-planpythontestsuite("none", "samba.tests.source")
+planpythontestsuite("none", "samba.tests.source", py3_compatible=True)
 if have_man_pages_support:
     planpythontestsuite("none", "samba.tests.docs")