X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=tests%2Fspecs%2Fpersistence%2Ffile_based_spec.py;fp=tests%2Fspecs%2Fpersistence%2Ffile_based_spec.py;h=c13b774cd6eb3fbe5373e7270a8890fb483a0797;hb=826cc2e9923c858d3c6a86c04f371cfb326e1728;hp=0000000000000000000000000000000000000000;hpb=44f7fa2ef41d54548aa800b2bb71a886261c5046;p=matthijs%2Fupstream%2Fmobilegtd.git diff --git a/tests/specs/persistence/file_based_spec.py b/tests/specs/persistence/file_based_spec.py new file mode 100644 index 0000000..c13b774 --- /dev/null +++ b/tests/specs/persistence/file_based_spec.py @@ -0,0 +1,43 @@ +import unittest +import os,tempfile,shutil +import inout.io +from inout import io + + +class FileSystemBasedBehaviour(unittest.TestCase): + def setUp(self): + self.current_dir = os.getcwd() + self.tempdir = tempfile.mkdtemp() + os.chdir(self.tempdir) + def tearDown(self): + os.chdir(self.current_dir) + #shutil.rmtree(self.tempdir,True) + + def create_file(self,path): + inout.io.create_file(path).close() + + def assertCreatedFile(self,path,error_message = None): + if not error_message: + error_message = u"The file %s should have been created"%repr(path) + self.assertTrue(os.path.isfile(io.os_encode(path)),error_message) + +class FileBasedBehaviour(FileSystemBasedBehaviour): + + def file_content(self): + f=file(self.path(),'r') + raw=f.read() + f.close() + return raw + + def create_file(self,path=None): + if path == None: + path = self.path() + super(FileBasedBehaviour,self).create_file(path) + + def write(self,content,path=None): + if path == None: + path = self.path() + inout.io.write(path,content) + + +__all__= ["FileBasedBehaviour","FileSystemBasedBehaviour"]