1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-25 01:06:50 +00:00
borg/darc/testsuite/xattr.py

42 lines
1.7 KiB
Python
Raw Normal View History

2013-06-27 11:28:59 +00:00
import tempfile
import os
from darc.testsuite import DarcTestCase
from darc.xattr import lsetxattr, llistxattr, lgetxattr, get_all, set, flistxattr, fgetxattr, fsetxattr
class XattrTestCase(DarcTestCase):
2013-06-27 19:56:14 +00:00
def setUp(self):
self.tmpfile = tempfile.NamedTemporaryFile(dir=os.getcwd())
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-06-27 11:28:59 +00:00
def test_low_level(self):
2013-06-27 19:56:14 +00:00
self.assert_equal(llistxattr(self.tmpfile.name), [])
self.assert_equal(llistxattr(self.symlink), [])
2013-06-27 20:10:15 +00:00
lsetxattr(self.tmpfile.name, b'foo', b'bar')
self.assert_equal(llistxattr(self.tmpfile.name), [b'foo'])
self.assert_equal(lgetxattr(self.tmpfile.name, b'foo'), b'bar')
2013-06-27 19:56:14 +00:00
self.assert_equal(llistxattr(self.symlink), [])
2013-06-27 11:28:59 +00:00
def test_low_level_fileno(self):
2013-06-27 19:56:14 +00:00
self.assert_equal(flistxattr(self.tmpfile.fileno()), [])
2013-06-27 20:10:15 +00:00
fsetxattr(self.tmpfile.fileno(), b'foo', b'bar')
self.assert_equal(flistxattr(self.tmpfile.fileno()), [b'foo'])
self.assert_equal(fgetxattr(self.tmpfile.fileno(), b'foo'), b'bar')
2013-06-27 11:28:59 +00:00
def test_high_level(self):
2013-06-27 19:56:14 +00:00
self.assert_equal(get_all(self.tmpfile.name), {})
self.assert_equal(get_all(self.symlink), {})
set(self.tmpfile.name, b'foo', b'bar')
self.assert_equal(get_all(self.tmpfile.name), {b'foo': b'bar'})
self.assert_equal(get_all(self.symlink), {})
2013-06-27 11:28:59 +00:00
def test_high_level_fileno(self):
2013-06-27 19:56:14 +00:00
self.assert_equal(get_all(self.tmpfile.fileno()), {})
set(self.tmpfile.fileno(), b'foo', b'bar')
self.assert_equal(get_all(self.tmpfile.fileno()), {b'foo': b'bar'})