Example #1
0
 def setUp(self):
     self._tmp_dir = TemporaryDirectory(prefix='signac_collection_')
     self._fn_collection = os.path.join(self._tmp_dir.name, 'test.txt')
     self.addCleanup(self._tmp_dir.cleanup)
     with open(self._fn_collection, 'w') as file:
         for i in range(3):
             file.write('{"a": 0}\n')
Example #2
0
 def setUp(self):
     self._tmp_dir = TemporaryDirectory(prefix='h5store_')
     self.addCleanup(self._tmp_dir.cleanup)
     self.store = H5StoreManager(prefix=self._tmp_dir.name)
     with open(os.path.join(self._tmp_dir.name, 'other_file.txt'),
               'w') as file:
         file.write(r'blank\n')
Example #3
0
 def setUp(self):
     self._tmp_dir = TemporaryDirectory(prefix='signac_collection_')
     self._fn_json = os.path.join(self._tmp_dir.name, 'test.json')
     self.addCleanup(self._tmp_dir.cleanup)
     self.c = Collection.open(filename=':memory:')
     docs = [dict(_id=str(i)) for i in range(10)]
     self.c.update(docs)
     self.c.flush()
Example #4
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))
Example #5
0
 def setUp(self):
     self._tmp_dir = TemporaryDirectory(prefix='signac_')
     self.addCleanup(self._tmp_dir.cleanup)
     self._tmp_pr_a = os.path.join(self._tmp_dir.name, 'pr_a')
     self._tmp_pr_b = os.path.join(self._tmp_dir.name, 'pr_b')
     os.mkdir(self._tmp_pr_a)
     os.mkdir(self._tmp_pr_b)
     self.project_a = signac.Project.init_project(name='test-project-a',
                                                  root=self._tmp_pr_a)
     self.project_b = signac.Project.init_project(name='test-project-b',
                                                  root=self._tmp_pr_b)
Example #6
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))
Example #7
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))
Example #8
0
 def setUp(self):
     pythonpath = os.environ.get('PYTHONPATH')
     if pythonpath is None:
         pythonpath = [os.getcwd()]
     else:
         pythonpath = [os.getcwd()] + pythonpath.split(':')
     os.environ['PYTHONPATH'] = ':'.join(pythonpath)
     self.tmpdir = TemporaryDirectory(prefix='signac_')
     self.addCleanup(self.tmpdir.cleanup)
     self.cwd = os.getcwd()
     self.addCleanup(self.return_to_cwd)
     os.chdir(self.tmpdir.name)
Example #9
0
 def setUp(self):
     self._tmp_dir = TemporaryDirectory(prefix='signac_')
     self.addCleanup(self._tmp_dir.cleanup)
     self._tmp_pr = os.path.join(self._tmp_dir.name, 'pr')
     self._tmp_wd = os.path.join(self._tmp_dir.name, 'wd')
     os.mkdir(self._tmp_pr)
     self.config = signac.common.config.load_config()
     self.project = self.project_class.init_project(
         name='testing_test_project',
         root=self._tmp_pr,
         workspace=self._tmp_wd)
     self.project.config['default_host'] = 'testing'
Example #10
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))
Example #11
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')
Example #12
0
 def setUp(self):
     self._tmp_dir = TemporaryDirectory(prefix='signac-flow_')
     self.addCleanup(self._tmp_dir.cleanup)
     self.project = self.project_class.init_project(name='FlowTestProject',
                                                    root=self._tmp_dir.name)
 def setUp(self):
     MockScheduler.reset()
     self._tmp_dir = TemporaryDirectory(prefix='signac-flow_')
     self.addCleanup(self._tmp_dir.cleanup)
     self.project = FlowProject.init_project(name='FlowTestProject',
                                             root=self._tmp_dir.name)
Example #14
0
 def setUp(self):
     self._tmp_dir = TemporaryDirectory(prefix='signac_collection_')
     self._fn_collection = os.path.join(self._tmp_dir.name, 'test.txt')
     self.addCleanup(self._tmp_dir.cleanup)
     self.c = Collection.open(self._fn_collection, mode=self.mode)
     self.addCleanup(self.c.close)
Example #15
0
 def setUp(self):
     self._tmp_dir = TemporaryDirectory(prefix='signac_collection_')
     self._fn_collection = os.path.join(self._tmp_dir.name, 'test.txt')
     self.addCleanup(self._tmp_dir.cleanup)
     with Collection.open(self._fn_collection, 'w') as c:
         c.update([dict(_id=str(i)) for i in range(10)])
Example #16
0
 def setUp(self):
     self._tmp_dir = TemporaryDirectory(prefix='signac_')
     self.addCleanup(self._tmp_dir.cleanup)
Example #17
0
import signac
from signac.errors import Error
from signac.errors import BufferException
from signac.errors import BufferedFileError
from signac.common import six

from test_project import BaseProjectTest

if six.PY2:
    from tempdir import TemporaryDirectory
else:
    from tempfile import TemporaryDirectory

# Determine if we can run permission error tests
with TemporaryDirectory() as tmp_dir:
    path = os.path.join(tmp_dir, 'subdir')
    os.mkdir(path)
    mode = os.stat(path).st_mode
    try:
        os.chmod(path, S_IREAD)
        with open(os.path.join(path, 'testfile.txt'), 'w') as file:
            pass
    except OSError:
        ABLE_TO_PREVENT_WRITE = True
    else:
        ABLE_TO_PREVENT_WRITE = False
    finally:
        os.chmod(path, mode)

Example #18
0
 def setUp(self):
     self._tmp_dir = TemporaryDirectory(prefix='signac_test_h5store_')
     self._fn_store = os.path.join(self._tmp_dir.name, FN_STORE)
     self._fn_store_other = os.path.join(self._tmp_dir.name,
                                         'other_' + FN_STORE)
     self.addCleanup(self._tmp_dir.cleanup)
Example #19
0
 def setUp(self):
     self._tmp_dir = TemporaryDirectory(prefix='jsondict_')
     self._fn_dict = os.path.join(self._tmp_dir.name, FN_DICT)
     self.addCleanup(self._tmp_dir.cleanup)
Example #20
0
 def setUp(self):
     self._tmp_dir = TemporaryDirectory(prefix='signac_')
     self.addCleanup(self._tmp_dir.cleanup)
     self.doc = JSONDict(
         filename=os.path.join(self._tmp_dir.name, 'doc.json'))