Skip to content

Commit

Permalink
extract path to 'c.yml' as constant
Browse files Browse the repository at this point in the history
  • Loading branch information
emcek committed Oct 17, 2023
1 parent e6b3860 commit 9218ab4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
18 changes: 14 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ def resources():
return Path(__file__).resolve().with_name('resources')


@fixture()
def test_config_yaml(resources):
"""
Path to YAML tests config file.
:return: path to yaml config file
"""
return resources / 'c.yml'


# <=><=><=><=><=> dcsbios <=><=><=><=><=>
@fixture
def protocol_parser():
Expand Down Expand Up @@ -200,21 +210,21 @@ def default_config():


@fixture()
def switch_dcs_bios_path_in_config(resources):
def switch_dcs_bios_path_in_config(resources, test_config_yaml):
"""
Switch path to config yaml file during testing.
:param resources: path to tests/resources directory
"""
from dcspy import utils

org = utils.load_yaml(resources / 'c.yml')
org = utils.load_yaml(test_config_yaml)
dcs_bios = org['dcsbios']
org['dcsbios'] = str(resources / 'dcs_bios')
utils.save_yaml(data=org, full_path=resources / 'c.yml')
utils.save_yaml(data=org, full_path=test_config_yaml)
yield
org['dcsbios'] = dcs_bios
utils.save_yaml(data=org, full_path=resources / 'c.yml')
utils.save_yaml(data=org, full_path=test_config_yaml)


# <=><=><=><=><=> DCS World autoupdate_cfg <=><=><=><=><=>
Expand Down
4 changes: 2 additions & 2 deletions tests/test_qtgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@mark.qt6
@mark.skipif(condition=platform != 'win32', reason='Run only on Windows')
def test_qt(qtbot, resources, switch_dcs_bios_path_in_config):
def test_qt(qtbot, test_config_yaml, switch_dcs_bios_path_in_config):
from time import sleep

from PySide6 import QtCore
Expand All @@ -18,7 +18,7 @@ def test_qt(qtbot, resources, switch_dcs_bios_path_in_config):
QQuickWindow.setGraphicsApi(QSGRendererInterface.OpenGLRhi)
QtCore.QCoreApplication.setAttribute(Qt.AA_ShareOpenGLContexts)

with patch('dcspy.qt_gui.default_yaml', resources / 'c.yml'):
with patch('dcspy.qt_gui.default_yaml', test_config_yaml):
dcspy_gui = qt_gui.DcsPyQtGui()
dcspy_gui.show()
qtbot.addWidget(dcspy_gui)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_proc_is_running():

def test_dummy_save_load_set_defaults(tmpdir):
from os import environ
test_tmp_yaml = Path(tmpdir) / 'c.yml'
test_tmp_yaml = Path(tmpdir) / 'test_cfg.yaml'

utils.save_yaml(data={'font_mono_xs': 9}, full_path=test_tmp_yaml)
d_cfg = utils.load_yaml(full_path=test_tmp_yaml)
Expand Down

0 comments on commit 9218ab4

Please sign in to comment.