Пример #1
0
class ApplicationWithEnvsTest(InvokableAppWithCommandTest):
    @patch.dict(os.environ, {}, clear=True)
    def set_up(self):
        test_env.reset_entries()
        self.application = Application(InvokableApplicationTest.APP_NAME,
                                       FakeCommand)

    def _register_dir(self, directory: str):
        self.application.register_config_directory(
            os.path.join(DATA_DIR, 'cfgdirs', directory))

    def _register_dirs(self):
        self._register_dir('dir1')
        self._register_dir('dir2')
        self._register_dir('dir3')

    def _asssert_env_after_run(self,
                               expected_list: typing.List[str],
                               env_name: str = None):
        self._invoke_application(['-e', env_name or 'foobar', 'fake'],
                                 expected_exit_value=42)
        self._asssert_env(expected_list)

    def _asssert_env(self, expected_list: typing.List[str]):
        self.assert_equal(expected_list, test_env.entries,
                          'Mismatching list of env strings in test_env')

    def test_all_env_with_name_foobar(self):
        self._register_dirs()
        self._asssert_env_after_run(
            ['dir1-common', 'dir2-common', 'dir2-foobar', 'dir3-foobar'])

    def test_all_env_with_name_test(self):
        self._register_dirs()
        self._asssert_env_after_run(
            ['dir1-common', 'dir2-common', 'dir2-test'], 'test')

    def test_all_env_with_default_env(self):
        self.assert_equal('development',
                          self.application._env_config.current_env)
        self._register_dirs()
        self._invoke_application(['fake'], expected_exit_value=42)
        self.assert_equal('development',
                          self.application._env_config.current_env)
        self._asssert_env(['dir1-common', 'dir2-common', 'dir2-dev'])

    @patch.dict(
        os.environ,
        {'DEWI_ENV': 'production'},
    )
    def test_all_env_with_env_var(self):
        self.application = Application(InvokableApplicationTest.APP_NAME,
                                       FakeCommand)
        self.assert_equal('production',
                          self.application._env_config.current_env)
        self._register_dirs()
        self._invoke_application(['fake'], expected_exit_value=42)
        self.assert_equal('production',
                          self.application._env_config.current_env)
        self._asssert_env(['dir1-common', 'dir2-common', 'dir2-prod'])
Пример #2
0
 def test_all_env_with_env_var(self):
     self.application = Application(InvokableApplicationTest.APP_NAME,
                                    FakeCommand)
     self.assert_equal('production',
                       self.application._env_config.current_env)
     self._register_dirs()
     self._invoke_application(['fake'], expected_exit_value=42)
     self.assert_equal('production',
                       self.application._env_config.current_env)
     self._asssert_env(['dir1-common', 'dir2-common', 'dir2-prod'])
Пример #3
0
def main():
    if int(os.environ.get('DEWI_CORE_DEV_WITH_PLUGINS', '0')) == 1:
        app = Application('dewi-review')
        app.load_plugin('dewi_core.commands.review.ReviewPlugin')
    else:
        app = Application('dewi-review', ReviewCommand)
    app.run()
Пример #4
0
def main():
    if int(os.environ.get('DEWI_CORE_DEV_WITH_PLUGINS', '0')) == 1:
        app = Application('dewi-edit')
        app.load_plugin('dewi_core.commands.edit.edit.EditPlugin')
    else:
        app = Application('dewi-edit', EditCommand)
    app.run(sys.argv[1:])
Пример #5
0
def main():
    app = Application('steven')
    app.load_plugin('steven.StevenPlugin')
    app.run(sys.argv[1:])

    if __name__ == '__main__':
        main()
Пример #6
0
def main():
    app = Application('dewi-packt', PacktCommand)
    app.run(sys.argv[1:])
Пример #7
0
def main():
    app = Application('dewi-hash', HashCommand)
    app.run(sys.argv[1:])
Пример #8
0
def main():
    app = Application('dewi-http', HttpCommand)
    app.run(sys.argv[1:])
Пример #9
0
 def set_up(self):
     self.application = Application(self.APP_NAME)
     self.application.add_command_class(FakeCommand)
Пример #10
0
def main():
    app = Application('dewi-filesync', FileSyncCommand)
    app.run(sys.argv[1:])
Пример #11
0
def main():
    app = Application('dewi-stocks', StocksCommand)
    app.run(sys.argv[1:])
Пример #12
0
def main():
    app = Application('dewi-dedup-images', ImageDeduplicatorCommand)
    app.run(sys.argv[1:])
Пример #13
0
def main():
    app = Application('dewi-json-formatter', JsonFormatterCommand)
    app.run(sys.argv[1:])
Пример #14
0
def main():
    app = Application('dewi-worktime', WorktimeCommand)
    app.run(sys.argv[1:])
Пример #15
0
def main():
    app = Application('dewi-lithurgical', LithurgicalCommand)
    app.run(sys.argv[1:])
Пример #16
0
def main():
    app = Application('dewi-edit-or-review')
    app.load_plugin('dewi_core.commands.edit.edit.EditPlugin')
    app.load_plugin('dewi_core.commands.review.ReviewPlugin')
    app.load_plugin('dewi_core.commands.editreview.EditReviewPlugin')
    app.run()
Пример #17
0
class ApplicationTest(InvokableAppWithCommandTest):
    @patch.dict(os.environ, {}, clear=True)
    def set_up(self):
        self.application = Application(self.APP_NAME)
        self.application.add_command_class(FakeCommand)

    def test_help_option(self):
        self.assert_help_option(suffix='[OPTIONS] COMMAND [ARGS]')

    def test_that_a_command_name_is_requiredto_run(self):
        self.assert_list_command()

    def test_list_command(self):
        self.assert_list_command()

    def test_list_all_command(self):
        self.assert_list_all_command()

    def test_command_run_method_is_called(self):
        self.assert_fake_command_run(['fake'])

    def test_command_run_method_exception_is_handled(self):
        redirect = self._invoke_application_redirected(['fake', 'ERROR'],
                                                       expected_exit_value=1)
        self.assert_equal('', redirect.stdout.getvalue())
        self.assert_in('Fake Command Error', redirect.stderr.getvalue())

    def test_command_run_method_exception_is_handled_in_debug_mode(self):
        redirect = self._invoke_application_redirected(['-d', 'fake', 'ERROR'],
                                                       expected_exit_value=1)

        self.assert_in('Exception occurred:\n', redirect.stdout.getvalue())
        self.assert_in(' Type: RuntimeError\n', redirect.stdout.getvalue())
        self.assert_in(' Message: Fake Command Error\n',
                       redirect.stdout.getvalue())
        self.assert_in(
            '/dewi_core/tests/test_application.py:XX in run\n',
            re.sub(r'dewi_core/tests/test_application.py:([0-9]+)',
                   'dewi_core/tests/test_application.py:XX',
                   redirect.stdout.getvalue()))
        self.assert_in('Fake Command Error', redirect.stderr.getvalue())

    def test_unknown_command(self):
        """
        Test that the output is something like the following,
        without checking the exact space character count between the command name (fake)
        and the description (- A fake command for tests).

        ---8<---
        ERROR: The command 'unknown-name' is not known.

        Available commands and aliases:
        fake                             - A fake command for tests
        --->8---
        """

        redirect = self._invoke_application_redirected(['unknown-name'],
                                                       expected_exit_value=1)
        self.assert_equal('', redirect.stderr.getvalue())

        output = redirect.stdout.getvalue()
        self.assert_in("ERROR: The command 'unknown-name' is not known.\n",
                       output)
        self.assert_in(
            "Similar names - firstly based on command name length:\n", output)
        self.assert_not_in(" list-all ", output)
        self.assert_in(" not-so-fake ", output)

    def test_run_help_of_command(self):
        redirect = self._invoke_application_redirected(['fake', '--help'],
                                                       expected_exit_value=0)
        self.assert_in(f'{self.APP_NAME} fake [OPTIONS]',
                       redirect.stdout.getvalue())
        self.assert_equal('', redirect.stderr.getvalue())
Пример #18
0
def main():
    app = Application('dewi-safe-delete-images', SafeEraserCommand)
    app.run(sys.argv[1:])
Пример #19
0
 def set_up(self):
     self.application = Application(self.APP_NAME, FakeCommand)
Пример #20
0
def main():
    app = Application('steven')
    app.load_plugin('steven.StevenPlugin')
    app.run(sys.argv[1:])
Пример #21
0
 def set_up(self):
     test_env.reset_entries()
     self.application = Application(InvokableApplicationTest.APP_NAME,
                                    FakeCommand)
Пример #22
0
def main():
    app = Application('dewi-primes', PrimesCommand)
    app.run(sys.argv[1:])
Пример #23
0
def main():
    app = Application('dewi-sysinfo', SysInfoCommand)
    app.run(sys.argv[1:])
Пример #24
0
def main():
    app = Application('steven-ssh', XSshCommand)
    app.run(sys.argv[1:])
Пример #25
0
def main():
    app = Application('dewi-collect-images', ImageCollectorCommand)
    app.run(sys.argv[1:])
Пример #26
0
def main():
    app = Application('dewi-dice', DiceCommand)
    app.run(sys.argv[1:])
Пример #27
0
def main():
    app = Application('dewi-sort-photos', PhotoSorterCommand)
    app.run(sys.argv[1:])
Пример #28
0
def main():
    app = Application('dewi-find', FindCommand)
    app.run(sys.argv[1:])
Пример #29
0
def main():
    app = Application('dewi-split-zorp-log', SplitZorpLogCommand)
    app.run(sys.argv[1:])
Пример #30
0
def main():
    app = Application('dewi-fetch-covidhu', FetchCovidHuCommand)
    app.run(sys.argv[1:])