diff options
author | gfxmonk <tim@gfxmonk.net> | 2012-01-23 20:05:42 +1100 |
---|---|---|
committer | gfxmonk <tim@gfxmonk.net> | 2012-01-23 20:08:47 +1100 |
commit | 559d249aa98d41993b5fb7f37afaa1ce57a3523a (patch) | |
tree | e3bbd484656a41520182b1ffb065b728155b47a3 | |
parent | e3f942892f8ed45ce61b1a022b9fad63b0cb5737 (diff) | |
download | xattr-559d249aa98d41993b5fb7f37afaa1ce57a3523a.tar.gz |
Add failing test for https://bugs.launchpad.net/ubuntu/+source/python-xattr/+bug/919874
Use NamedTemporaryFile in tests instead of mkstemp in order to
use it as a symlink target. As a side benefit, it doesn't
need to be explicitly deleted.
-rw-r--r-- | xattr/tests/test_xattr.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/xattr/tests/test_xattr.py b/xattr/tests/test_xattr.py index 3470013..0124fef 100644 --- a/xattr/tests/test_xattr.py +++ b/xattr/tests/test_xattr.py @@ -1,16 +1,17 @@ import os from unittest import TestCase -from tempfile import mkstemp, mkdtemp +from tempfile import mkdtemp, NamedTemporaryFile +from os import tempnam import xattr class TestFile(TestCase): def setUp(self): - self.tempfh, self.tempfile = mkstemp() + self.tempfile = NamedTemporaryFile() + self.tempfilename = self.tempfile.name def tearDown(self): - os.close(self.tempfh) - os.unlink(self.tempfile) + self.tempfile.close() def testAttr(self): x = xattr.xattr(self.tempfile) @@ -33,10 +34,22 @@ class TestFile(TestCase): x = xattr.xattr(self.tempfile) self.assertTrue('user.sop.foo' not in x) + def testSymlinkAttrs(self): + symlinkPath = tempnam() + os.symlink(self.tempfilename, symlinkPath) + try: + symlink = xattr.xattr(symlinkPath, options=xattr.XATTR_NOFOLLOW) + realfile = xattr.xattr(self.tempfilename) + symlink['user.islink'] = 'true' + self.assertEqual(dict(realfile), {}) + self.assertEqual(symlink['user.islink'], 'true') + finally: + os.remove(symlinkPath) class TestDir(TestFile): def setUp(self): self.tempfile = mkdtemp() + self.tempfilename = self.tempfile def tearDown(self): os.rmdir(self.tempfile) |