Exemplo n.º 1
0
def test__config__load_file_f():
    """Test loading config from a file path."""
    c = ConfigLoader()
    cfg = c.load_config_at_path(
        os.path.join("test", "fixtures", "config", "inheritance_a",
                     "testing.sql"))
    assert cfg == config_a
Exemplo n.º 2
0
def test__config__load_user_appdir_config(mock_listdir, mock_path_exists,
                                          mock_xdg_home):
    """Test loading config from user appdir."""
    xdg_config_path = os.environ.get("XDG_CONFIG_HOME") + "/sqlfluff"

    def path_exists(x):
        if x == os.path.expanduser("~/.config/sqlfluff"):
            return False
        if x == xdg_config_path:
            return False
        else:
            return True

    mock_path_exists.side_effect = path_exists

    c = ConfigLoader()

    with patch.object(appdirs, attribute="system", new="darwin"):
        resolved_path = c._get_user_config_dir_path()
        c.load_user_appdir_config()
    assert resolved_path == os.path.expanduser(
        "~/Library/Application Support/sqlfluff")

    mock_path_exists.assert_has_calls([
        call(xdg_config_path),
        call(os.path.expanduser("~/Library/Application Support/sqlfluff")),
    ])
Exemplo n.º 3
0
def test__config__load_toml():
    """Test loading config from a pyproject.toml file."""
    c = ConfigLoader()
    cfg = c.load_default_config_file(
        os.path.join("test", "fixtures", "config", "toml"),
        "pyproject.toml",
    )
    assert cfg == {
        "core": {
            "testing_int": 5,
            "testing_bar": 7.698,
            "testing_bool": False,
            "testing_arr": ["a", "b", "c"],
            "testing_inline_table": {
                "x": 1
            },
        },
        "bar": {
            "foo": "foobar"
        },
        "fnarr": {
            "fnarr": {
                "foo": "foobar"
            }
        },
    }
Exemplo n.º 4
0
def test__config__iter_config_paths_right_order():
    """Test that config paths are fetched ordered by priority."""
    c = ConfigLoader()
    cfg_paths = c.iter_config_locations_up_to_path(
        os.path.join("test", "fixtures", "config", "inheritance_a", "nested",
                     "blah.sql"),
        working_path="test/fixtures",
    )
    assert list(cfg_paths) == [
        str(Path(p).resolve()) for p in [
            "test/fixtures",
            "test/fixtures/config",
            "test/fixtures/config/inheritance_a",
            "test/fixtures/config/inheritance_a/nested",
        ]
    ]
Exemplo n.º 5
0
def test__config__load_nested():
    """Test nested overwrite and order of precedence of config files in the same directory."""
    c = ConfigLoader()
    cfg = c.load_config_up_to_path(
        os.path.join("test", "fixtures", "config", "inheritance_a", "nested",
                     "blah.sql"))
    assert cfg == {
        "core": {
            "testing_val": "foobar",
            "testing_int": 1,
            "testing_bar": 7.698
        },
        "bar": {
            "foo": "foobar"
        },
        "fnarr": {
            "fnarr": {
                "foo": "foobar"
            }
        },
    }