Ejemplo n.º 1
0
def test_archive_project(mock_client):
    runner = _CliRunner()
    result = runner.invoke(
        _main._flyte_cli,
        ["archive-project", "-p", "foo", "-h", "a.b.com", "-i"])
    assert result.exit_code == 0
    mock_client().update_project.assert_called_with(
        _Project.archived_project("foo"))
Ejemplo n.º 2
0
def test_list_projects(mock_client):
    mock_client().list_projects_paginated.return_value = ([], "")
    runner = _CliRunner()
    result = runner.invoke(
        _main._flyte_cli, ["list-projects", "-h", "a.b.com", "-i", "--filter", "ne(state,-1)", "--sort-by", "asc(name)"]
    )
    assert result.exit_code == 0
    mock_client().list_projects_paginated.assert_called_with(
        limit=100,
        token="",
        filters=[_filters.Filter.from_python_std("ne(state,-1)")],
        sort_by=_admin_common.Sort.from_python_std("asc(name)"),
    )
Ejemplo n.º 3
0
 def run(args):
     os.environ.setdefault('LC_CTYPE', 'ko_KR.UTF-8')
     runner = _CliRunner()
     if app_type:
         backup = cli._AppType
         cli._AppType = app_type
     else:
         backup = None
     try:
         return runner.invoke(cli.cli, args)
     finally:
         if app_type:
             cli._AppType = backup
Ejemplo n.º 4
0
    def _run_main(self, main, args):
        if _ClickCommand is not None and isinstance(main, _ClickCommand):
            if "LANG" not in os.environ:
                # Avoid click complaining about unicode for tests that mock env vars
                os.environ["LANG"] = "en_US.UTF-8"

            runner = _CliRunner()
            r = runner.invoke(main, args=args)
            return ClickWrapper(r.output, None, r.exit_code, r.exception)

        if callable(main):
            result = ClickWrapper(None, None, None, None)
            try:
                result.stdout = main()
                result.exit_code = 0

            except AssertionError:
                raise

            except SystemExit as e:
                if isinstance(e.code, int):
                    result.exit_code = e.code

                else:
                    result.exit_code = 1
                    result.stderr = stringified(e)

            except BaseException as e:
                result.exit_code = 1
                result.exception = e
                result.stderr = stringified(e)

            return result

        if isinstance(main, str):
            script = self._resolved_script(main)
            if not script:
                assert False, "Can't find script '%s', invalid main" % script

            r = runez.run(sys.executable, script, *args, fatal=False)
            return ClickWrapper(r.output, r.error, r.exit_code, r.exc_info)

        assert False, "Can't invoke invalid main: %s" % main