Skip to content

Commit

Permalink
fix: get setting from QgsSettings not config.yml in testing
Browse files Browse the repository at this point in the history
  • Loading branch information
merydian committed Aug 30, 2024
1 parent 40defc3 commit 60c2796
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import os
import yaml

from qgis.core import QgsSettings

from ORStools.ORStoolsPlugin import ORStools
from ORStools.utils.configmanager import read_config
from tests.utils.utilities import get_qgis_app

with open("ORStools/config.yml", "r+") as file:
data = yaml.safe_load(file)
QGISAPP, CANVAS, IFACE, PARENT = get_qgis_app()

ORStools(IFACE).add_default_provider_to_settings()
s = QgsSettings()
data = s.value("ORStools/config")

def pytest_sessionstart(session):
"""
Expand All @@ -14,8 +19,7 @@ def pytest_sessionstart(session):
"""
if data["providers"][0]["key"] == "":
data["providers"][0]["key"] = os.environ.get("ORS_API_KEY")
with open("ORStools/config.yml", "w") as file:
yaml.dump(data, file)
s.setValue("ORStools/config", data)
else:
raise ValueError("API key is not empty.")

Expand All @@ -25,10 +29,8 @@ def pytest_sessionfinish(session, exitstatus):
Called after whole test run finished, right before
returning the exit status to the system.
"""
with open("ORStools/config.yml", "w") as file:
if not data["providers"][0]["key"] == "":
data['providers'][0]['key'] = '' # fmt: skip
yaml.dump(data, file)

if not data["providers"][0]["key"] == "":
data['providers'][0]['key'] = '' # fmt: skip
s.setValue("ORStools/config", data)
config = read_config()
assert config["providers"][0]["key"] == '' # fmt: skip
2 changes: 1 addition & 1 deletion tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ def test_ORStoolsDialog(self):
dlg.line_tool.canvasDoubleClickEvent(map_dclick)

self.assertTrue(dlg.isVisible())
self.assertAlmostEqual(
self.assertEqual(
dlg.routing_fromline_list.item(0).text(), "Point 0: -0.187575, 56.516620"
)

0 comments on commit 60c2796

Please sign in to comment.