def test_dirs_under(self): fs = FileSystem() parentDir = fs.normpath(fs.join(self._this_dir, "..")) self.assertTrue(self._this_dir in fs.dirs_under(parentDir)) def filter_no_dir(fs, dirpath): return False self.assertEqual(len(fs.dirs_under(parentDir, filter_no_dir)), 0) def filter_this_dir(fs, dirpath): return dirpath != self._this_dir self.assertFalse(self._this_dir in fs.dirs_under(parentDir, filter_this_dir))
def test_maybe_make_directory__failure(self): # FIXME: os.chmod() doesn't work on Windows to set directories # as readonly, so we skip this test for now. if sys.platform in ('win32', 'cygwin'): return fs = FileSystem() with fs.mkdtemp(prefix='filesystem_unittest_') as d: # Remove write permissions on the parent directory. os.chmod(d, stat.S_IRUSR) # Now try to create a sub directory - should fail. sub_dir = fs.join(d, 'subdir') self.assertRaises(OSError, fs.maybe_make_directory, sub_dir) # Clean up in case the test failed and we did create the # directory. if os.path.exists(sub_dir): os.rmdir(sub_dir)
def test_join(self): fs = FileSystem() self.assertEqual(fs.join('foo', 'bar'), os.path.join('foo', 'bar'))
def test_sep(self): fs = FileSystem() self.assertEqual(fs.sep, os.sep) self.assertEqual(fs.join("foo", "bar"), os.path.join("foo", "bar"))