def should_perform_dry_run(self, path_is_dir, path_iterdir, subprocess_call, logging_info): click = mock.MagicMock() seq = JobSequence('MY_VERBOSE_VAR', 'my_default_dir', click=click) seq.run(None, None, verbose=2, dry_run=True) self.assertIsNone(os.environ.get('MY_VERBOSE_VAR')) path_iterdir.assert_has_calls([]) subprocess_call.assert_has_calls([])
def should_run_job_sequence(self, path_is_dir, path_iterdir, subprocess_call, logging_info): click = mock.MagicMock() seq = JobSequence('MY_VERBOSE_VAR', 'my_default_dir', click=click) seq.run(None, None, verbose=0) self.assertEqual(os.environ['MY_VERBOSE_VAR'], '') path_iterdir.assert_has_calls([]) subprocess_call.assert_not_called()
def should_combine_patterns(self, path_is_dir, path_iterdir, subprocess_call, logging_info): click = mock.MagicMock() seq = JobSequence('MY_VERBOSE_VAR', 'my_default_dir', click=click) seq.run(['ba', '!baz'], 'my_other_dir', verbose=2) self.assertEqual(os.environ['MY_VERBOSE_VAR'], 'vv') path_iterdir.assert_has_calls([]) subprocess_call.assert_has_calls([ self._job_call(Path('my_other_dir', 'bar')), ])
def should_run_cli(self, path_is_dir, path_iterdir, subprocess_call, logging_info, sys_exit): click = mock.MagicMock() seq = JobSequence('MY_VERBOSE_VAR', 'my_default_dir', click=click) seq.run = mock.MagicMock(return_value=1) click.command = mock.MagicMock( side_effect=lambda *args, **kwargs: (lambda x: x)) seq.verbose_option = mock.MagicMock( side_effect=lambda *args, **kwargs: (lambda x: x)) seq.dry_run_option = mock.MagicMock( side_effect=lambda *args, **kwargs: (lambda x: x)) seq.job_dir_option = mock.MagicMock( side_effect=lambda *args, **kwargs: (lambda x: x)) seq.patterns_argument = mock.MagicMock( side_effect=lambda *args, **kwargs: (lambda x: x)) seq.cli(['patterns'], None) seq.verbose_option.assert_called_with() seq.dry_run_option.assert_called_with() seq.job_dir_option.assert_called_with() seq.patterns_argument.assert_called_with() seq.run.assert_called_once_with(['patterns'], None, verbose=0, dry_run=False) sys_exit.assert_called_once_with(1)
def should_generate_dry_run_option(self): click = mock.MagicMock() seq = JobSequence('MY_VERBOSE_VAR', 'my_default_dir', click=click) result = seq.dry_run_option() click.option.assert_called_once_with( '--dry', 'dry_run', is_flag=True, help= "Dry run. Only report about actions, do not actually execute them. Implies at least one level in verbosity." )
def should_generate_verbose_option(self): click = mock.MagicMock() seq = JobSequence('MY_VERBOSE_VAR', 'my_default_dir', click=click) result = seq.verbose_option() click.option.assert_called_once_with( '-v', '--verbose', count=True, help= 'Verbosity level.Passed to jobs via $MY_VERBOSE_VAR.Has cumulative value, each flag adds one level to verbosity and one character to environment variable: MY_VERBOSE_VAR=vvv.' )
def should_run_on_specified_log_dir(self, path_is_dir, path_iterdir, subprocess_call, logging_info): click = mock.MagicMock() seq = JobSequence('MY_VERBOSE_VAR', 'my_default_dir', click=click) seq.run(None, 'my_other_dir', verbose=2) self.assertEqual(os.environ['MY_VERBOSE_VAR'], 'vv') path_iterdir.assert_has_calls([]) subprocess_call.assert_has_calls([ self._job_call(Path('my_other_dir', 'bar')), self._job_call(Path('my_other_dir', 'foo')), ])
def should_skip_missing_job_dirs(self, path_is_dir, path_iterdir, subprocess_call, logging_info): click = mock.MagicMock() seq = JobSequence('MY_VERBOSE_VAR', ['my_default_dir', 'my_other_dir'], click=click) seq.run(None, None, verbose=0) self.assertEqual(os.environ['MY_VERBOSE_VAR'], '') path_iterdir.assert_has_calls([]) subprocess_call.assert_has_calls([ self._job_call(Path('my_default_dir', 'bar')), self._job_call(Path('my_default_dir', 'foo.2')), ])
def should_generate_job_dir_option(self): click = mock.MagicMock() seq = JobSequence('MY_VERBOSE_VAR', 'my_default_dir', click=click) result = seq.job_dir_option() click.option.assert_called_once_with( '-d', '--dir', 'job_dirs', multiple=True, default=['my_default_dir'], show_default=True, help= "Custom directory with job files. Can be specified several times, job files from all directories are sorted and executed in total order." )
def should_generate_patterns_argument(self): click = mock.MagicMock() seq = JobSequence('MY_VERBOSE_VAR', 'my_default_dir', click=click) result = seq.patterns_argument() click.argument.assert_called_once_with('patterns', nargs=-1)