mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-21 00:03:45 +08:00
common: replace custom xattr implementation with os module's (#24448)
* use os module's xattr function * fix that * handle in helper old-commit-hash: 81dacbedcacaf9db43d19700e04e7361c0fbbbcc
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
import os
|
||||
import tempfile
|
||||
import shutil
|
||||
import unittest
|
||||
|
||||
from common.xattr import getxattr, setxattr, listxattr, removexattr
|
||||
|
||||
class TestParams(unittest.TestCase):
|
||||
USER_TEST='user.test'
|
||||
def setUp(self):
|
||||
self.tmpdir = tempfile.mkdtemp()
|
||||
self.tmpfn = os.path.join(self.tmpdir, 'test.txt')
|
||||
open(self.tmpfn, 'w').close()
|
||||
#print("using", self.tmpfn)
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.tmpdir)
|
||||
|
||||
def test_getxattr_none(self):
|
||||
a = getxattr(self.tmpfn, TestParams.USER_TEST)
|
||||
assert a is None
|
||||
|
||||
def test_listxattr_none(self):
|
||||
l = listxattr(self.tmpfn)
|
||||
assert l == []
|
||||
|
||||
def test_setxattr(self):
|
||||
setxattr(self.tmpfn, TestParams.USER_TEST, b'123')
|
||||
a = getxattr(self.tmpfn, TestParams.USER_TEST)
|
||||
assert a == b'123'
|
||||
|
||||
def test_listxattr(self):
|
||||
setxattr(self.tmpfn, 'user.test1', b'123')
|
||||
setxattr(self.tmpfn, 'user.test2', b'123')
|
||||
l = listxattr(self.tmpfn)
|
||||
assert l == ['user.test1', 'user.test2']
|
||||
|
||||
def test_removexattr(self):
|
||||
setxattr(self.tmpfn, TestParams.USER_TEST, b'123')
|
||||
a = getxattr(self.tmpfn, TestParams.USER_TEST)
|
||||
assert a == b'123'
|
||||
removexattr(self.tmpfn, TestParams.USER_TEST)
|
||||
a = getxattr(self.tmpfn, TestParams.USER_TEST)
|
||||
assert a is None
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user