self.failUnlessFalse(dirinfo.islink)
# create a file under the directory
- f = os.path.join(basedir, "a/1.txt")
+ f = os.path.join(basedir, "a", "1.txt")
self.touch(basedir, "a/1.txt", data="a"*10)
fileinfo = fileutil.get_pathinfo(f)
self.failUnlessTrue(fileinfo.isfile)
self.failUnlessEqual(fileinfo.size, 10)
# create a symlink under the directory a pointing to 1.txt
- slname = os.path.join(basedir, "a/linkto1.txt")
+ slname = os.path.join(basedir, "a", "linkto1.txt")
os.symlink(f, slname)
symlinkinfo = fileutil.get_pathinfo(slname)
self.failUnlessTrue(symlinkinfo.islink)
self.failUnlessFalse(symlinkinfo.isfile)
self.failUnlessFalse(symlinkinfo.isdir)
+ # path at which nothing exists
+ dnename = os.path.join(basedir, "a", "doesnotexist")
+ now = time.time()
+ dneinfo = fileutil.get_pathinfo(dnename, now=now)
+ self.failUnlessFalse(dneinfo.exists)
+ self.failUnlessFalse(dneinfo.isfile)
+ self.failUnlessFalse(dneinfo.isdir)
+ self.failUnlessFalse(dneinfo.islink)
+ self.failUnlessEqual(dneinfo.size, None)
+ self.failUnlessEqual(dneinfo.mtime, now)
+ self.failUnlessEqual(dneinfo.ctime, now)
+
class PollMixinTests(unittest.TestCase):
def setUp(self):
PathInfo = namedtuple('PathInfo', 'isdir isfile islink exists size mtime ctime')
-def get_pathinfo(path_u):
+def get_pathinfo(path_u, now=None):
try:
statinfo = os.lstat(path_u)
mode = statinfo.st_mode
)
except OSError as e:
if e.errno == ENOENT:
+ if now is None:
+ now = time.time()
return PathInfo(isdir =False,
isfile=False,
islink=False,
exists=False,
size =None,
- mtime =None,
- ctime =None,
+ mtime =now,
+ ctime =now,
)
raise