summaryrefslogtreecommitdiffstats
path: root/lang/python/python-iniconfig/test.sh
blob: 609c15a5ad9beed3dbf19e829e4c85cd1f0fb495 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/sh

[ "$1" = "python3-iniconfig" ] || exit 0

python3 - << EOF
import sys
import iniconfig
import tempfile, os

# Write a simple INI file and parse it
ini = "[section1]\nkey1 = value1\nkey2 = 42\n\n[section2]\nflag = true\n"
with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f:
    f.write(ini)
    tmp = f.name

try:
    cfg = iniconfig.IniConfig(tmp)
    assert cfg["section1"]["key1"] == "value1", "key1 mismatch"
    assert cfg["section1"]["key2"] == "42", "key2 mismatch"
    assert cfg["section2"]["flag"] == "true", "flag mismatch"
    assert "section1" in cfg, "section1 not found"
    assert "missing" not in cfg, "missing section should not exist"
finally:
    os.unlink(tmp)

sys.exit(0)
EOF