Beispiel #1
0
def test_get_explicit_config_file_existing_single_and_plural_dir_via_env(
        fs_fast):
    exists_dir_1 = "/var/some-dir-to-look-for-configs"
    exists_dir_2 = "/var/another-dir-to-look-for-configs"
    exists_dir_3 = "/var/yet-anothe-dir-to-look-for-configs"

    fs_fast.create_dir(exists_dir_1)
    fs_fast.create_dir(exists_dir_2)
    fs_fast.create_dir(exists_dir_3)

    assert os.path.isdir(exists_dir_1)
    assert os.path.isdir(exists_dir_2)
    assert os.path.isdir(exists_dir_3)

    # combine singular and plural and filter dupes
    mock_environ = {
        "SG_CONFIG_DIR": exists_dir_1,
        "SG_CONFIG_DIRS":
        "%s:%s:%s" % (exists_dir_1, exists_dir_2, exists_dir_3),
    }

    with patch_os_environ(mock_environ):
        dirs = get_explicit_config_file_dirs()

        assert len(dirs) == 3
        assert exists_dir_1 in dirs
        assert exists_dir_2 in dirs
        assert exists_dir_3 in dirs
Beispiel #2
0
def test_get_explicit_config_file_existing_single_and_plural_dir_via_arg(
        fs_fast):
    exists_dir_1 = "/var/some-dir-to-look-for-configs"
    exists_dir_2 = "/var/another-dir-to-look-for-configs"
    exists_dir_3 = "/var/yet-anothe-dir-to-look-for-configs"

    fs_fast.create_dir(exists_dir_1)
    fs_fast.create_dir(exists_dir_2)
    fs_fast.create_dir(exists_dir_3)

    assert os.path.isdir(exists_dir_1)
    assert os.path.isdir(exists_dir_2)
    assert os.path.isdir(exists_dir_3)

    # combine singular and plural and filter dupes
    mock_sysargv = [
        "sg",
        "--config-dir",
        exists_dir_1,
        "--config-dirs",
        "%s:%s:%s" % (exists_dir_1, exists_dir_2, exists_dir_3),
    ]

    with patch.object(sys, "argv", mock_sysargv):
        dirs = get_explicit_config_file_dirs()

        assert len(dirs) == 3
        assert exists_dir_1 in dirs
        assert exists_dir_2 in dirs
        assert exists_dir_3 in dirs
Beispiel #3
0
def test_get_explicit_config_file_non_existing_single_dir_via_arg(fs_fast):
    dne_dir = "/var/some-nonexisting-dir-to-look-for-configs"

    assert not os.path.isdir(dne_dir)

    # singular
    mock_sysargv = ["sg", "--config-dir", dne_dir]

    with patch.object(sys, "argv", mock_sysargv):
        dirs = get_explicit_config_file_dirs()

        assert len(dirs) == 0
Beispiel #4
0
def test_get_explicit_config_file_non_existing_single_dir_via_env(fs_fast):
    dne_dir = "/var/some-nonexisting-dir-to-look-for-configs"

    assert not os.path.isdir(dne_dir)

    # singular
    mock_environ = {"SG_CONFIG_DIR": dne_dir}

    with patch_os_environ(mock_environ):
        dirs = get_explicit_config_file_dirs()

        assert len(dirs) == 0
Beispiel #5
0
def test_get_explicit_config_file_existing_single_dir_via_arg(fs_fast):
    exists_dir = "/var/some-dir-to-look-for-configs"

    fs_fast.create_dir(exists_dir)

    assert os.path.isdir(exists_dir)

    # singular
    mock_sysargv = ["sg", "--config-dir", exists_dir]

    with patch.object(sys, "argv", mock_sysargv):
        dirs = get_explicit_config_file_dirs()

        assert len(dirs) == 1
        assert exists_dir in dirs
Beispiel #6
0
def test_get_explicit_config_file_existing_single_dir_via_env(fs_fast):
    exists_dir = "/var/some-dir-to-look-for-configs"

    fs_fast.create_dir(exists_dir)

    assert os.path.isdir(exists_dir)

    # singular
    mock_environ = {"SG_CONFIG_DIR": exists_dir}

    with patch_os_environ(mock_environ):
        dirs = get_explicit_config_file_dirs()

        assert len(dirs) == 1
        assert exists_dir in dirs
Beispiel #7
0
def test_get_explicit_config_file_non_existing_dirs_via_arg(fs_fast):
    non_exist_dir_1 = "/var/some-non-existing-dir-to-look-for-configs"
    non_exist_dir_2 = "/var/another-non-existing-dir-to-look-for-configs"

    assert not os.path.isdir(non_exist_dir_1)
    assert not os.path.isdir(non_exist_dir_2)

    mock_sysargv = [
        "sg",
        "--config-dirs",
        "%s:%s:%s" % (non_exist_dir_1, non_exist_dir_1, non_exist_dir_2),
    ]

    with patch.object(sys, "argv", mock_sysargv):
        dirs = get_explicit_config_file_dirs()

        assert len(dirs) == 0
Beispiel #8
0
def test_get_explicit_config_file_non_existing_dirs_via_env(fs_fast):
    non_exist_dir_1 = "/var/some-non-existing-dir-to-look-for-configs"
    non_exist_dir_2 = "/var/another-non-existing-dir-to-look-for-configs"

    assert not os.path.isdir(non_exist_dir_1)
    assert not os.path.isdir(non_exist_dir_2)

    mock_environ = {
        "SG_CONFIG_DIR":
        non_exist_dir_1,
        "SG_CONFIG_DIRS":
        "%s:%s:%s" % (non_exist_dir_1, non_exist_dir_1, non_exist_dir_2),
    }

    with patch_os_environ(mock_environ):
        dirs = get_explicit_config_file_dirs()

        assert len(dirs) == 0
Beispiel #9
0
def test_get_explicit_config_file_existing_dirs_via_arg(fs_fast):
    exists_dir_1 = "/var/some-dir-to-look-for-configs"
    exists_dir_2 = "/var/another-dir-to-look-for-configs"

    fs_fast.create_dir(exists_dir_1)
    fs_fast.create_dir(exists_dir_2)

    assert os.path.isdir(exists_dir_1)
    assert os.path.isdir(exists_dir_2)

    # Try with duplicates which should be filtered
    mock_sysargv = [
        "sg", "--config-dirs",
        "%s:%s:%s" % (exists_dir_1, exists_dir_1, exists_dir_2)
    ]

    with patch.object(sys, "argv", mock_sysargv):
        dirs = get_explicit_config_file_dirs()

        assert len(dirs) == 2
        assert exists_dir_1 in dirs
        assert exists_dir_2 in dirs
Beispiel #10
0
def test_get_explicit_config_file_existing_dirs_via_env(fs_fast):
    exists_dir_1 = "/var/some-dir-to-look-for-configs"
    exists_dir_2 = "/var/another-dir-to-look-for-configs"

    fs_fast.create_dir(exists_dir_1)
    fs_fast.create_dir(exists_dir_2)

    assert os.path.isdir(exists_dir_1)
    assert os.path.isdir(exists_dir_2)

    # Try with duplicates which should be filtered
    mock_environ = {
        "SG_CONFIG_DIRS":
        "%s:%s:%s" % (exists_dir_1, exists_dir_1, exists_dir_2)
    }

    with patch_os_environ(mock_environ):
        dirs = get_explicit_config_file_dirs()

        assert len(dirs) == 2
        assert exists_dir_1 in dirs
        assert exists_dir_2 in dirs