Skip to content

Commit 24a7e59

Browse files
committed
Rename QtShim to QtCompat
1 parent 032cfdb commit 24a7e59

File tree

4 files changed

+58
-34
lines changed

4 files changed

+58
-34
lines changed

CAVEATS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,11 @@ Use compatibility wrapper.
258258

259259
```python
260260
# PySide2
261-
>>> from Qt import QtWidgets, QtShim
261+
>>> from Qt import QtWidgets, QtCompat
262262
>>> app = QtWidgets.QApplication(sys.argv)
263263
>>> view = QtWidgets.QTreeWidget()
264264
>>> header = view.header()
265-
>>> QtShim.setSectionResizeMode(header, QtWidgets.QHeaderView.Fixed)
265+
>>> QtCompat.setSectionResizeMode(header, QtWidgets.QHeaderView.Fixed)
266266
```
267267

268268
Or a conditional.

Qt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def _remap(object, name, value, safe=True):
109109

110110

111111
def _add(object, name, value):
112-
"""Append to self, accessible via Qt.QtShim"""
112+
"""Append to self, accessible via Qt.QtCompat"""
113113
self.__added__.append(name)
114114
setattr(self, name, value)
115115

@@ -174,7 +174,7 @@ def _pyqt4():
174174
# QtWebkit is optional in Qt , therefore might not be available
175175
pass
176176

177-
_add(PyQt4, "QtShim", self)
177+
_add(PyQt4, "QtCompat", self)
178178
_add(PyQt4, "__binding__", PyQt4.__name__)
179179
_add(PyQt4, "load_ui", lambda fname: uic.loadUi(fname))
180180
_add(PyQt4, "translate", lambda context, sourceText, disambiguation, n: (
@@ -349,7 +349,7 @@ def init():
349349
else:
350350
# Reference to this module
351351
binding.__shim__ = self
352-
binding.QtShim = self
352+
binding.QtCompat = self
353353

354354
sys.modules.update({
355355
__name__: binding,

README.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ app.exec_()
8181

8282
### Documentation
8383

84-
All members of `Qt` stem directly from those available via PySide2, along with these additional members, accessible via `Qt.QtShim`.
84+
All members of `Qt` stem directly from those available via PySide2, along with these additional members, accessible via `Qt.QtCompat`.
8585

8686
| Attribute | Returns | Description
8787
|:------------------------|:------------|:------------
@@ -103,8 +103,8 @@ All members of `Qt` stem directly from those available via PySide2, along with t
103103
**Example**
104104

105105
```python
106-
>>> from Qt import QtShim
107-
>>> QtShim.__binding__
106+
>>> from Qt import QtCompat
107+
>>> QtCompat.__binding__
108108
'PyQt5'
109109
```
110110

@@ -115,7 +115,7 @@ All members of `Qt` stem directly from those available via PySide2, along with t
115115
Some bindings offer features not available in others, you can use `__binding__` to capture those.
116116

117117
```python
118-
if "PySide" in QtShim.__binding__:
118+
if "PySide" in QtCompat.__binding__:
119119
do_pyside_stuff()
120120
```
121121

@@ -128,7 +128,7 @@ If your system has multiple choices where one or more is preferred, you can over
128128
```bash
129129
$ set QT_PREFERRED_BINDING=PyQt5 # Windows
130130
$ export QT_PREFERRED_BINDING=PyQt5 # Unix/OSX
131-
$ python -c "from Qt import QtShim;print(QtShim.__binding__)"
131+
$ python -c "from Qt import QtCompat;print(QtCompat.__binding__)"
132132
PyQt5
133133
```
134134

@@ -169,10 +169,10 @@ The `uic.loadUi` function of PyQt4 and PyQt5 as well as the `QtUiTools.QUiLoader
169169

170170
```python
171171
import sys
172-
from Qt import QtShim
172+
from Qt import QtCompat
173173

174174
app = QtWidgets.QApplication(sys.argv)
175-
ui = QtShim.load_ui(fname="my.ui")
175+
ui = QtCompat.load_ui(fname="my.ui")
176176
ui.show()
177177
app.exec_()
178178
```
@@ -340,6 +340,30 @@ Send us a pull-request with your project here.
340340

341341
### Developer Guide
342342

343+
Tests are performed on each aspect of the shim.
344+
345+
- [Functional](tests.py)
346+
- [Caveats](build_caveats.py)
347+
- [Examples](examples)
348+
- [Membership](build_membership.py)
349+
350+
Each of these are run under..
351+
352+
- Python 2.7
353+
- Python 3.4
354+
355+
..once for each binding or under a specific binding only.
356+
357+
Tests that are written at module level are run four times - once per binding - whereas tests written under a specific if-statement are run only for this particular binding.
358+
359+
```python
360+
if binding("PyQt4"):
361+
def test_something_related_to_pyqt4():
362+
pass
363+
```
364+
365+
**Running tests**
366+
343367
Due to the nature of multiple bindings and multiple interpreter support, setting up a development environment in which to properly test your contraptions can be challenging. So here is a guide for how to do just that using **Docker**.
344368

345369
With Docker setup, here's what you do.

tests.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,15 @@ def retranslateUi(self, uic):
219219
with open(fname, "w") as f:
220220
f.write(before)
221221

222-
from Qt import QtShim
222+
from Qt import QtCompat
223223

224224
os.chdir(self.tempdir)
225-
QtShim.cli(args=["--convert", "idempotency.py"])
225+
QtCompat.cli(args=["--convert", "idempotency.py"])
226226

227227
with open(fname) as f:
228228
assert f.read() == after
229229

230-
QtShim.cli(args=["--convert", "idempotency.py"])
230+
QtCompat.cli(args=["--convert", "idempotency.py"])
231231

232232
with open(fname) as f:
233233
assert f.read() == after
@@ -240,10 +240,10 @@ def test_convert_backup():
240240
with open(fname, "w") as f:
241241
f.write("")
242242

243-
from Qt import QtShim
243+
from Qt import QtCompat
244244

245245
os.chdir(self.tempdir)
246-
QtShim.cli(args=["--convert", "idempotency.py"])
246+
QtCompat.cli(args=["--convert", "idempotency.py"])
247247

248248
assert os.path.exists(
249249
os.path.join(self.tempdir, "%s_backup%s" % os.path.splitext(fname))
@@ -252,52 +252,52 @@ def test_convert_backup():
252252

253253
def test_meta_add():
254254
"""Qt._add() appends to __added__"""
255-
from Qt import QtShim
255+
from Qt import QtCompat
256256

257257
module = imp.new_module("QtMock")
258258

259-
QtShim._add(module, "MyAttr", None)
259+
QtCompat._add(module, "MyAttr", None)
260260

261-
assert "MyAttr" in QtShim.__added__, QtShim.__added__
262-
assert "MyAttr" not in QtShim.__remapped__
263-
assert "MyAttr" not in QtShim.__modified__
261+
assert "MyAttr" in QtCompat.__added__, QtCompat.__added__
262+
assert "MyAttr" not in QtCompat.__remapped__
263+
assert "MyAttr" not in QtCompat.__modified__
264264

265265

266266
def test_meta_remap():
267267
"""Qt._remap() appends to __modified__"""
268-
from Qt import QtShim
268+
from Qt import QtCompat
269269

270270
module = imp.new_module("QtMock")
271271

272-
QtShim._remap(module, "MyAttr", None)
272+
QtCompat._remap(module, "MyAttr", None)
273273

274-
assert "MyAttr" not in QtShim.__added__, QtShim.__added__
275-
assert "MyAttr" in QtShim.__remapped__
276-
assert "MyAttr" not in QtShim.__modified__
274+
assert "MyAttr" not in QtCompat.__added__, QtCompat.__added__
275+
assert "MyAttr" in QtCompat.__remapped__
276+
assert "MyAttr" not in QtCompat.__modified__
277277

278278

279279
def test_meta_remap_existing():
280280
"""Qt._remap() of existing member throws an exception"""
281-
from Qt import QtShim
281+
from Qt import QtCompat
282282

283283
module = imp.new_module("QtMock")
284284
module.MyAttr = None
285285

286-
assert_raises(AttributeError, QtShim._remap, module, "MyAttr", None)
286+
assert_raises(AttributeError, QtCompat._remap, module, "MyAttr", None)
287287

288288

289289
def test_meta_force_remap_existing():
290290
"""Unsafe Qt._remap() of existing member adds to modified"""
291-
from Qt import QtShim
291+
from Qt import QtCompat
292292

293293
module = imp.new_module("QtMock")
294294
module.MyAttr = 123
295295

296-
QtShim._remap(module, "MyAttr", None, safe=False)
296+
QtCompat._remap(module, "MyAttr", None, safe=False)
297297

298-
assert "MyAttr" in QtShim.__remapped__, QtShim.__remapped__
299-
assert "MyAttr" not in QtShim.__added__
300-
assert "MyAttr" in QtShim.__modified__
298+
assert "MyAttr" in QtCompat.__remapped__, QtCompat.__remapped__
299+
assert "MyAttr" not in QtCompat.__added__
300+
assert "MyAttr" in QtCompat.__modified__
301301
assert module.MyAttr is None, module.MyAttr
302302

303303

0 commit comments

Comments
 (0)