PySide6.QtTest.QAbstractItemModelTester¶
- class QAbstractItemModelTester¶
- The - QAbstractItemModelTesterclass helps testing QAbstractItemModel subclasses. More…- Synopsis¶- Methods¶- def - __init__()
- def - model()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- The - QAbstractItemModelTesterclass is a utility class to test item models.- When implementing an item model (that is, a concrete QAbstractItemModel subclass) one must abide to a very strict set of rules that ensure consistency for users of the model (views, proxy models, and so on). - For instance, for a given index, a model’s reimplementation of hasChildren() must be consistent with the values returned by rowCount() and columnCount(). - QAbstractItemModelTesterhelps catching the most common errors in custom item model classes. By performing a series of tests, it will try to check that the model status is consistent at all times. The tests will be repeated automatically every time the model is modified.- QAbstractItemModelTesteremploys non-destructive tests, which typically consist in reading data and metadata out of a given item model.- QAbstractItemModelTesterwill also attempt illegal modifications of the model. In models which are properly implemented, such attempts should be rejected, and no data should be changed as a consequence.- Usage¶- Using - QAbstractItemModelTesteris straightforward. In a test case it is sufficient to create an instance, passing the model that needs to be tested to the constructor:- MyModel *modelToBeTested = ...; auto tester = new QAbstractItemModelTester(modelToBeTested); - QAbstractItemModelTesterwill report testing failures through the Qt Test logging mechanisms.- It is also possible to use - QAbstractItemModelTesteroutside of a test case. For instance, it may be useful to test an item model used by an application without the need of building an explicit unit test for such a model (which might be challenging). In order to use- QAbstractItemModelTesteroutside of a test case, pass one of the- QAbstractItemModelTester::FailureReportingModeenumerators to its constructor, therefore specifying how failures should be logged.- QAbstractItemModelTestermay also report additional debugging information as logging messages under the- qt.modeltestlogging category. Such debug logging is disabled by default; refer to the QLoggingCategory documentation to learn how to enable it.- Note - While - QAbstractItemModelTesteris a valid help for development and testing of custom item models, it does not (and cannot) catch all possible problems in QAbstractItemModel subclasses. Notably, it will never perform meaningful destructive testing of a model, which must be therefore tested separately.- See also - Model/View ProgrammingQAbstractItemModel- class FailureReportingMode¶
- This enumeration specifies how - QAbstractItemModelTestershould report a failure when it tests a QAbstractItemModel subclass.- Constant - Description - QAbstractItemModelTester.FailureReportingMode.QtTest - The failures will be reported as QtTest test failures. - QAbstractItemModelTester.FailureReportingMode.Warning - The failures will be reported as warning messages in the - qt.modeltestlogging category.- QAbstractItemModelTester.FailureReportingMode.Fatal - A failure will cause immediate and abnormal program termination. The reason for the failure will be reported using - qFatal().
 - __init__(model[, parent=None])¶
- Parameters:
- model – - QAbstractItemModel
- parent – - QObject
 
 
 - Creates a model tester instance, with the given - parent, that will test the model- model.- __init__(model, mode[, parent=None])
- Parameters:
- model – - QAbstractItemModel
- mode – - FailureReportingMode
- parent – - QObject
 
 
 - Creates a model tester instance, with the given - parent, that will test the model- model, using the specified- modeto report test failures.- See also - failureReportingMode()¶
- Return type:
 
 - Returns the mode that this instancing is using to report test failures. - See also - model()¶
- Return type:
 
 - Returns the model that this instance is testing. - setUseFetchMore(value)¶
- Parameters:
- value – bool 
 
 - If - valueis true, enables dynamic population of the tested model, which is the default. If- valueis false, it disables it.- See also