From 9ddeac17f58273730be605a1f08097a15a3204d1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 21 Jan 2010 17:17:02 +1300 Subject: [PATCH] pyxattr: Factor out helper functions. --- source4/scripting/python/samba/tests/xattr.py | 48 +++++++++++++-------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/source4/scripting/python/samba/tests/xattr.py b/source4/scripting/python/samba/tests/xattr.py index 7854f84c8a2..9bfe52c67e3 100644 --- a/source4/scripting/python/samba/tests/xattr.py +++ b/source4/scripting/python/samba/tests/xattr.py @@ -20,20 +20,26 @@ import samba.xattr_native, samba.xattr_tdb from samba.dcerpc import xattr from samba.ndr import ndr_pack -from testtools import TestCase, TestSkipped +from testtools.testcase import TestCase, TestSkipped import random import os class XattrTests(TestCase): + def _tmpfilename(self): + random.seed() + path = os.environ['SELFTEST_PREFIX'] + return os.path.join(path, "pytests"+str(int(100000*random.random()))) + + def _eadbpath(self): + return os.path.join(os.environ['SELFTEST_PREFIX'], "eadb.tdb") + def test_set_xattr_native(self): if not samba.xattr_native.is_xattr_supported(): raise TestSkipped() - random.seed() - path = os.environ['SELFTEST_PREFIX'] - tempf = os.path.join(path,"pytests"+str(int(100000*random.random()))) ntacl = xattr.NTACL() ntacl.version = 1 + tempf = self._tmpfilename() open(tempf, 'w').write("empty") try: samba.xattr_native.wrap_setxattr(tempf, "user.unittests", @@ -45,9 +51,7 @@ class XattrTests(TestCase): def test_set_and_get_native(self): if not samba.xattr_native.is_xattr_supported(): raise TestSkipped() - random.seed() - path = os.environ['SELFTEST_PREFIX'] - tempf = os.path.join(path,"pytests"+str(int(100000*random.random()))) + tempf = self._tmpfilename() reftxt = "this is a test" open(tempf, 'w').write("empty") try: @@ -59,45 +63,41 @@ class XattrTests(TestCase): os.unlink(tempf) def test_set_xattr_tdb(self): - path = os.environ['SELFTEST_PREFIX'] - random.seed() - tempf = os.path.join(path, "pytests"+str(int(100000*random.random()))) + tempf = self._tmpfilename() + eadb_path = self._eadbpath() ntacl = xattr.NTACL() ntacl.version = 1 open(tempf, 'w').write("empty") try: - samba.xattr_tdb.wrap_setxattr(os.path.join(path, "eadb.tdb"), + samba.xattr_tdb.wrap_setxattr(eadb_path, tempf, "user.unittests", ndr_pack(ntacl)) finally: os.unlink(tempf) - os.unlink(os.path.join(path, "eadb.tdb")) + os.unlink(eadb_path) def test_set_tdb_not_open(self): - path = os.environ['SELFTEST_PREFIX'] - random.seed() - tempf = os.path.join(path, "pytests"+str(int(100000*random.random()))) + tempf = self._tmpfilename() ntacl = xattr.NTACL() ntacl.version = 1 open(tempf, 'w').write("empty") try: self.assertRaises(IOError, samba.xattr_tdb.wrap_setxattr, - os.path.join(path, "nonexistent","eadb.tdb"), tempf, + os.path.join("nonexistent", "eadb.tdb"), tempf, "user.unittests", ndr_pack(ntacl)) finally: os.unlink(tempf) def test_set_and_get_tdb(self): - path = os.environ['SELFTEST_PREFIX'] - random.seed() - tempf = os.path.join(path, "pytests"+str(int(100000*random.random()))) + tempf = self._tmpfilename() + eadb_path = self._eadbpath() reftxt = "this is a test" open(tempf, 'w').write("empty") try: - samba.xattr_tdb.wrap_setxattr(os.path.join(path, "eadb.tdb"), - tempf, "user.unittests", reftxt) - text = samba.xattr_tdb.wrap_getxattr( - os.path.join(path, "eadb.tdb"), tempf, "user.unittests") + samba.xattr_tdb.wrap_setxattr(eadb_path, tempf, "user.unittests", + reftxt) + text = samba.xattr_tdb.wrap_getxattr(eadb_path, tempf, + "user.unittests") self.assertEquals(text, reftxt) finally: os.unlink(tempf) - os.unlink(os.path.join(path, "eadb.tdb")) + os.unlink(eadb_path) -- 2.11.4.GIT