summary refs log blame commit diff stats
path: root/all_tests.py
blob: 33b16f7f22235b01b82df44056058167cdbdaa49 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                 



                                                                   
 



                                                                                       
 

                                                                  
#!/usr/bin/python
"""Run all the tests inside the test/ directory as a test suite."""
if __name__ == '__main__':
	import unittest
	from test import *

	tests = []
	for key, val in vars().copy().items():
		if key.startswith('tc_'):
			tests.extend(v for k,v in vars(val).items() if type(v) == type)

	suite = unittest.TestSuite(map(unittest.makeSuite, tests))
	unittest.TextTestRunner(verbosity=2).run(suite)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

             




                                      

                                                                                                   






                                       

                                       
                                
                                          
 

                                                                             






                                                      
                                                               

                                              




                                                            
                               

                                                      




                                               



                                   




                                     
                                                









                                                        





                                                                
                               


                                    



                                                       
import fstype

class FrozenException(Exception): pass
class NotLoadedYet(Exception): pass

class FSObject(object):
	def __init__(self, path):
		if type(self) == FSObject:
			raise TypeError("FSObject is an abstract class and cannot be initialized.")
		self.path = path
		self.exists = False
		self.accessible = False
		self.marked = False
		self.tagged = False
		self.frozen = False
		self.loaded = False
		self.islink = False
		self.brokenlink = False
		self.stat = None
		self.type = fstype.Unknown

	# load() reads useful information about the file from the file system
	# and caches it in instance attributes.
	def load(self):
		self.stop_if_frozen()
		self.loaded = True

		import os
		try:
			self.stat = os.stat(self.path)
			self.islink = os.path.islink(self.path)
			self.exists = True
			self.accessible = True

			if os.path.isdir(self.path):
				self.type = fstype.Directory
			elif os.path.isfile(self.path):
				self.type = fstype.File
		except OSError:
			self.islink = False
			self.type = fstype.Nonexistent
			self.exists = False
			self.accessible = False

	def load_once(self):
		self.stop_if_frozen()
		if not self.loaded:
			self.load()
			return True
		return False

	def load_if_outdated(self):
		self.stop_if_frozen()
		import os

		if self.load_once(): return True

		real_mtime = os.stat(self.path).st_mtime
		cached_mtime = self.stat.st_mtime

		if real_mtime != cached_mtime:
			self.load()
			return True

		return False

	def clone(self):
		clone = type(self)(self.path)
		for key in iter(self.__dict__):
			clone.__dict__[key] = self.__dict__[key]
		return clone

	def frozen_clone(self):
		clone = self.clone()
		clone.frozen = True
		return clone

	def stop_if_frozen(self):
		if self.frozen: raise FrozenException()