def test_temp_environment(self): self.setup_modules_system() with env.temp_environment(['testmod_foo'], { '_var0': 'val2', '_var3': 'val3' }) as environ: assert environ.is_loaded assert not environ.is_loaded
def completion_time(self, job): if (self._completion_time or not slurm_state_completed(job.state)): return self._completion_time with env.temp_environment(variables={'SLURM_TIME_FORMAT': '%s'}): completed = os_ext.run_command( 'sacct -S %s -P -j %s -o jobid,end' % (self._submit_time.strftime('%F'), job.jobid), log=False) state_match = list( re.finditer(r'^(?P<jobid>%s)\|(?P<end>\S+)' % self._state_patt, completed.stdout, re.MULTILINE)) if not state_match: return None self._completion_time = max(float(s.group('end')) for s in state_match) return self._completion_time