from traceback import print_exc
from tempfile import mkstemp
import os
+import sys
from src.simple_cnf import SimpleCnf
61 TESTVAR,0: "test"
"""
+#: encoding for text files, set in :py:func:`setUpModule`
+ENCODING = None
+
+
+def setUpModule():
+ """Called once before all tests; determines encoding
+
+ This test might run in very limited build environments without locale, so
+ auto-selection of temp-file text encoding may return 'ASCII'.
+ Therefore, do the encoding "manually".
+ """
+ global ENCODING
+ ENCODING = sys.getfilesystemencoding()
+ if ENCODING.lower() in ('ascii', 'ansi_x3.4-1968'):
+ ENCODING = 'utf8'
+ print('Using fallback encoding {} for temp file creation'
+ .format(ENCODING))
+ else:
+ print('Using filesystem encoding {} for temp file creation'
+ .format(ENCODING))
+
class SimpleCnfTest(unittest.TestCase):
""" The one and only test case in this module `-->` see module doc """
def setUpClass(cls):
""" before running tests: write conf var string to temp file """
try:
- sys_file_descriptor, cls.import_file = mkstemp(text=True)
+ sys_file_descriptor, cls.import_file = mkstemp()
os.close(sys_file_descriptor)
- with open(cls.import_file, 'wt') as file_handle:
- file_handle.write(TEST_SET)
+ with open(cls.import_file, 'wb') as file_handle:
+ file_handle.write(TEST_SET.encode(ENCODING))
print('created temp file {0}'.format(cls.import_file))
except Exception:
print('exception creating temp file:')