Esempio n. 1
0
def test_echo_is_type_dependent_and_access_dependent(maptype, getter, key,
                                                     expected):
    """ Retrieval of missing key/attr echoes it iff the type and access mode permit. """
    m = maptype()
    assert key not in m
    with ExpectContext(expected, getter) as ctx:
        ctx(m, key)
def test_select_local_config_file(tmpdir, setup, expect):
    """Selection of local filepath hinges on its existence as a file"""
    with TmpEnv(overwrite=True, **{ev: "" for ev in CFG_ENV_VARS}):
        _check_no_env_vars()
        path = setup(tmpdir)
        print("Path: {}".format(path))
        with ExpectContext(expect(path), select_genome_config) as ctx:
            ctx(path)
Esempio n. 3
0
def test_check_all_result_is_conjunctive(create_result, expected,
                                         str_list_monad):
    """ Even one uncallable means result is False or an Exception occurs. """
    cmd = "noncmd"
    with mock.patch.object(piper_utils, "determine_uncallable",
                           return_value=[(cmd, cmd)]), \
        ExpectContext(expected, piper_utils.check_all_commands) as check:
        check(cmds=str_list_monad(cmd), get_bad_result=create_result)
Esempio n. 4
0
def test_check_all_bad_handler_is_type_error_iff_uncallability_exists(
        uncall_result, str_list_monad, handler, expectation):
    """ Invalid handler evaluation is conditional having >= 1 uncallable command. """
    cmd = "noncmd"
    with mock.patch.object(piper_utils, "determine_uncallable",
                           return_value=uncall_result), \
         ExpectContext(expectation, piper_utils.check_all_commands) as check:
        check(cmds=str_list_monad(cmd), handle=handler)
Esempio n. 5
0
def test_exp_ctx_ordinary_result(exp_res, fun, expect_success, args, kwargs):
    """ The expectation context correctly handles ordinary expectation. """
    try:
        with ExpectContext(expected=exp_res, test_func=fun) as ctx:
            res = ctx(*args, **kwargs)
    except AssertionError as e:
        if expect_success:
            pytest.fail("Expected success but assertion failed: {}".format(e))
    else:
        if not expect_success:
            pytest.fail("Unexpected function execution success (feigned "
                        "expectation {} and got {})".format(exp_res, res))
Esempio n. 6
0
def test_exp_ctx_exceptional_result(err, fun, expect_success, args, kwargs):
    """ The expectation context correctly handles exceptional expectation. """
    try:
        with ExpectContext(expected=err, test_func=fun) as ctx:
            ctx(*args, **kwargs)
    except AssertionError as e:
        if expect_success:
            # Wrong failure type
            pytest.fail(str(e))
    except Exception as e:
        if expect_success:
            pytest.fail("Expected to catch a {} but hit {}".
                        format(type(err), type(e)))
Esempio n. 7
0
def test_command_callability_check_basic(cmd, exp):
    """ Verify expected behavior of command callability checker. """
    with ExpectContext(exp, is_command_callable) as check_callable:
        check_callable(cmd)