簡體   English   中英

在更新pytest-qt v3.1.0裝置qtmodeltester.check時明確測試了DisplayRole的string_types時,測試失敗

[英]Tests failed while updated pytest-qt v3.1.0 fixture qtmodeltester.check explicitly testing string_types for DisplayRole

pytest-qt v3.1.0顯式測試string_types是否顯示數據的DisplayRole。 對於較舊的版本則不是這種情況。 它破壞了我們的測試,因為我們返回了我們認為合理的數據DispalyRole的對象(int,str等)(不是嗎?)。

任何人都可以分享一下,如果您知道為什么會這樣?

技術:Python 2.7.x x64和Pyside v1.2.4操作系統:Windows 7計算機

def _test_data(self):
    """Test model's implementation of data()"""
    if not self._has_children():
        return

    # A valid index should have a valid QVariant data
    assert self._model.index(0, 0).isValid()

    string_types = [str]
    if sys.version_info.major == 2:
        string_types.append(unicode)  # noqa
    if qt_api.QString is not None:
        string_types.append(qt_api.QString)

    string_types = tuple(string_types)

    types = [
        (qt_api.QtCore.Qt.DisplayRole, string_types),
        (qt_api.QtCore.Qt.ToolTipRole, string_types),
        (qt_api.QtCore.Qt.StatusTipRole, string_types),
        (qt_api.QtCore.Qt.WhatsThisRole, string_types),
        (qt_api.QtCore.Qt.SizeHintRole, qt_api.QtCore.QSize),
        (qt_api.QtCore.Qt.FontRole, qt_api.QtGui.QFont),
        (
            qt_api.QtCore.Qt.BackgroundColorRole,
            (qt_api.QtGui.QColor, qt_api.QtGui.QBrush),
        ),
        (
            qt_api.QtCore.Qt.TextColorRole,
            (qt_api.QtGui.QColor, qt_api.QtGui.QBrush),
        ),
        (
            qt_api.QtCore.Qt.DecorationRole,
            (
                qt_api.QtGui.QPixmap,
                qt_api.QtGui.QImage,
                qt_api.QtGui.QIcon,
                qt_api.QtGui.QColor,
                qt_api.QtGui.QBrush,
            ),
        ),
    ]

    # General purpose roles with a fixed expected type
    for role, typ in types:
        data = self._model.data(self._model.index(0, 0), role)
        if data is not None:
            data = qt_api.extract_from_variant(data)

      assert data == None or isinstance(data, typ), role  # noqa
      AssertionError: PySide.QtCore.Qt.ItemDataRole.DisplayRole
      assert (1 == None or False)
      where False = isinstance(1, (<type 'str'>, <type 'unicode'>))

.tox\py27\lib\site-packages\pytestqt\modeltest.py:499: AssertionError

這是pytest-qt維護者之一的建議:

模型測試器基於Qt模型測試器(並已通過v1.3.0更新到其最新版本)。 進行相同的檢查 ,並且Qt的文檔還說 (強調我的意思):

定制模型應返回這些類型的數據。

Qt :: DisplayRole:要以文本形式呈現的關鍵數據。 (QString的)

如果您將該數據用於自定義目的(而不是顯示它),則可能應該使用Qt :: UserRole。

恕我直言,從Qt的測試人員和文檔中很明顯,這是不允許的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM