def test_configure_qtpy_sets_requested_api( pytester: _pytest.pytester.Pytester, api_string: str, api: ssst._utilities.QtApis, ) -> None: content = f""" import os import sys import ssst._utilities os.environ.pop(ssst._utilities.qt_api_variable_name) def test(): assert 'qtpy' not in sys.modules ssst._utilities.configure_qtpy( api=ssst._utilities.QtApis({api_string!r}), ) assert "qtpy" not in sys.modules import qtpy assert qtpy.API == {api.value!r} """ pytester.makepyfile(content) run_result = pytester.runpytest_subprocess() run_result.assert_outcomes(passed=1)
def test_configure_qtpy_raises(pytester: _pytest.pytester.Pytester) -> None: content = f""" import os import sys import pytest import ssst._utilities import ssst.exceptions os.environ.pop(ssst._utilities.qt_api_variable_name) def test(): import qtpy with pytest.raises(ssst.exceptions.QtpyError, match="qtpy imported prior to"): ssst._utilities.configure_qtpy( api=ssst._utilities.QtApis.PyQt5, ) """ pytester.makepyfile(content) run_result = pytester.runpytest_subprocess() run_result.assert_outcomes(passed=1)
def test_configure_qtpy_handles_env_var( pytester: _pytest.pytester.Pytester, api: ssst._utilities.QtApis, ) -> None: content = f""" import os import sys import ssst._utilities os.environ[ssst._utilities.qt_api_variable_name] = {api.value!r} def test(): assert 'qtpy' not in sys.modules ssst._utilities.configure_qtpy(api=42) assert "qtpy" not in sys.modules import qtpy assert qtpy.API == {api.value!r} """ pytester.makepyfile(content) run_result = pytester.runpytest_subprocess() run_result.assert_outcomes(passed=1)
def test_configure_qt_wrapper_handles_env_var( pytester: _pytest.pytester.Pytester, api: ssst._utilities.QtApis, ) -> None: content = f""" import os import sys import qts import ssst._utilities os.environ[ssst._utilities.qt_api_variable_name] = {api.value!r} def test(): assert qts.wrapper is None ssst._utilities.configure_qt_wrapper(api=42) assert qts.wrapper is not None assert qts.wrapper.name == {api.name!r} """ pytester.makepyfile(content) run_result = pytester.runpytest_subprocess() run_result.assert_outcomes(passed=1)
def test_configure_qt_wrapper_sets_requested_api( pytester: _pytest.pytester.Pytester, api: ssst._utilities.QtApis, ) -> None: content = f""" import os import sys import qts import ssst._utilities os.environ.pop(ssst._utilities.qt_api_variable_name) def test(): assert qts.wrapper is None ssst._utilities.configure_qt_wrapper( api=ssst._utilities.QtApis({api.value!r}), ) assert qts.wrapper.name == {api.name!r} """ pytester.makepyfile(content) run_result = pytester.runpytest_subprocess() run_result.assert_outcomes(passed=1)
def test_configure_qt_wrapper_raises( pytester: _pytest.pytester.Pytester) -> None: content = f""" import os import sys import pytest import ssst._utilities import ssst.exceptions if ssst._utilities.qt_api_variable_name in os.environ: os.environ.pop(ssst._utilities.qt_api_variable_name) def test(): import qts qts.autoset_wrapper() with pytest.raises(ssst.exceptions.QtWrapperError, match="qts already configured"): ssst._utilities.configure_qt_wrapper( api=ssst._utilities.QtApis.PyQt5, ) """ pytester.makepyfile(content) run_result = pytester.runpytest_subprocess() run_result.assert_outcomes(passed=1)
def test_compile_paths_raises_if_qtpy_not_imported( pytester: _pytest.pytester.Pytester, ) -> None: content = f""" import pytest import ssst._utilities def test(): with pytest.raises( ssst.QtpyError, match="QtPy is expected to be imported before calling this function.", ): ssst._utilities.compile_paths(ui_paths=[]) """ pytester.makepyfile(content) run_result = pytester.runpytest_subprocess() run_result.assert_outcomes(passed=1)
def test_configure_qtpy_does_not_import( pytester: _pytest.pytester.Pytester) -> None: content = f""" import os import sys import pytest import ssst._utilities os.environ.pop(ssst._utilities.qt_api_variable_name) def test(): ssst._utilities.configure_qtpy(api=ssst._utilities.QtApis.PyQt5) assert "qtpy" not in sys.modules """ pytester.makepyfile(content) run_result = pytester.runpytest_subprocess() run_result.assert_outcomes(passed=1)
def test_spawn_uses_tmphome(pytester: Pytester) -> None: tmphome = str(pytester.path) assert os.environ.get("HOME") == tmphome pytester._monkeypatch.setenv("CUSTOMENV", "42") p1 = pytester.makepyfile(""" import os def test(): assert os.environ["HOME"] == {tmphome!r} assert os.environ["CUSTOMENV"] == "42" """.format(tmphome=tmphome)) child = pytester.spawn_pytest(str(p1)) out = child.read() assert child.wait() == 0, out.decode("utf8")