Add files from the old svn, r101.
[matthijs/upstream/mobilegtd.git] / tests / specs / persistence / file_based_spec.py
1 import unittest
2 import os,tempfile,shutil
3 import inout.io
4 from inout import io
5
6
7 class FileSystemBasedBehaviour(unittest.TestCase):
8         def setUp(self):
9                 self.current_dir = os.getcwd()
10                 self.tempdir = tempfile.mkdtemp()
11                 os.chdir(self.tempdir)
12         def tearDown(self):
13                 os.chdir(self.current_dir)
14                 #shutil.rmtree(self.tempdir,True)
15
16         def create_file(self,path):
17                 inout.io.create_file(path).close()
18
19         def assertCreatedFile(self,path,error_message = None):
20                 if not error_message:
21                         error_message = u"The file %s should have been created"%repr(path)
22                 self.assertTrue(os.path.isfile(io.os_encode(path)),error_message)
23
24 class FileBasedBehaviour(FileSystemBasedBehaviour):
25
26         def file_content(self):
27                 f=file(self.path(),'r')
28                 raw=f.read()
29                 f.close()
30                 return raw
31
32         def create_file(self,path=None):
33                 if path == None:
34                         path = self.path()
35                 super(FileBasedBehaviour,self).create_file(path)
36
37         def write(self,content,path=None):
38                 if path == None:
39                         path = self.path()
40                 inout.io.write(path,content)
41
42
43 __all__= ["FileBasedBehaviour","FileSystemBasedBehaviour"]