| 1 |
# SPDX-FileCopyrightText: Peter Pentchev <[email protected]> |
| 2 |
# SPDX-License-Identifier: BSD-2-Clause |
| 3 |
|
| 4 |
"""Test that the backends return ConfigParser objects.""" |
| 5 |
|
| 6 |
import confget |
| 7 |
|
| 8 |
from .data import test_defs as tdefs |
| 9 |
|
| 10 |
|
| 11 |
def test_ini() -> None: |
| 12 |
"""Test the ConfigParser object returned by the INI file backend.""" |
| 13 |
cfg = confget.Config([], filename=tdefs.get_test_path("t3.ini")) |
| 14 |
ini = confget.BACKENDS[confget.BackendType.INI](cfg) |
| 15 |
|
| 16 |
data = ini.read_file() |
| 17 |
assert set(data.keys()) == {"", "a"} |
| 18 |
assert data["a"]["aonly"] == "a" |
| 19 |
assert data["a"]["both"] == "a" |
| 20 |
assert data[""]["defonly"] == "default" |
| 21 |
assert data[""]["both"] == "default" |
| 22 |
assert "aonly" not in data[""] |
| 23 |
assert "defonly" not in data["a"] |
| 24 |
|
| 25 |
par = ini.get_configparser() |
| 26 |
assert set(par.sections()) == {"", "a"} |
| 27 |
assert par.get("a", "aonly") == "a" |
| 28 |
assert par.get("a", "both") == "a" |
| 29 |
assert par.get("", "defonly") == "default" |
| 30 |
assert par.get("", "both") == "default" |
| 31 |
assert "aonly" not in par[""] |
| 32 |
# And this is where ConfigParser gets weird... |
| 33 |
assert par.get("a", "defonly") == "default" |