コード例 #1
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_run_explicit(self, *args):
     with mock.patch(
         "corral.run.execute_step", return_value=[]
     ) as execute_step:
         cli.run_from_command_line()
         expected = map(lambda s: mock.call(s, sync=True), run.load_steps())
         execute_step.assert_has_calls(expected)
コード例 #2
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_lsalerts_none(self, *args):
     with mock.patch("corral.run.load_alerts",
                     return_value=()) as load_alerts:
         with mock.patch("texttable.Texttable.add_rows") as add_rows:
             cli.run_from_command_line()
             add_rows.assert_not_called()
             self.assertTrue(load_alerts.called)
コード例 #3
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_lsalerts(self, *args):
     with mock.patch("corral.run.load_alerts") as load_alerts:
         with mock.patch("texttable.Texttable.header") as header:
             cli.run_from_command_line()
             header.assert_called_with(
                 ('Alert Class', 'Process', 'Groups'))
             self.assertTrue(load_alerts.called)
コード例 #4
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_stack_trace_option(self, *args):
     with mock.patch("sys.argv",
                     new=["test", "--stacktrace", "create", "foo"]):
         with self.assertRaises(Exception):
             cli.run_from_command_line()
     with mock.patch("sys.argv", new=["test", "create", "foo"]):
         cli.run_from_command_line()
コード例 #5
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_command_api(self, *args):
     with mock.patch("corral.core.setup_environment") as setup_environment:
         with mock.patch("tests.commands.TestAPICommand.setup") as setup:
             with mock.patch("tests.commands.TestAPICommand.handle") as hdl:
                 cli.run_from_command_line()
                 self.assertTrue(setup_environment.called)
                 self.assertTrue(setup.called)
                 self.assertTrue(hdl.called)
コード例 #6
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
    def test_create_db_comand_noinput(self, *args):
        patch = "corral.cli.commands.CreateDB.ask"
        with mock.patch(patch, return_value="yes") as ask:
            with mock.patch("corral.db.create_all") as create_all:
                cli.run_from_command_line()
                ask.assert_not_called()
                self.assertTrue(create_all.called)

        with mock.patch(patch, return_value="no") as ask:
            with mock.patch("corral.db.create_all") as create_all:
                cli.run_from_command_line()
                ask.assert_not_called()
                self.assertTrue(create_all.called)
コード例 #7
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_import_bpython_fails(self, *args):
     original = builtin_commands.Shell.run_bpython
     property_mock = mock.PropertyMock(side_effect=ImportError)
     try:
         builtin_commands.Shell.run_bpython = property_mock
         shell_cmd = builtin_commands.Shell()
         shell_cmd.configure(mock.Mock())
         shell_cmd.setup()
         with mock.patch("IPython.start_ipython") as start_ipython:
             cli.run_from_command_line()
             self.assertTrue(start_ipython.called)
     finally:
         builtin_commands.Shell.run_bpython = original
コード例 #8
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_import_ipython_and_bpython_fails(self, *args):
     ioriginal = builtin_commands.Shell.run_ipython
     boriginal = builtin_commands.Shell.run_bpython
     property_mock = mock.PropertyMock(side_effect=ImportError)
     try:
         builtin_commands.Shell.run_ipython = property_mock
         builtin_commands.Shell.run_bpython = property_mock
         shell_cmd = builtin_commands.Shell()
         shell_cmd.configure(mock.Mock())
         shell_cmd.setup()
         with mock.patch("code.InteractiveConsole.interact") as interact:
             cli.run_from_command_line()
             self.assertTrue(interact.called)
     finally:
         builtin_commands.Shell.run_ipython = ioriginal
         builtin_commands.Shell.run_bpython = boriginal
コード例 #9
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
    def test_default_shell_command(self, *args):
        mockeable_shell_calls = {
            "ipython": "IPython.start_ipython",
            "bpython": "bpython.embed",
            "plain": "code.InteractiveConsole.interact",
        }

        shell_cmd = builtin_commands.Shell()
        shell_cmd.configure(mock.Mock())
        shell_cmd.setup()
        shells = shell_cmd.shells

        first_shell = tuple(shells.keys())[0]
        to_mock = mockeable_shell_calls[first_shell]

        with mock.patch(to_mock) as call:
            cli.run_from_command_line()
            self.assertTrue(call.called)
コード例 #10
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_check_alerts_all_async(self, *args):
     call_count = len(run.load_alerts())
     with mock.patch("corral.run.alert.AlertRunner.start") as proc_start:
         with mock.patch("corral.run.alert.AlertRunner.join") as proc_join:
             with mock.patch("corral.run.alert.AlertRunner.exitcode", 0):
                 with mock.patch("sys.exit") as sys_exit:
                     cli.run_from_command_line()
                     self.assertEquals(proc_start.call_count, call_count)
                     self.assertEquals(proc_join.call_count, call_count)
                     sys_exit.assert_not_called()
     with mock.patch("corral.run.alert.AlertRunner.start") as proc_start:
         with mock.patch("corral.run.alert.AlertRunner.join") as proc_join:
             with mock.patch("corral.run.alert.AlertRunner.exitcode", 1):
                 with mock.patch("sys.exit") as sys_exit:
                     cli.run_from_command_line()
                     self.assertEquals(proc_start.call_count, call_count)
                     self.assertEquals(proc_join.call_count, call_count)
                     sys_exit.assert_called_once_with(call_count)
コード例 #11
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
    def test_create_db_comand(self, *args):
        patch = "corral.cli.commands.CreateDB.ask"
        with mock.patch(patch, return_value="yes") as ask:
            with mock.patch("corral.db.create_all") as create_all:
                cli.run_from_command_line()
                self.assertTrue(ask.called)
                self.assertTrue(create_all.called)

        with mock.patch(patch, return_value="no") as ask:
            with mock.patch("corral.db.create_all") as create_all:
                cli.run_from_command_line()
                self.assertTrue(ask.called)
                create_all.assert_not_called()

        with mock.patch(patch, side_effect=["foo", "no"]) as ask:
            with mock.patch("corral.db.create_all") as create_all:
                cli.run_from_command_line()
                expected = [
                    mock.call(arg) for arg in
                    ("Do you want to create the database [Yes/no]? ",
                     "Please answer 'yes' or 'no': ")]
                ask.assert_has_calls(expected)
                self.assertFalse(create_all.called)
コード例 #12
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_dbshell(self, *args):
     with mock.patch("corral.libs.sqlalchemy_sql_shell.run") as run_dbshell:
         with mock.patch("sys.stdout"):
             cli.run_from_command_line()
             run_dbshell.assert_called_with(db.engine)
コード例 #13
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_run_invalid_step(self, *args):
     with mock.patch("corral.run.execute_step"):
         with self.assertRaises(SystemExit):
             cli.run_from_command_line()
コード例 #14
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_ipython(self, *args):
     with mock.patch("IPython.start_ipython") as start_ipython:
         cli.run_from_command_line()
         self.assertTrue(start_ipython.called)
コード例 #15
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_bpython(self, *args):
     with mock.patch("bpython.embed") as embed:
         cli.run_from_command_line()
         self.assertTrue(embed.called)
コード例 #16
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_run_second(self, *args):
     with mock.patch("corral.run.execute_step") as execute_step:
         cli.run_from_command_line()
         expected = [mock.call(Step2, sync=True)]
         execute_step.assert_has_calls(expected)
コード例 #17
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_load(self, *args):
     with mock.patch("corral.run.execute_loader") as execute_loader:
         cli.run_from_command_line()
         execute_loader.assert_called_with(TestLoader, sync=True)
コード例 #18
0
ファイル: test_cli.py プロジェクト: EdwardBetts/corral
 def test_notebook_command(self, *args):
     with mock.patch("IPython.start_ipython") as start_ipython:
         cli.run_from_command_line()
         self.assertTrue(start_ipython.called)
         expected = [mock.call(argv=['notebook'])]
         start_ipython.assert_has_calls(expected)
コード例 #19
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_create_comand(self, create_pipeline):
     cli.run_from_command_line()
     create_pipeline.assert_called_with("foo")
コード例 #20
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_plain(self, *args):
     with mock.patch("code.InteractiveConsole.interact") as interact:
         cli.run_from_command_line()
         self.assertTrue(interact.called)
コード例 #21
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_check_alerts_invalid(self, *args):
     with mock.patch("corral.run.execute_alert"):
         with self.assertRaises(SystemExit):
             cli.run_from_command_line()
コード例 #22
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_duplicate_title(self, *args):
     patch = "tests.commands.TestAPICommand.options"
     with mock.patch.dict(patch, {"title": "exec"}):
         with self.assertRaises(exceptions.ImproperlyConfigured):
             cli.run_from_command_line()
コード例 #23
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_execfile(self, *args):
     path = os.path.abspath(os.path.dirname(__file__))
     script = os.path.join(path, "script.py")
     with mock.patch("sys.argv", new=["test", "exec", script]):
         cli.run_from_command_line()
コード例 #24
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_exit_error(self, *args):
     with mock.patch("corral.core.setup_environment"):
         with mock.patch("sys.exit") as sys_exit:
             cli.run_from_command_line()
             sys_exit.assert_called_once_with(
                 commands.TestExitErrorCommand.EXIT_STATUS)
コード例 #25
0
ファイル: test_cli.py プロジェクト: toros-astro/corral
 def test_notebook_command(self, *args):
     with mock.patch("notebook.notebookapp.NotebookApp.instance") as nb:
         cli.run_from_command_line()
         self.assertTrue(nb.called)
コード例 #26
0
ファイル: in_corral.py プロジェクト: toros-astro/toritos
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os

if __name__ == "__main__":
    os.environ.setdefault("CORRAL_SETTINGS_MODULE", "toritos.settings")

    from corral import cli
    cli.run_from_command_line()
コード例 #27
0
ファイル: in_corral.py プロジェクト: mardom/corral
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Created at ${timestamp} by corral ${version}

if __name__ == "__main__":
    import os

    os.environ.setdefault("CORRAL_SETTINGS_MODULE", "${project_name}.settings")

    from corral import cli
    cli.run_from_command_line()