borg/attic/testsuite/xattr.py

31 lines
1.4 KiB
Python
Raw Normal View History

2013-06-27 11:28:59 +00:00
import os
import tempfile
import unittest
2013-07-08 21:38:27 +00:00
from attic.testsuite import AtticTestCase
2013-07-27 20:33:43 +00:00
from attic.xattr import is_enabled, getxattr, setxattr, listxattr
2013-06-27 11:28:59 +00:00
@unittest.skipUnless(is_enabled(), 'xattr not enabled on filesystem')
2013-07-08 21:38:27 +00:00
class XattrTestCase(AtticTestCase):
2013-06-27 11:28:59 +00:00
2013-06-27 19:56:14 +00:00
def setUp(self):
self.tmpfile = tempfile.NamedTemporaryFile()
2013-06-27 19:56:14 +00:00
self.symlink = os.path.join(os.path.dirname(self.tmpfile.name), 'symlink')
os.symlink(self.tmpfile.name, self.symlink)
def tearDown(self):
os.unlink(self.symlink)
2013-07-27 20:33:43 +00:00
def test(self):
self.assert_equal(listxattr(self.tmpfile.name), [])
self.assert_equal(listxattr(self.tmpfile.fileno()), [])
self.assert_equal(listxattr(self.symlink), [])
setxattr(self.tmpfile.name, 'user.foo', b'bar')
setxattr(self.tmpfile.fileno(), 'user.bar', b'foo')
self.assert_equal(set(listxattr(self.tmpfile.name)), set(['user.foo', 'user.bar']))
self.assert_equal(set(listxattr(self.tmpfile.fileno())), set(['user.foo', 'user.bar']))
self.assert_equal(set(listxattr(self.symlink)), set(['user.foo', 'user.bar']))
self.assert_equal(listxattr(self.symlink, follow_symlinks=False), [])
self.assert_equal(getxattr(self.tmpfile.name, 'user.foo'), b'bar')
self.assert_equal(getxattr(self.tmpfile.fileno(), 'user.foo'), b'bar')
self.assert_equal(getxattr(self.symlink, 'user.foo'), b'bar')