Esempio n. 1
0
 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([])
Esempio n. 2
0
 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()
Esempio n. 3
0
 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')),
     ])
Esempio n. 4
0
    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)
Esempio n. 5
0
 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."
     )
Esempio n. 6
0
 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.'
     )
Esempio n. 7
0
 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')),
     ])
Esempio n. 8
0
 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')),
     ])
Esempio n. 9
0
 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."
     )
Esempio n. 10
0
 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)