Пример #1
0
 def test_create_doc_dict_with_error_dryrun(self):
     proxy = _FileModifyProxy(dry_run=True)
     with pytest.raises(RuntimeError):
         with proxy.create_doc_backup(self.doc) as p:
             p["a"] = 0
             raise RuntimeError()
     assert len(self.doc) == 0
Пример #2
0
 def test_create_doc_dict_with_error_dryrun(self):
     proxy = _FileModifyProxy(dry_run=True)
     with self.assertRaises(RuntimeError):
         with proxy.create_doc_backup(self.doc) as p:
             p['a'] = 0
             raise RuntimeError()
     self.assertEqual(len(self.doc), 0)
Пример #3
0
 def test_create_doc_dict_dryrun(self):
     proxy = _FileModifyProxy(dry_run=True)
     with proxy.create_doc_backup(self.doc) as p:
         pass
     with proxy.create_doc_backup(self.doc) as p:
         p["a"] = 0
     assert len(self.doc) == 0
Пример #4
0
 def test_create_doc_dict_dryrun(self):
     proxy = _FileModifyProxy(dry_run=True)
     with proxy.create_doc_backup(self.doc) as p:
         pass
     with proxy.create_doc_backup(self.doc) as p:
         p['a'] = 0
     self.assertEqual(len(self.doc), 0)
Пример #5
0
 def test_create_doc_dict_with_error(self):
     proxy = _FileModifyProxy()
     with pytest.raises(RuntimeError):
         with proxy.create_doc_backup(self.doc) as p:
             p['a'] = 0
             raise RuntimeError()
     assert len(self.doc) == 0
Пример #6
0
 def test_create_doc_dict(self):
     proxy = _FileModifyProxy()
     with proxy.create_doc_backup(self.doc) as p:
         pass
     with proxy.create_doc_backup(self.doc) as p:
         p['a'] = 0
     self.assertEqual(len(self.doc), 1)
     self.assertEqual(self.doc['a'], 0)
Пример #7
0
 def test_create_doc_dict(self):
     proxy = _FileModifyProxy()
     with proxy.create_doc_backup(self.doc) as p:
         pass
     with proxy.create_doc_backup(self.doc) as p:
         p["a"] = 0
     assert len(self.doc) == 1
     assert self.doc["a"] == 0
Пример #8
0
 def test_remove(self):
     proxy = _FileModifyProxy()
     with TemporaryDirectory(prefix='signac_') as tmp:
         fn = os.path.join(tmp, 'test.txt')
         assert not os.path.isfile(fn)
         touch(fn)
         assert os.path.isfile(fn)
         proxy.remove(fn)
         assert not os.path.isfile(fn)
Пример #9
0
 def test_remove_dryrun(self):
     proxy = _FileModifyProxy(dry_run=True)
     with TemporaryDirectory(prefix="signac_") as tmp:
         fn = os.path.join(tmp, "test.txt")
         assert not os.path.isfile(fn)
         touch(fn)
         assert os.path.isfile(fn)
         proxy.remove(fn)
         assert os.path.isfile(fn)
Пример #10
0
 def test_remove_dryrun(self):
     proxy = _FileModifyProxy(dry_run=True)
     with TemporaryDirectory(prefix='signac_') as tmp:
         fn = os.path.join(tmp, 'test.txt')
         self.assertFalse(os.path.isfile(fn))
         touch(fn)
         self.assertTrue(os.path.isfile(fn))
         proxy.remove(fn)
         self.assertTrue(os.path.isfile(fn))
Пример #11
0
 def test_copy(self):
     proxy = _FileModifyProxy()
     with TemporaryDirectory(prefix='signac_') as tmp:
         fn_src = os.path.join(tmp, 'src.txt')
         fn_dst = os.path.join(tmp, 'dst.txt')
         touch(fn_src)
         self.assertTrue(os.path.isfile(fn_src))
         self.assertFalse(os.path.isfile(fn_dst))
         proxy.copy(fn_src, fn_dst)
         self.assertTrue(os.path.isfile(fn_src))
         self.assertTrue(os.path.isfile(fn_dst))
Пример #12
0
 def test_copy(self):
     proxy = _FileModifyProxy()
     with TemporaryDirectory(prefix="signac_") as tmp:
         fn_src = os.path.join(tmp, "src.txt")
         fn_dst = os.path.join(tmp, "dst.txt")
         touch(fn_src)
         assert os.path.isfile(fn_src)
         assert not os.path.isfile(fn_dst)
         proxy.copy(fn_src, fn_dst)
         assert os.path.isfile(fn_src)
         assert os.path.isfile(fn_dst)
Пример #13
0
 def test_copy_dry_run(self):
     proxy = _FileModifyProxy(dry_run=True)
     with TemporaryDirectory(prefix="signac_") as tmp:
         fn_src = os.path.join(tmp, "src.txt")
         fn_dst = os.path.join(tmp, "dst.txt")
         with open(fn_src, "w") as file:
             file.write("test")
         assert os.path.isfile(fn_src)
         assert not os.path.isfile(fn_dst)
         proxy.copy(fn_src, fn_dst)
         assert os.path.isfile(fn_src)
         assert not os.path.isfile(fn_dst)
Пример #14
0
 def test_copy_dry_run(self):
     proxy = _FileModifyProxy(dry_run=True)
     with TemporaryDirectory(prefix='signac_') as tmp:
         fn_src = os.path.join(tmp, 'src.txt')
         fn_dst = os.path.join(tmp, 'dst.txt')
         with open(fn_src, 'w') as file:
             file.write('test')
         self.assertTrue(os.path.isfile(fn_src))
         self.assertFalse(os.path.isfile(fn_dst))
         proxy.copy(fn_src, fn_dst)
         self.assertTrue(os.path.isfile(fn_src))
         self.assertFalse(os.path.isfile(fn_dst))
Пример #15
0
 def test_copytree(self):
     proxy = _FileModifyProxy()
     with TemporaryDirectory(prefix='signac_') as tmp:
         src = os.path.join(tmp, 'src')
         dst = os.path.join(tmp, 'dst')
         _mkdir_p(src)
         fn_src = os.path.join(src, 'test.txt')
         fn_dst = os.path.join(dst, 'test.txt')
         touch(fn_src)
         assert os.path.isfile(fn_src)
         assert not os.path.isfile(fn_dst)
         proxy.copytree(src, dst)
         assert os.path.isfile(fn_src)
         assert os.path.isfile(fn_dst)
Пример #16
0
 def test_copytree_dryrun(self):
     proxy = _FileModifyProxy(dry_run=True)
     with TemporaryDirectory(prefix="signac_") as tmp:
         src = os.path.join(tmp, "src")
         dst = os.path.join(tmp, "dst")
         _mkdir_p(src)
         fn_src = os.path.join(src, "test.txt")
         fn_dst = os.path.join(dst, "test.txt")
         touch(fn_src)
         assert os.path.isfile(fn_src)
         assert not os.path.isfile(fn_dst)
         proxy.copytree(src, dst)
         assert os.path.isfile(fn_src)
         assert not os.path.isfile(fn_dst)
Пример #17
0
 def test_copytree_dryrun(self):
     proxy = _FileModifyProxy(dry_run=True)
     with TemporaryDirectory(prefix='signac_') as tmp:
         src = os.path.join(tmp, 'src')
         dst = os.path.join(tmp, 'dst')
         _mkdir_p(src)
         fn_src = os.path.join(src, 'test.txt')
         fn_dst = os.path.join(dst, 'test.txt')
         touch(fn_src)
         self.assertTrue(os.path.isfile(fn_src))
         self.assertFalse(os.path.isfile(fn_dst))
         proxy.copytree(src, dst)
         self.assertTrue(os.path.isfile(fn_src))
         self.assertFalse(os.path.isfile(fn_dst))
Пример #18
0
 def test_create_backup(self):
     proxy = _FileModifyProxy()
     with TemporaryDirectory(prefix='signac_') as tmp:
         fn = os.path.join(tmp, 'test.txt')
         assert not os.path.isfile(fn)
         with open(fn, 'w') as file:
             file.write('a')
         assert os.path.isfile(fn)
         with proxy.create_backup(fn) as fn_backup:
             assert os.path.isfile(fn_backup)
         assert os.path.isfile(fn)
         assert not os.path.isfile(fn_backup)
         with pytest.raises(RuntimeError):
             with proxy.create_backup(fn) as fn_backup:
                 assert os.path.isfile(fn_backup)
                 with open(fn, 'w') as file:
                     file.write('b')
                 raise RuntimeError()
         assert os.path.isfile(fn)
         assert not os.path.isfile(fn_backup)
         with open(fn) as file:
             assert file.read() == 'a'
Пример #19
0
 def test_create_backup_dryrun(self):
     proxy = _FileModifyProxy(dry_run=True)
     with TemporaryDirectory(prefix="signac_") as tmp:
         fn = os.path.join(tmp, "test.txt")
         assert not os.path.isfile(fn)
         with open(fn, "w") as file:
             file.write("a")
         assert os.path.isfile(fn)
         with proxy.create_backup(fn) as fn_backup:
             assert not os.path.isfile(fn_backup)
         assert os.path.isfile(fn)
         assert not os.path.isfile(fn_backup)
         with pytest.raises(RuntimeError):
             with proxy.create_backup(fn) as fn_backup:
                 assert not os.path.isfile(fn_backup)
                 with open(fn, "w") as file:
                     file.write("b")
                 raise RuntimeError()
         assert os.path.isfile(fn)
         assert not os.path.isfile(fn_backup)
         with open(fn) as file:
             assert file.read() == "b"
Пример #20
0
 def test_create_backup_dryrun(self):
     proxy = _FileModifyProxy(dry_run=True)
     with TemporaryDirectory(prefix='signac_') as tmp:
         fn = os.path.join(tmp, 'test.txt')
         self.assertFalse(os.path.isfile(fn))
         with open(fn, 'w') as file:
             file.write('a')
         self.assertTrue(os.path.isfile(fn))
         with proxy.create_backup(fn) as fn_backup:
             self.assertFalse(os.path.isfile(fn_backup))
         self.assertTrue(os.path.isfile(fn))
         self.assertFalse(os.path.isfile(fn_backup))
         with self.assertRaises(RuntimeError):
             with proxy.create_backup(fn) as fn_backup:
                 self.assertFalse(os.path.isfile(fn_backup))
                 with open(fn, 'w') as file:
                     file.write('b')
                 raise RuntimeError()
         self.assertTrue(os.path.isfile(fn))
         self.assertFalse(os.path.isfile(fn_backup))
         with open(fn) as file:
             self.assertEqual(file.read(), 'b')