def test_directory_sandbox(): with temporary_dir() as d: ds1 = DirectorySandbox(os.path.join(d, 'task1')) ds2 = DirectorySandbox(os.path.join(d, 'task2')) ds1.create() ds2.create() assert os.path.exists(ds1.root) assert os.path.exists(ds2.root) ds1.destroy() assert not os.path.exists(ds1.root) assert os.path.exists(ds2.root) ds2.destroy() assert not os.path.exists(ds2.root)
def test_create(chmod, chown, getpwnam, getgrgid): getgrgid.return_value.gr_name = 'foo' getpwnam.return_value.pw_gid = 123 getpwnam.return_value.pw_uid = 456 with temporary_dir() as d: real_path = os.path.join(d, 'sandbox') ds = DirectorySandbox(real_path, 'cletus') ds.create() assert os.path.exists(real_path) getpwnam.assert_called_with('cletus') getgrgid.assert_called_with(123) chown.assert_called_with(real_path, 456, 123) chmod.assert_called_with(real_path, 0700)
def yield_runner(self, runner_class, **bindings): with contextlib.nested(temporary_dir(), temporary_dir()) as (td1, td2): sandbox = DirectorySandbox(td1) checkpoint_root = td2 task_runner = runner_class( runner_pex=os.path.join('dist', 'thermos_runner.pex'), task_id='hello_world', task=TASK.bind(**bindings).task(), role=getpass.getuser(), portmap={}, sandbox=sandbox, checkpoint_root=checkpoint_root, ) yield task_runner
def from_assigned_task(self, assigned_task): return DirectorySandbox(safe_mkdtemp())