Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ def _pyqt5():
PyQt5.__qt_version__ = PyQt5.QtCore.QT_VERSION_STR
PyQt5.load_ui = pyqt5_load_ui

# provide mocked UnicodeUTF8 For backward compatibility
PyQt5.QtWidgets.QApplication.UnicodeUTF8 = None

old_translate_fn = PyQt5.QtWidgets.QApplication.translate

def translate(context, key, disambiguation=None, encoding=None, n=0):
return old_translate_fn(context, key, disambiguation, n)

PyQt5.QtWidgets.QApplication.translate = staticmethod(translate)

return PyQt5


Expand Down Expand Up @@ -101,6 +111,16 @@ def _pyside2():
PySide2.__qt_version__ = PySide2.QtCore.qVersion()
PySide2.load_ui = pyside2_load_ui

# provide mocked UnicodeUTF8 For backward compatibility
PySide2.QtWidgets.QApplication.UnicodeUTF8 = None

old_translate_fn = PySide2.QtWidgets.QApplication.translate

def translate(context, key, disambiguation=None, encoding=None, n=0):
return old_translate_fn(context, key, disambiguation, n)

PySide2.QtWidgets.QApplication.translate = staticmethod(translate)

return PySide2


Expand Down
78 changes: 78 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,81 @@ def test_sip_api_already_set():
import sip
sip.setapi("QString", 1)
assert_raises(ImportError, __import__, "Qt")


def test_translate_and_UnicodeUTF8_in_pyside():
with pyside():
from Qt import QtWidgets

# this does exist in PySide
assert QtWidgets.QApplication.UnicodeUTF8 is not None

# use patched method with old arguments
QtWidgets.QApplication.translate(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to include a return value in the test, to make sure it produces the expected value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, just wanted to check the overall testing first (which is failing).
I'll add a check of the return value once I have something basic working ;)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok. No problem.

As tests now require all bindings, I'd imagine it can get tricky to replicate this environment locally. The developer guide has instructions on how to run these via Docker, if you have access to this. It'll let you run tests locally without installing any bindings, exactly the way Travis is running it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool I'll have a look, if you don't mind though , for now, I'll hammer a bit your remote testing ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checking now on local docker installation so I don't mess to much up with travis

'Href_Gui',
'Text',
0,
QtWidgets.QApplication.UnicodeUTF8
)


def test_translate_and_UnicodeUTF8_in_pyqt4():
with pyqt4():
from Qt import QtWidgets

# this does exist in PyQt4
assert QtWidgets.QApplication.UnicodeUTF8 is not None

# use patched method with old arguments
QtWidgets.QApplication.translate(
'Href_Gui',
'Text',
0,
QtWidgets.QApplication.UnicodeUTF8
)


def test_translate_and_UnicodeUTF8_in_pyside2():
with pyside2():
from Qt import QtWidgets

# this does not exist in PySide2 by default
assert QtWidgets.QApplication.UnicodeUTF8 is None

# use patched method with old arguments
QtWidgets.QApplication.translate(
'Href_Gui',
'Text',
0,
QtWidgets.QApplication.UnicodeUTF8
)

# use patched method with new arguments
QtWidgets.QApplication.translate(
'SomeText',
'Form',
0,
)


def test_translate_and_UnicodeUTF8_in_PyQt5():
with pyqt5():
from Qt import QtWidgets

# this does not exist in PyQt5 by default
assert QtWidgets.QApplication.UnicodeUTF8 is None

# use patched method with old arguments
QtWidgets.QApplication.translate(
'SomeText',
'Form',
None,
QtWidgets.QApplication.UnicodeUTF8
)

# use patched method with new arguments
QtWidgets.QApplication.translate(
'SomeText',
'Form',
None,
)