内容表

QTest

概要

静态函数

详细描述

QTest namespace contains all the functions and declarations that are related to the QTestLib 工具。

请参考 QTestLib Manual documentation for information on how to write unit tests.

PySide.QtTest.QTest. LogElementType

The enum specifies the kinds of test log messages.

常量 描述
QTest.LET_Undefined  
QTest.LET_Property  
QTest.LET_Properties  
QTest.LET_Failure  
QTest.LET_Error  
QTest.LET_TestCase  
QTest.LET_TestSuite  
QTest.LET_Benchmark  
QTest.LET_SystemError  

注意

该枚举在 Qt 4.6 引入或被修改

PySide.QtTest.QTest. AttributeIndex

This enum numbers the different tests.

常量 描述
QTest.AI_Undefined  
QTest.AI_Name  
QTest.AI_Result  
QTest.AI_Tests  
QTest.AI_Failures  
QTest.AI_Errors  
QTest.AI_Type  
QTest.AI_Description  
QTest.AI_PropertyValue  
QTest.AI_QTestVersion  
QTest.AI_QtVersion  
QTest.AI_File  
QTest.AI_Line  
QTest.AI_Metric  
QTest.AI_Tag  
QTest.AI_Value  
QTest.AI_Iterations  

注意

该枚举在 Qt 4.6 引入或被修改

PySide.QtTest.QTest. QBenchmarkMetric

This enum lists all the things that can be benchmarked.

常量 描述
QTest.FramesPerSecond Frames per second
QTest.BitsPerSecond Bits per second
QTest.BytesPerSecond Bytes per second
QTest.WalltimeMilliseconds Clock time in milliseconds
QTest.CPUTicks CPU time
QTest.InstructionReads Instruction reads
QTest.Events Event count

另请参阅

QTest.benchmarkMetricName() QTest.benchmarkMetricUnit()

注意

This enum was introduced or modified in Qt 4.7

PySide.QtTest.QTest. TestFailMode

This enum describes the modes for handling an expected failure of the QVERIFY() or QCOMPARE() macros.

常量 描述
QTest.Abort Aborts the execution of the test. Use this mode when it doesn't make sense to execute the test any further after the expected failure.
QTest.Continue Continues execution of the test after the expected failure.

另请参阅

QEXPECT_FAIL()

PySide.QtTest.QTest. MouseAction

This enum describes possible actions for mouse handling.

常量 描述
QTest.MousePress A mouse button is pressed.
QTest.MouseRelease A mouse button is released.
QTest.MouseClick A mouse button is clicked (pressed and released).
QTest.MouseDClick A mouse button is double clicked (pressed and released twice).
QTest.MouseMove The mouse pointer has moved.
PySide.QtTest.QTest. SkipMode

This enum describes the modes for skipping tests during execution of the test data.

常量 描述
QTest.SkipSingle Skips the current entry in the test table; continues execution of all the other entries in the table.
QTest.SkipAll Skips all the entries in the test table; the test won't be executed further.

另请参阅

QSKIP()

PySide.QtTest.QTest. KeyAction

This enum describes possible actions for key handling.

常量 描述
QTest.Press 键被按下。
QTest.Release 键被释放。
QTest.Click 键被点击 (按下并释放)。
static PySide.QtTest.QTest. addColumnInternal ( id , name )
参数:
  • id PySide.QtCore.int
  • name – str
static PySide.QtTest.QTest. asciiToKey ( ascii )
参数: ascii PySide.QtCore.char
返回类型: PySide.QtCore.Qt.Key

Convert an ascii char key value to a Qt Key value. If the key is unknown a 0 is returned.

Note: this may happen more than you like since not all known ascii keys _are_ converted already. So feel free to add all the keys you need.

static PySide.QtTest.QTest. compare_ptr_helper ( t1 , t2 , actual , expected , file , line )
参数:
  • t1 void
  • t2 void
  • actual – str
  • expected – str
  • file – str
  • line PySide.QtCore.int
返回类型:

PySide.QtCore.bool

static PySide.QtTest.QTest. compare_string_helper ( t1 , t2 , actual , expected , file , line )
参数:
  • t1 – str
  • t2 – str
  • actual – str
  • expected – str
  • file – str
  • line PySide.QtCore.int
返回类型:

PySide.QtCore.bool

static PySide.QtTest.QTest. currentDataTag ( )
返回类型: str

Returns the name of the current test data. If the test doesn't have any assigned testdata, the function returns 0.

static PySide.QtTest.QTest. currentTestFailed ( )
返回类型: PySide.QtCore.bool

Returns true if the current test function failed, otherwise false.

static PySide.QtTest.QTest. currentTestFunction ( )
返回类型: str

Returns the name of the test function that is currently executed.

范例:

void MyTestClass.cleanup()
{
    if (qstrcmp(currentTestFunction(), "myDatabaseTest") == 0) {
        // clean up all database connections
        closeAllDatabases()
    }
}
										
static PySide.QtTest.QTest. ignoreMessage ( type , message )
参数:
  • type PySide.QtCore.QtMsgType
  • message – str

Ignores messages created by qDebug() or qWarning() 。若 message with the corresponding type is outputted, it will be removed from the test log. If the test finished and the message was not outputted, a test failure is appended to the test log.

注意

Invoking this function will only ignore one message. If the message you want to ignore is outputted twice, you have to call PySide.QtTest.QTest.ignoreMessage() twice, too.

范例:

QDir dir
QTest.ignoreMessage(QtWarningMsg, "QDir.mkdir: Empty or null file name(s)")
dir.mkdir("")
										

The example above tests that QDir.mkdir() outputs the right warning when invoked with an invalid file name.

static PySide.QtTest.QTest. keyClick ( widget , key [ , modifier=Qt.NoModifier [ , delay=-1 ] ] )
参数:
  • widget PySide.QtGui.QWidget
  • key PySide.QtCore.char
  • modifier PySide.QtCore.Qt.KeyboardModifiers
  • delay PySide.QtCore.int
static PySide.QtTest.QTest. keyClick ( widget , key [ , modifier=Qt.NoModifier [ , delay=-1 ] ] )
参数:
  • widget PySide.QtGui.QWidget
  • key PySide.QtCore.Qt.Key
  • modifier PySide.QtCore.Qt.KeyboardModifiers
  • delay PySide.QtCore.int
static PySide.QtTest.QTest. keyClicks ( widget , sequence [ , modifier=Qt.NoModifier [ , delay=-1 ] ] )
参数:
  • widget PySide.QtGui.QWidget
  • sequence – unicode
  • modifier PySide.QtCore.Qt.KeyboardModifiers
  • delay PySide.QtCore.int
static PySide.QtTest.QTest. keyEvent ( action , widget , key [ , modifier=Qt.NoModifier [ , delay=-1 ] ] )
参数:
static PySide.QtTest.QTest. keyEvent ( action , widget , ascii [ , modifier=Qt.NoModifier [ , delay=-1 ] ] )
参数:
static PySide.QtTest.QTest. keyPress ( widget , key [ , modifier=Qt.NoModifier [ , delay=-1 ] ] )
参数:
  • widget PySide.QtGui.QWidget
  • key PySide.QtCore.Qt.Key
  • modifier PySide.QtCore.Qt.KeyboardModifiers
  • delay PySide.QtCore.int
static PySide.QtTest.QTest. keyPress ( widget , key [ , modifier=Qt.NoModifier [ , delay=-1 ] ] )
参数:
  • widget PySide.QtGui.QWidget
  • key PySide.QtCore.char
  • modifier PySide.QtCore.Qt.KeyboardModifiers
  • delay PySide.QtCore.int
static PySide.QtTest.QTest. keyRelease ( widget , key [ , modifier=Qt.NoModifier [ , delay=-1 ] ] )
参数:
  • widget PySide.QtGui.QWidget
  • key PySide.QtCore.Qt.Key
  • modifier PySide.QtCore.Qt.KeyboardModifiers
  • delay PySide.QtCore.int
static PySide.QtTest.QTest. keyRelease ( widget , key [ , modifier=Qt.NoModifier [ , delay=-1 ] ] )
参数:
  • widget PySide.QtGui.QWidget
  • key PySide.QtCore.char
  • modifier PySide.QtCore.Qt.KeyboardModifiers
  • delay PySide.QtCore.int
static PySide.QtTest.QTest. keyToAscii ( key )
参数: key PySide.QtCore.Qt.Key
返回类型: PySide.QtCore.char
static PySide.QtTest.QTest. mouseClick ( widget , button [ , stateKey=0 [ , pos=QPoint() [ , delay=-1 ] ] ] )
参数:
static PySide.QtTest.QTest. mouseDClick ( widget , button [ , stateKey=0 [ , pos=QPoint() [ , delay=-1 ] ] ] )
参数:
static PySide.QtTest.QTest. mouseEvent ( action , widget , button , stateKey , pos [ , delay=-1 ] )
参数:
static PySide.QtTest.QTest. mouseMove ( widget [ , pos=QPoint() [ , delay=-1 ] ] )
参数:

Moves the mouse pointer to a widget 。若 pos is not specified, the mouse pointer moves to the center of the widget. If a delay (in milliseconds) is given, the test will wait before moving the mouse pointer.

static PySide.QtTest.QTest. mousePress ( widget , button [ , stateKey=0 [ , pos=QPoint() [ , delay=-1 ] ] ] )
参数:
static PySide.QtTest.QTest. mouseRelease ( widget , button [ , stateKey=0 [ , pos=QPoint() [ , delay=-1 ] ] ] )
参数:
static PySide.QtTest.QTest. qElementData ( elementName , metaTypeId )
参数:
  • elementName – str
  • metaTypeId PySide.QtCore.int
返回类型:

void

static PySide.QtTest.QTest. qExpectFail ( dataIndex , comment , mode , file , line )
参数:
返回类型:

PySide.QtCore.bool

static PySide.QtTest.QTest. qGlobalData ( tagName , typeId )
参数:
  • tagName – str
  • typeId PySide.QtCore.int
返回类型:

void

static PySide.QtTest.QTest. qSkip ( message , mode , file , line )
参数:
static PySide.QtTest.QTest. qWaitForWindowShown ( window )
参数: window PySide.QtGui.QWidget
返回类型: PySide.QtCore.bool

Waits until the window is shown in the screen. This is mainly useful for asynchronous systems like X11, where a window will be mapped to screen some time after being asked to show itself on the screen. Returns true.

范例:

widget = QWidget()
widget.show()
QTest.qWaitForWindowShown(widget)
											
static PySide.QtTest.QTest. sendKeyEvent ( action , widget , code , ascii , modifier [ , delay=-1 ] )
参数:
static PySide.QtTest.QTest. sendKeyEvent ( action , widget , code , text , modifier [ , delay=-1 ] )
参数:
static PySide.QtTest.QTest. setBenchmarkResult ( result , metric )
参数:

Sets the benchmark result for this test function to result .

Use this function if you want to report benchmark results without using the QBENCHMARK macro. Use metric to specify how QTestLib should interpret the results.

The context for the result will be the test function name and any data tag from the _data function. This function can only be called once in each test function, subsequent calls will replace the earlier reported results.

Note that the -iterations command line argument has no effect on test functions without the QBENCHMARK macro.

static PySide.QtTest.QTest. simulateEvent ( widget , press , code , modifier , text , repeat [ , delay=-1 ] )
参数:
  • widget PySide.QtGui.QWidget
  • press PySide.QtCore.bool
  • code PySide.QtCore.int
  • modifier PySide.QtCore.Qt.KeyboardModifiers
  • text – unicode
  • repeat PySide.QtCore.bool
  • delay PySide.QtCore.int
static PySide.QtTest.QTest. testObject ( )
返回类型: PySide.QtCore.QObject
static PySide.QtTest.QTest. touchEvent ( [ widget=None [ , deviceType=QTouchEvent.TouchScreen ] ] )
参数:
返回类型:

PySide.QtTest.QTouchEventSequence