3f10872caf52fb89a89c3c0ce55527faf08589a2
Test cases for the dircache module
from test
.test_support
import run_unittest
, TESTFN
import dircache
, os
, time
, sys
, tempfile
class DircacheTests(unittest
.TestCase
):
self
.tempdir
= tempfile
.mkdtemp()
for fname
in os
.listdir(self
.tempdir
):
def writeTemp(self
, fname
):
f
= open(os
.path
.join(self
.tempdir
, fname
), 'w')
def mkdirTemp(self
, fname
):
os
.mkdir(os
.path
.join(self
.tempdir
, fname
))
def delTemp(self
, fname
):
fname
= os
.path
.join(self
.tempdir
, fname
)
entries
= dircache
.listdir(self
.tempdir
)
self
.assertEquals(entries
, [])
# Check that cache is actually caching, not just passing through.
self
.assert_(dircache
.listdir(self
.tempdir
) is entries
)
# Directories aren't "files" on Windows, and directory mtime has
# nothing to do with when files under a directory get created.
# That is, this test can't possibly work under Windows -- dircache
# is only good for capturing a one-shot snapshot there.
if sys
.platform
[:3] not in ('win', 'os2'):
# Sadly, dircache has the same granularity as stat.mtime, and so
# can't notice any changes that occured within 1 sec of the last
# time it examined a directory.
entries
= dircache
.listdir(self
.tempdir
)
self
.assertEquals(entries
, ['test1'])
self
.assert_(dircache
.listdir(self
.tempdir
) is entries
)
self
.assertRaises(OSError, dircache
.listdir
, self
.tempdir
+"_nonexistent")
lst
= ['A', 'test2', 'test_nonexistent']
dircache
.annotate(self
.tempdir
, lst
)
self
.assertEquals(lst
, ['A/', 'test2', 'test_nonexistent'])
run_unittest(DircacheTests
)
if __name__
== "__main__":