Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mottosso authored May 5, 2024
1 parent 60000f6 commit d75bee7
Showing 1 changed file with 47 additions and 29 deletions.
76 changes: 47 additions & 29 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,32 @@ def tearDownModule():
teardown()


preferred_binding = None

# Use whichever binding is currently available
try:
import PySide as __
preferred_binding = "PySide"
except ImportError:
try:
import PySide2 as __
preferred_binding = "PySide2"
except ImportError:
try:
import PySide6 as __
preferred_binding = "PySide6"
except ImportError:
try:
import PyQt4 as __
preferred_binding = "PyQt4"
except ImportError:
try:
import PyQt5 as __
preferred_binding = "PyQt5"
except ImportError:
pass


def binding(binding):
"""Isolate test to a particular binding
Expand All @@ -380,7 +406,11 @@ def binding(binding):
"""

return os.getenv("QT_PREFERRED_BINDING") == binding
if "QT_PREFERRED_BINDING" in os.environ:
return os.getenv("QT_PREFERRED_BINDING") == binding

return binding == preferred_binding



@contextlib.contextmanager
Expand All @@ -404,20 +434,6 @@ def messageOutputHandler(msgType, logContext, msg):
QtCompat.qInstallMessageHandler(None)


def test_environment():
"""Tests require all bindings to be installed (except PySide on py3.5+)"""

if sys.version_info < (3, 5):
# PySide is not available for Python > 3.4
imp.find_module("PySide")
elif os.environ.get("QT_PREFERRED_BINDING") == "PySide6":
imp.find_module("PySide6")
else:
imp.find_module("PySide2")
imp.find_module("PyQt4")
imp.find_module("PyQt5")


def test_load_ui_returntype():
"""load_ui returns an instance of QObject"""

Expand Down Expand Up @@ -829,7 +845,7 @@ def test_vendoring():
env = os.environ.copy()
env["QT_PREFERRED_BINDING_JSON"] = json.dumps(
{
"Qt": ["PySide6", "PyQt5", "PyQt4"],
"Qt": ["PySide6", "PySide2", "PyQt5", "PyQt4"],
"default": ["None"]
}
)
Expand All @@ -842,7 +858,7 @@ def test_vendoring():
) == 0

print("Testing QT_PREFERRED_BINDING_JSON and QT_PREFERRED_BINDING work..")
env["QT_PREFERRED_BINDING_JSON"] = '{"Qt":["PySide6","PyQt5","PyQt4"]}'
env["QT_PREFERRED_BINDING_JSON"] = '{"Qt":["PySide6", "PySide2","PyQt5","PyQt4"]}'
env["QT_PREFERRED_BINDING"] = "None"
assert subprocess.call(
[sys.executable, "-c", cmd],
Expand Down Expand Up @@ -999,8 +1015,10 @@ def test_binding_and_qt_version():
def test_binding_states():
"""Tests to see if the Qt binding enum states are set properly"""
import Qt
print(Qt)
print("ADTAD A---- - - -- - - _SDFSD")
assert Qt.IsPySide == binding("PySide")
assert Qt.IsPySide2 == binding("PySide2")
assert Qt.IsPySide2 == binding("PySide2"), "%s != %s" % (Qt.IsPySide2, binding("PySide2"))
assert Qt.IsPySide6 == binding("PySide6")
assert Qt.IsPyQt5 == binding("PyQt5")
assert Qt.IsPyQt4 == binding("PyQt4")
Expand Down Expand Up @@ -1374,26 +1392,26 @@ def test_preferred_pyside():
"PySide should have been picked, "
"instead got %s" % Qt.__binding__)


if binding("PySide2"):
def test_preferred_pyside2():
"""QT_PREFERRED_BINDING = PySide2 properly forces the binding"""
import Qt
assert Qt.__binding__ == "PySide2", (
"PySide2 should have been picked, "
"instead got %s" % Qt.__binding__)

def test_coexistence():
"""Qt.py may be use alongside the actual binding"""

from Qt import QtCore
import PySide2.QtGui
import PySide.QtGui

# Qt remaps QStringListModel
assert QtCore.QStringListModel

# But does not delete the original
assert PySide2.QtGui.QStringListModel
assert PySide.QtGui.QStringListModel


if binding("PySide2"):
def test_preferred_pyside2():
"""QT_PREFERRED_BINDING = PySide2 properly forces the binding"""
import Qt
assert Qt.__binding__ == "PySide2", (
"PySide2 should have been picked, "
"instead got %s" % Qt.__binding__)


if binding("PySide6"):
Expand Down

0 comments on commit d75bee7

Please sign in to comment.