test_macos_checks.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. from __future__ import absolute_import
  2. import mock
  3. import platform
  4. import sys
  5. import pytest
  6. from qtpy import PYQT5, PYSIDE2
  7. @pytest.mark.skipif(not PYQT5, reason="Targeted to PyQt5")
  8. @mock.patch.object(platform, 'mac_ver')
  9. def test_qt59_exception(mac_ver, monkeypatch):
  10. # Remove qtpy to reimport it again
  11. try:
  12. del sys.modules["qtpy"]
  13. except KeyError:
  14. pass
  15. # Patch stdlib to emulate a macOS system
  16. monkeypatch.setattr("sys.platform", 'darwin')
  17. mac_ver.return_value = ('10.9.2',)
  18. # Patch Qt version
  19. monkeypatch.setattr("PyQt5.QtCore.QT_VERSION_STR", '5.9.1')
  20. # This should raise an Exception
  21. with pytest.raises(Exception) as e:
  22. import qtpy
  23. assert '10.10' in str(e.value)
  24. assert '5.9' in str(e.value)
  25. @pytest.mark.skipif(not PYQT5, reason="Targeted to PyQt5")
  26. @mock.patch.object(platform, 'mac_ver')
  27. def test_qt59_no_exception(mac_ver, monkeypatch):
  28. # Remove qtpy to reimport it again
  29. try:
  30. del sys.modules["qtpy"]
  31. except KeyError:
  32. pass
  33. # Patch stdlib to emulate a macOS system
  34. monkeypatch.setattr("sys.platform", 'darwin')
  35. mac_ver.return_value = ('10.10.1',)
  36. # Patch Qt version
  37. monkeypatch.setattr("PyQt5.QtCore.QT_VERSION_STR", '5.9.5')
  38. # This should not raise an Exception
  39. try:
  40. import qtpy
  41. except Exception:
  42. pytest.fail("Error!")
  43. @pytest.mark.skipif(not (PYQT5 or PYSIDE2),
  44. reason="Targeted to PyQt5 or PySide2")
  45. @mock.patch.object(platform, 'mac_ver')
  46. def test_qt511_exception(mac_ver, monkeypatch):
  47. # Remove qtpy to reimport it again
  48. try:
  49. del sys.modules["qtpy"]
  50. except KeyError:
  51. pass
  52. # Patch stdlib to emulate a macOS system
  53. monkeypatch.setattr("sys.platform", 'darwin')
  54. mac_ver.return_value = ('10.10.3',)
  55. # Patch Qt version
  56. if PYQT5:
  57. monkeypatch.setattr("PyQt5.QtCore.QT_VERSION_STR", '5.11.1')
  58. else:
  59. monkeypatch.setattr("PySide2.QtCore.__version__", '5.11.1')
  60. # This should raise an Exception
  61. with pytest.raises(Exception) as e:
  62. import qtpy
  63. assert '10.11' in str(e.value)
  64. assert '5.11' in str(e.value)
  65. @pytest.mark.skipif(not (PYQT5 or PYSIDE2),
  66. reason="Targeted to PyQt5 or PySide2")
  67. @mock.patch.object(platform, 'mac_ver')
  68. def test_qt511_no_exception(mac_ver, monkeypatch):
  69. # Remove qtpy to reimport it again
  70. try:
  71. del sys.modules["qtpy"]
  72. except KeyError:
  73. pass
  74. # Patch stdlib to emulate a macOS system
  75. monkeypatch.setattr("sys.platform", 'darwin')
  76. mac_ver.return_value = ('10.13.2',)
  77. # Patch Qt version
  78. if PYQT5:
  79. monkeypatch.setattr("PyQt5.QtCore.QT_VERSION_STR", '5.11.1')
  80. else:
  81. monkeypatch.setattr("PySide2.QtCore.__version__", '5.11.1')
  82. # This should not raise an Exception
  83. try:
  84. import qtpy
  85. except Exception:
  86. pytest.fail("Error!")