Example #1
0
 def test2(self):
     name = tempfile.mktemp()
     data = "asdfsad"
     dsfile.setFileContents(filename=name, data=data)
     assert os.path.exists(name)
     dsfile.ensureAbsent(path=name)
     assert not os.path.exists(name)
Example #2
0
    def test(self):
        name = tempfile.mktemp()
        data = "hello"
        data2 = "I won't do what you tell me"
        dsfile.ensureAbsent(path=name)
        assert not os.path.exists(name)
        dsfile.setFileContents(filename=name, data=data)
        assert os.path.exists(name)
        self.assertEqual(data, dsfile.fileContents(filename=name))
        f = open(name, "r+")
        self.assertEqual(data, dsfile.fileContents(file=f))
        dsfile.setFileContents(file=f, data=data2)
        self.assertEqual(data2, dsfile.fileContents(file=f))
        self.assertEqual(data2, dsfile.fileContents(filename=name))

        # the following assert only works on win32
        if sys.platform == "win32":
            self.assertRaises(OSError, dsfile.ensureAbsent, name )
        
        f.close() # important on win32, or next line will fail (read lock)
        dsfile.ensureAbsent(path=name)
        assert not os.path.exists(name)