1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-26 17:57:59 +00:00
borg/attic/testsuite/xattr.py

44 lines
1.8 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
from attic.xattr import lsetxattr, llistxattr, lgetxattr, get_all, set, flistxattr, fgetxattr, fsetxattr, is_enabled
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-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'})