diff options
author | hut <hut@lavabit.com> | 2009-11-24 00:41:16 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2009-11-24 00:41:16 +0100 |
commit | fae694a03ebb52888a747010fcb92fa43b33b4a8 (patch) | |
tree | ccd0d4e8d6a759eb8086d6a7da80316787b868ea /test | |
parent | 6ca37350f8e6bffe78520fddfc29ca53fa562e87 (diff) | |
download | ranger-fae694a03ebb52888a747010fcb92fa43b33b4a8.tar.gz |
better implementation of directories/files
Diffstat (limited to 'test')
-rw-r--r-- | test/tc_directory.py | 74 | ||||
l--------- | test/testdir/symlink | 1 | ||||
-rw-r--r-- | test/testdir/textfile.txt | 4 |
3 files changed, 54 insertions, 25 deletions
diff --git a/test/tc_directory.py b/test/tc_directory.py index b0a4b780..69717ba2 100644 --- a/test/tc_directory.py +++ b/test/tc_directory.py @@ -1,9 +1,10 @@ import unittest import sys, os sys.path.append('../code') -import directory +import directory, fsobject, file TESTDIR = os.path.realpath(os.path.join(os.path.dirname(sys.argv[0]), 'testdir')) +TESTFILE = os.path.join(TESTDIR, 'testfile5234148') NONEXISTANT_DIR = '/this/directory/will/most/certainly/not/exist' class Test1(unittest.TestCase): @@ -12,42 +13,54 @@ class Test1(unittest.TestCase): dir = directory.Directory(TESTDIR) self.assertEqual(dir.path, TESTDIR) - self.assertFalse(dir.files_loaded) + self.assertFalse(dir.content_loaded) + self.assertEqual(dir.filenames, None) self.assertEqual(dir.files, None) - self.assertRaises(directory.NotLoadedYet, len, dir) - self.assertRaises(directory.NotLoadedYet, dir.__getitem__, 0) + self.assertRaises(fsobject.NotLoadedYet, len, dir) + self.assertRaises(fsobject.NotLoadedYet, dir.__getitem__, 0) - def testAfterFilesLoaded(self): - # Check whether the directory has the correct list of files. + def testAfterContentLoaded(self): + # Check whether the directory has the correct list of filenames. dir = directory.Directory(TESTDIR) - dir.load_files() + dir.load_content() self.assertTrue(dir.exists) - self.assertEqual(type(dir.files), list) + self.assertEqual(type(dir.filenames), list) - # Get the files you expect it to have and sort both before - # comparing. I don't expect any order after only loading the files. - assumed_files = os.listdir(TESTDIR) - assumed_files.sort() - dir.files.sort() + # Get the filenames you expect it to have and sort both before + # comparing. I don't expect any order after only loading the filenames. + assumed_filenames = os.listdir(TESTDIR) + assumed_filenames.sort() + dir.filenames.sort() self.assertTrue(len(dir) > 0) - self.assertEqual(dir.files, assumed_files) + self.assertEqual(dir.filenames, assumed_filenames) + + # build a file object for each file in the list assumed_filenames + # and find exactly one equivalent in dir.files + for name in assumed_filenames: + f = file.File(name) + f.load() + equal = 0 + for dirfile in dir.files: + if (f.__dict__ == dirfile.__dict__): + equal += 1 + self.assertEqual(equal, 1) def testNonexistantDir(self): dir = directory.Directory(NONEXISTANT_DIR) - dir.load_files() + dir.load_content() - self.assertTrue(dir.files_loaded) + self.assertTrue(dir.content_loaded) self.assertFalse(dir.exists) self.assertFalse(dir.accessible) - self.assertEqual(dir.files, None) - self.assertRaises(directory.NotLoadedYet, len, dir) - self.assertRaises(directory.NotLoadedYet, dir.__getitem__, 0) + self.assertEqual(dir.filenames, None) + self.assertRaises(fsobject.NotLoadedYet, len, dir) + self.assertRaises(fsobject.NotLoadedYet, dir.__getitem__, 0) def testModifyFrozenClone(self): dir = directory.Directory(TESTDIR) - clone = dir.frozenClone() + clone = dir.frozen_clone() # assert that their attributes are equal, except for frozen, which # should be true for the clone. @@ -56,12 +69,23 @@ class Test1(unittest.TestCase): self.assertEqual(dir.__dict__, clone.__dict__) clone.frozen = True - # check for inequality after loading files with one object - self.assertEqual(dir.files, clone.files) - dir.load_files() - self.assertNotEqual(dir.files, clone.files) + # check for inequality after loading filenames with one object + self.assertEqual(dir.filenames, clone.filenames) + dir.load_content() + self.assertNotEqual(dir.filenames, clone.filenames) + + self.assertRaises(fsobject.FrozenException, clone.load_content) + + def test_load_if_outdated(self): + if os.path.exists(TESTFILE): os.unlink(TESTFILE) + dir = directory.Directory(TESTDIR) + dir.load() + + open(TESTFILE, 'w').close() + + self.assertTrue(dir.load_if_outdated()) - self.assertRaises(directory.FrozenException, clone.load_files) + os.unlink(TESTFILE) unittest.main() diff --git a/test/testdir/symlink b/test/testdir/symlink new file mode 120000 index 00000000..5cbc1596 --- /dev/null +++ b/test/testdir/symlink @@ -0,0 +1 @@ +textfile.txt \ No newline at end of file diff --git a/test/testdir/textfile.txt b/test/testdir/textfile.txt new file mode 100644 index 00000000..45a23497 --- /dev/null +++ b/test/testdir/textfile.txt @@ -0,0 +1,4 @@ +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. +Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. |