mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-26 09:13:35 +05:00
Squashed 'kiauh/core/submodules/simple_config_parser/' content from commit 90081a6
git-subtree-dir: kiauh/core/submodules/simple_config_parser git-subtree-split: 90081a6539ec38adf6a1a5bb707a0e9934567c7f
This commit is contained in:
66
tests/public_api/test_sections_api.py
Normal file
66
tests/public_api/test_sections_api.py
Normal file
@@ -0,0 +1,66 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
|
||||
import pytest
|
||||
|
||||
from src.simple_config_parser.simple_config_parser import (
|
||||
DuplicateSectionError,
|
||||
)
|
||||
|
||||
|
||||
def test_get_sections(parser):
|
||||
expected_keys = {
|
||||
"section_1",
|
||||
"section_2",
|
||||
"section_3",
|
||||
"section_4",
|
||||
"section number 5",
|
||||
}
|
||||
assert expected_keys.issubset(
|
||||
parser.get_sections()
|
||||
), f"Expected keys: {expected_keys}, got: {parser.get_sections()}"
|
||||
|
||||
|
||||
def test_has_section(parser):
|
||||
assert parser.has_section("section_1") is True
|
||||
assert parser.has_section("not_available") is False
|
||||
|
||||
|
||||
def test_add_section(parser):
|
||||
pre_add_count = len(parser.get_sections())
|
||||
parser.add_section("new_section")
|
||||
parser.add_section("new_section2")
|
||||
assert parser.has_section("new_section") is True
|
||||
assert parser.has_section("new_section2") is True
|
||||
assert len(parser.get_sections()) == pre_add_count + 2
|
||||
|
||||
new_section = parser.config["new_section"]
|
||||
assert isinstance(new_section, dict)
|
||||
assert new_section["_raw"] == "[new_section]\n"
|
||||
|
||||
# this should be the collector, added by the parser before
|
||||
# then second section was added
|
||||
assert list(new_section.keys())[-1].startswith("#_")
|
||||
assert "\n" in new_section[list(new_section.keys())[-1]]
|
||||
|
||||
new_section2 = parser.config["new_section2"]
|
||||
assert isinstance(new_section2, dict)
|
||||
assert new_section2["_raw"] == "[new_section2]\n"
|
||||
|
||||
|
||||
def test_add_section_duplicate(parser):
|
||||
with pytest.raises(DuplicateSectionError):
|
||||
parser.add_section("section_1")
|
||||
|
||||
|
||||
def test_remove_section(parser):
|
||||
pre_remove_count = len(parser.get_sections())
|
||||
parser.remove_section("section_1")
|
||||
assert parser.has_section("section_1") is False
|
||||
assert len(parser.get_sections()) == pre_remove_count - 1
|
||||
assert "section_1" not in parser.config
|
||||
Reference in New Issue
Block a user