Files
kiauh/tests/public_api/test_write_file.py
dw-0 2f924a2550 Squashed 'kiauh/core/submodules/simple_config_parser/' content from commit 90081a6
git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: 90081a6539ec38adf6a1a5bb707a0e9934567c7f
2024-09-24 19:22:13 +02:00

42 lines
1.5 KiB
Python

# ======================================================================= #
# 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 #
# ======================================================================= #
from pathlib import Path
import pytest
from src.simple_config_parser.simple_config_parser import (
SimpleConfigParser,
)
BASE_DIR = Path(__file__).parent.parent.joinpath("assets")
TEST_DATA_PATH = BASE_DIR.joinpath("test_config_1.cfg")
# TEST_DATA_PATH_2 = BASE_DIR.joinpath("test_config_1_write.cfg")
def test_write_file_exception():
parser = SimpleConfigParser()
with pytest.raises(ValueError):
parser.write_file(None) # noqa
def test_write_to_file(tmp_path):
tmp_file = Path(tmp_path).joinpath("tmp_config.cfg")
parser1 = SimpleConfigParser()
parser1.read_file(TEST_DATA_PATH)
# parser1.write_file(TEST_DATA_PATH_2)
parser1.write_file(tmp_file)
parser2 = SimpleConfigParser()
parser2.read_file(tmp_file)
assert tmp_file.exists()
assert parser2.config is not None
with open(TEST_DATA_PATH, "r") as original, open(tmp_file, "r") as written:
assert original.read() == written.read()