Beispiel #1
0
def test_from_config_dict_calls(mocker):
    cd = mocker.Mock(
        ConfigDict,
        **{
            "get_comma_list.return_value": ["foo.py", "bar/"],
            "get_check_set.return_value": sentinel.CHECK_SET,
            "get_path_list.return_value": sentinel.PATH_LIST,
        },
    )
    cfg = Configuration.from_config_dict(cd)
    assert attr.asdict(cfg, recurse=False) == {
        "select": sentinel.CHECK_SET,
        "ignore": sentinel.CHECK_SET,
        "toplevel": ["foo.py", "bar"],
        "package_paths": sentinel.PATH_LIST,
        "src_dirs": sentinel.PATH_LIST,
        "package_omit": ["foo.py", "bar/"],
    }
    assert cd.get_check_set.call_count == 2
    cd.get_check_set.assert_any_call("select")
    cd.get_check_set.assert_any_call("ignore")
    assert cd.get_comma_list.call_count == 2
    cd.get_comma_list.assert_any_call("toplevel")
    cd.get_comma_list.assert_any_call("package_omit")
    assert cd.get_path_list.call_count == 2
    cd.get_path_list.assert_any_call("package")
    cd.get_path_list.assert_any_call("src_dir")
Beispiel #2
0
def test_from_config_file_no_arg(mocker, cfgdict):
    cdmock = mocker.patch('check_wheel_contents.config.ConfigDict',
                          autospec=True)
    cdmock.find_default.return_value = cfgdict
    if cfgdict is None:
        expected = Configuration()
    else:
        expected = Configuration.from_config_dict(cfgdict)
    cfg = Configuration.from_config_file()
    assert cfg == expected
    assert cdmock.method_calls == [mocker.call.find_default()]
Beispiel #3
0
def test_from_config_file(mocker, cfgdict):
    cdmock = mocker.patch('check_wheel_contents.config.ConfigDict',
                          autospec=True)
    cdmock.from_file.return_value = cfgdict
    if cfgdict is None:
        expected = Configuration()
    else:
        expected = Configuration.from_config_dict(cfgdict)
    path = '/foo/bar/quux'
    cfg = Configuration.from_config_file(path)
    assert cfg == expected
    assert cdmock.method_calls == [mocker.call.from_file(Path(path))]
Beispiel #4
0
def test_from_config_dict(cfgdict, expected):
    assert Configuration.from_config_dict(cfgdict) == expected