]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Fix fileutil tests.
authorDaira Hopwood <daira@jacaranda.org>
Sat, 24 Oct 2015 00:14:18 +0000 (01:14 +0100)
committermeejah <meejah@meejah.ca>
Wed, 20 Jan 2016 08:30:17 +0000 (01:30 -0700)
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
src/allmydata/test/test_util.py
src/allmydata/util/fileutil.py

index c91c8503eb7dc8b9eed70110b270a44dc4f2967f..ad97e6c082dcb698c5e0e0329a7e98c1f7d9e927 100644 (file)
@@ -568,7 +568,7 @@ class FileUtil(ReallyEqualMixin, unittest.TestCase):
             self.failIf(baz_notlong.startswith(u"\\\\?\\"), baz_notlong)
             self.failUnlessReallyEqual(baz_notlong[1 :], u":\\baz")
 
-            bar_notlong = fileutil.abspath_expanduser_unicode(u"\\bar", base=baz, long_path=False)
+            bar_notlong = fileutil.abspath_expanduser_unicode(u"\\bar", base=baz_notlong, long_path=False)
             self.failIf(bar_notlong.startswith(u"\\\\?\\"), bar_notlong)
             self.failUnlessReallyEqual(bar_notlong[1 :], u":\\bar")
             # not u":\\baz\\bar", because \bar is absolute on the current drive.
@@ -664,9 +664,9 @@ class FileUtil(ReallyEqualMixin, unittest.TestCase):
         self.failUnlessFalse(dirinfo.isfile)
         self.failUnlessFalse(dirinfo.islink)
 
-        # create a file under the directory
-        f = os.path.join(basedir, "a", "1.txt")
-        self.touch(basedir, "a/1.txt", data="a"*10)
+        # create a file
+        f = os.path.join(basedir, "1.txt")
+        fileutil.write(f, "a"*10)
         fileinfo = fileutil.get_pathinfo(f)
         self.failUnlessTrue(fileinfo.isfile)
         self.failUnlessTrue(fileinfo.exists)
@@ -674,17 +674,8 @@ class FileUtil(ReallyEqualMixin, unittest.TestCase):
         self.failUnlessFalse(fileinfo.islink)
         self.failUnlessEqual(fileinfo.size, 10)
 
-        # create a symlink under the directory a pointing to 1.txt
-        slname = os.path.join(basedir, "a", "linkto1.txt")
-        os.symlink(f, slname)
-        symlinkinfo = fileutil.get_pathinfo(slname)
-        self.failUnlessTrue(symlinkinfo.islink)
-        self.failUnlessTrue(symlinkinfo.exists)
-        self.failUnlessFalse(symlinkinfo.isfile)
-        self.failUnlessFalse(symlinkinfo.isdir)
-
         # path at which nothing exists
-        dnename = os.path.join(basedir, "a", "doesnotexist")
+        dnename = os.path.join(basedir, "doesnotexist")
         now = time.time()
         dneinfo = fileutil.get_pathinfo(dnename, now=now)
         self.failUnlessFalse(dneinfo.exists)
@@ -695,6 +686,25 @@ class FileUtil(ReallyEqualMixin, unittest.TestCase):
         self.failUnlessEqual(dneinfo.mtime, now)
         self.failUnlessEqual(dneinfo.ctime, now)
 
+    def test_get_pathinfo_symlink(self):
+        if not hasattr(os, 'symlink'):
+            raise unittest.SkipTest("can't create symlinks on this platform")
+
+        basedir = "util/FileUtil/test_get_pathinfo"
+        fileutil.make_dirs(basedir)
+
+        f = os.path.join(basedir, "1.txt")
+        fileutil.write(f, "a"*10)
+
+        # create a symlink pointing to 1.txt
+        slname = os.path.join(basedir, "linkto1.txt")
+        os.symlink(f, slname)
+        symlinkinfo = fileutil.get_pathinfo(slname)
+        self.failUnlessTrue(symlinkinfo.islink)
+        self.failUnlessTrue(symlinkinfo.exists)
+        self.failUnlessFalse(symlinkinfo.isfile)
+        self.failUnlessFalse(symlinkinfo.isdir)
+
 
 class PollMixinTests(unittest.TestCase):
     def setUp(self):
index 625c50389e1952cde3b1413fa65836ade52378bf..b35fe2dc4210ce30c76041080f079b41656825bb 100644 (file)
@@ -292,7 +292,7 @@ def abspath_expanduser_unicode(path, base=None, long_path=True):
     """
     if not isinstance(path, unicode):
         raise AssertionError("paths must be Unicode strings")
-    if base is not None:
+    if base is not None and long_path:
         precondition_abspath(base)
 
     path = expanduser(path)