summary refs log tree commit diff stats
path: root/test
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-11-24 00:41:16 +0100
committerhut <hut@lavabit.com>2009-11-24 00:41:16 +0100
commitfae694a03ebb52888a747010fcb92fa43b33b4a8 (patch)
treeccd0d4e8d6a759eb8086d6a7da80316787b868ea /test
parent6ca37350f8e6bffe78520fddfc29ca53fa562e87 (diff)
downloadranger-fae694a03ebb52888a747010fcb92fa43b33b4a8.tar.gz
better implementation of directories/files
Diffstat (limited to 'test')
-rw-r--r--test/tc_directory.py74
l---------test/testdir/symlink1
-rw-r--r--test/testdir/textfile.txt4
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.
60783869092916030288400269104140792886215078424516709087000699282120660418371806535567252532567532861291042487761825829765157959847035622262934860034158722980534989650226291748788202734209222245339856264766914905562842503912757710284027998066365825488926488025456610172967026640765590429099456815065265305371829412703369313785178609040708667114965583434347693385781711386455873678123014587687126603489139095620099393610310291616152881384379099042317473363948045759314931405297634757481193567091101377517210080315590248530906692037671922033229094334676851422144773793937517034436619910403375111735471918550464490263655128162288244625759163330391072253837421821408835086573917715096828874782656995995744906617583441375223970968340800535598491754173818839994469748676265516582765848358845314277568790029095170283529716344562129640435231176006651012412006597558512761785838292041974844236080071930457618932349229279650198751872127267507981255470958904556357921221033346697499235630254947802490114195212382815309114079073860251522742995818072471625916685451333123948049470791191532673430282441860414263639548000448002670496248201792896476697583183271314251702969234889627668440323260927524960357996469256504936818360900323809293459588970695365349406034021665443755890045632882250545255640564482465151875471196218443965825337543885690941130315095261793780029741207665147939425902989695946995565761218656196733786236256125216320862869222103274889218654364802296780705765615144632046927906821207388377814233562823608963208068222468012248261177185896381409183903673672220888321513755600372798394004152970028783076670944474560134556417254370906979396122571429894671543578468788614445812314593571984922528471605049221242470141214780573455105008019086996033027634787081081754501193071412233908663938339529425786905076431006383519834389341596131854347546495569781038293097164651438407007073604112373599843452251610507027056235266012764848308407611830130527932054274628654036036745328651057065874882256981579367897669742205750596834408697350201410206723585020072452256326513410559240190274216248439140359989535394590944070469120914093870012645600162374288021092764579310657922955249887275846101264836999892256959688159205600101655256375678