test: Fix test for default location of config.rsc

The tests for the default path of the config.rsc are now performed
optionally. If write permission exists for the standard paths, the
tests are performed with the config.rsc.
This commit is contained in:
2024-11-12 10:18:52 +01:00
parent 41720ee042
commit 19bbdb03e8

View File

@@ -4,9 +4,10 @@ __author__ = "Sven Sager"
__copyright__ = "Copyright (C) 2024 Sven Sager" __copyright__ = "Copyright (C) 2024 Sven Sager"
__license__ = "GPLv2" __license__ = "GPLv2"
from os import remove from os import remove, makedirs
from os.path import join, dirname from os.path import join, dirname
from shutil import copyfile from shutil import copyfile
from warnings import warn
import revpimodio2 import revpimodio2
from .. import TestRevPiModIO from .. import TestRevPiModIO
@@ -30,11 +31,17 @@ class TestInitModio(TestRevPiModIO):
"configrsc": join(self.data_dir, "config.rsc"), "configrsc": join(self.data_dir, "config.rsc"),
} }
# Datei an richtigen Ort kopieren und löschen # Check default path of config.rsc
copyfile(defaultkwargs["configrsc"], "/opt/KUNBUS/config.rsc") for config_file in ("/opt/KUNBUS/config.rsc", "/etc/revpi/config.rsc"):
rpi = revpimodio2.RevPiModIO(procimg=self.fh_procimg.name) config_dir = dirname(config_file)
del rpi try:
remove("/opt/KUNBUS/config.rsc") makedirs(config_dir, exist_ok=True)
copyfile(defaultkwargs["configrsc"], config_file)
except PermissionError:
warn(f"Skip test for default location of '{config_file}' - permission denied")
else:
revpimodio2.RevPiModIO(procimg=self.fh_procimg.name)
remove(config_file)
# RevPiModIO # RevPiModIO
rpi = self.modio() rpi = self.modio()