def test_file_open(self):
     with self.assertRaises(PermissionError):
         with open(self._path, 'wt', encoding='utf-8') as f:
             f.write('original')
             with FileReplace(self._path, mode='wt') as f:
                 f.write('hello')
     self.confirm('original')
Ejemplo n.º 2
0
 def test_exception_during_replace(self):
     with open(self._path, 'wt', encoding='utf-8') as f:
         f.write('original')
     with self.assertRaises(RuntimeError):
         with FileReplace(self._path, mode='wt') as f:
             f.write('hello')
             raise RuntimeError('doh')
     self.confirm('original')
Ejemplo n.º 3
0
 def test_file_open(self):
     if sys.platform.startswith('win'):
         # windows has file locking by default
         with self.assertRaises(PermissionError):
             with open(self._path, 'wt', encoding='utf-8') as f1:
                 f1.write('original')
                 with FileReplace(self._path, mode='wt') as f2:
                     f2.write('hello')
         self.confirm('original')
Ejemplo n.º 4
0
 def test_file_delete_during_replace(self):
     with FileReplace(self._path, mode='wt') as f:
         f.write('hello')
         os.remove(self._path)
     self.confirm('hello')
Ejemplo n.º 5
0
 def test_file_exists(self):
     with FileReplace(self._path, mode='wt') as f:
         f.write('hello')
     self.confirm('hello')
Ejemplo n.º 6
0
 def test_does_not_exist(self):
     os.remove(self._path)
     with FileReplace(self._path, mode='wt') as f:
         f.write('hello')
     self.confirm('hello')