summaryrefslogtreecommitdiff
path: root/xattr
diff options
context:
space:
mode:
authorRoman Bogorodskiy <bogorodskiy@gmail.com>2018-02-18 12:02:17 +0400
committerRoman Bogorodskiy <bogorodskiy@gmail.com>2018-02-18 12:11:05 +0400
commit4366bb9b3952adfd73792cd4fea2b427e88cc43b (patch)
tree98bc695baae93eb5a2d75df05be7077e4f923f7e /xattr
parented5a6e6695ca9d8d472fdba25433c96da4064886 (diff)
downloadxattr-4366bb9b3952adfd73792cd4fea2b427e88cc43b.tar.gz
Make tests independent of user's locale
As os.fsencode() is not present in Python 2.7, a custom wrapper is used which calls sys.getfilesystemencoding() to detect filesystem encoding. This detection is based on user's locale settings, so in different environments it could be either Unicode or non-Unicode value, and the tests will behave differently in this case. To make tests independent of that, explicitly set 'compat.fs_encoding' variable and run tests for both Unicode and ASCII.
Diffstat (limited to 'xattr')
-rw-r--r--xattr/tests/test_xattr.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/xattr/tests/test_xattr.py b/xattr/tests/test_xattr.py
index c22efec..cb6ebb9 100644
--- a/xattr/tests/test_xattr.py
+++ b/xattr/tests/test_xattr.py
@@ -13,7 +13,22 @@ class BaseTestXattr(object):
# manual override here.
TESTDIR = None
- def test_attr(self):
+ def test_attr_fs_encoding_unicode(self):
+ # Not using setlocale(LC_ALL, ..) to set locale because
+ # sys.getfilesystemencoding() implementation falls back
+ # to user's preferred locale by calling setlocale(LC_ALL, '').
+ xattr.compat.fs_encoding = 'UTF-8'
+ self._test_attr()
+
+ def test_attr_fs_encoding_ascii(self):
+ xattr.compat.fs_encoding = 'US-ASCII'
+ if sys.version_info[0] < 3:
+ with self.assertRaises(UnicodeEncodeError):
+ self._test_attr()
+ else:
+ self._test_attr()
+
+ def _test_attr(self):
x = xattr.xattr(self.tempfile)
# Solaris 11 and forward contain system attributes (file flags) in