Exemple #1
0
def test_main_various_args(run_command_mock, docopt_mock, args):
    docopt_mock.return_value = args
    # add common args and expected arg manipulations
    args['--namespace'] = 'foo'
    args['--retries'] = int(args['--retries'])
    args['--interactive'] = True
    args['<name>'] = args['<name>']
    main()
    run_command_mock.assert_called_with(args)
Exemple #2
0
def test_main_invalid_names(docopt_mock):
    """ Test that an invalid name throws a ValueError """
    args = {
        # underscore should not be allowed in name for the init command
        "init": True,
        "<name>": "foo_bar"
    }
    docopt_mock.return_value = args
    with pytest.raises(ValueError):
        main()
Exemple #3
0
def test_main_uncaught_exception(docopt_mock, run_command_mock):
    """tests what happens when some part of the program fails"""
    run_command_mock.side_effect = Exception
    with catch_stdout() as output:
        with pytest.raises(Exception):
            main()
        output = output.getvalue()
        assert "You've discovered a bug! Please make an issue on " + \
            "https://github.com/IntelAI/mlt/issues if one does not " + \
            "exist already." in output, output
Exemple #4
0
def test_main_invalid_namespace(docopt_mock):
    """ Test that an invalid namespace throws a ValueError """
    args = {
        "<name>": "foo",
        # underscore should not be allowed in namespace
        "--namespace": "foo_bar",
        "-i": False,
        "--retries": 5
    }
    docopt_mock.return_value = args
    with pytest.raises(ValueError):
        main()
        run_command(args)
Exemple #5
0
def test_main_set_remove_name(docopt_mock, command):
    """ Ensure that set and unset commands require name arg."""
    args = {
        command: True,
        "--namespace": "foo",
        "<name>": "",
        "-i": False,
        "-l": False,
        "-v": False,
        "--retries": 5
    }
    docopt_mock.return_value = args
    with pytest.raises(ValueError):
        main()
Exemple #6
0
def test_main_load_args(docopt_mock, run_command_mock):
    """Set env var and verify that it's loaded in the args"""
    args = {
        "--namespace": "foo",
        "<name>": "bar",
        "-i": False,
        "-l": False,
        "-v": False,
        "--retries": 5,
        "status": True
    }
    docopt_mock.return_value = args
    os.environ["MLT_REGISTRY"] = "gcr.io/foobar"
    os.environ["MLT_SKIP_CRD_CHECK"] = "True"
    main()
    # can't check `.items() <= .items()` here because of python2
    assert args["registry"] == "gcr.io/foobar", args["registry"]
    assert args["skip-crd-check"] is True, args["skip-crd-check"]