mirror of
https://github.com/thp/pyotherside.git
synced 2025-01-28 23:52:55 +08:00
Test call_sync with one parameter
Introduce qtquicktests/ with a single test. This allows us to write tests entirely in QML with no C++ component. The single test tests for regressions in issue #49. The qtquicktests framework (supplied by QT/QML upstream) provides only a template expansion that provides a main() function. Therefore, we must generate a new binary as the shim for running the tests, as the public API mechanism doesn't allow us to generate a single binary with the two backends. As qmake supports only one binary per directory (without getting really hacky), we must add a new directory for it. Perhaps now the tests/ directory should be renamed to cpptests/ or something for clarity. Unfortunately "make check" doesn't work, so I've provided a "./run" wrapper you can run manually from inside the qtquicktests/ directory for now. This is because qtquicktests appears to have been designed to test QML apps, not plugins. This isn't much of a problem, except that the test runner is unable to find the in-tree built plugin. The generated binary does support a "-plugins <directory>" option, but it seems to be impossible to get "make check" to use it: * The qmake extension supports an INCLUDESPATH to add a "-includes <directory> option, but no equivalent PLUGINSPATH. * Even though qtquicktests reports "." as being in the plugins path after a failure, it does not appear to actually look there, so symlinking or copying the plugin in to the current directory doesn't work. * qmltestcase.prf uses testcase.prf which allows TESTARGS to be added. However, it reads this from the environment (a Makefile variable) rather than from a qmake variable. There appears to be no way of exporting a Makefile variable from a .pro file (unless its name is to start with EXPORT_). See http://stackoverflow.com/q/35554105/478206. * Copying and modifying mysqltestcase.prf from /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/ to add a PLUGINSPATH configurable option does work, but then you have to run qmake with "QMAKEFEATURES=. qmake" since even though it is documented to look in the project root, that doesn't work (I tried both the top level and inside qtquicktests/). So I gave up trying to get "make check" to work, and resorted to a wrapper around calling qtquicktests with the correct options, which at least works for now.
This commit is contained in:
parent
260c9c275c
commit
16fc61db5b
@ -1,5 +1,5 @@
|
|||||||
TEMPLATE = subdirs
|
TEMPLATE = subdirs
|
||||||
SUBDIRS += src tests
|
SUBDIRS += src tests qtquicktests
|
||||||
|
|
||||||
tests.depends = src
|
tests.depends = src
|
||||||
|
|
||||||
|
17
qtquicktests/PythonRectangle.qml
Normal file
17
qtquicktests/PythonRectangle.qml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import QtQuick 2.3
|
||||||
|
|
||||||
|
import io.thp.pyotherside 1.5
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
property bool ready: false;
|
||||||
|
property alias py: py;
|
||||||
|
Python {
|
||||||
|
id: py
|
||||||
|
Component.onCompleted: {
|
||||||
|
addImportPath(Qt.resolvedUrl('.'));
|
||||||
|
importModule('test_functions', function() {
|
||||||
|
ready = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2
qtquicktests/qtquicktests.cpp
Normal file
2
qtquicktests/qtquicktests.cpp
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#include <QtQuickTest/quicktest.h>
|
||||||
|
QUICK_TEST_MAIN(qtquicktests)
|
4
qtquicktests/qtquicktests.pro
Normal file
4
qtquicktests/qtquicktests.pro
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
TEMPLATE = app
|
||||||
|
TARGET = qtquicktests
|
||||||
|
CONFIG += warn_on qmltestcase
|
||||||
|
SOURCES += qtquicktests.cpp
|
3
qtquicktests/run
Executable file
3
qtquicktests/run
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
exec ./qtquicktests -plugins ../src
|
4
qtquicktests/test_functions.py
Normal file
4
qtquicktests/test_functions.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
def function_that_takes_one_parameter(parameter):
|
||||||
|
'''For tst_model_add_one:call_sync_with_parameters'''
|
||||||
|
assert parameter == 1
|
||||||
|
return 1
|
13
qtquicktests/tst_call_sync.qml
Normal file
13
qtquicktests/tst_call_sync.qml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import QtTest 1.0
|
||||||
|
|
||||||
|
PythonRectangle {
|
||||||
|
TestCase {
|
||||||
|
name: "call_sync_with_parameters"
|
||||||
|
when: ready
|
||||||
|
|
||||||
|
function test_call_sync_with_parameters() {
|
||||||
|
var result = py.call_sync('test_functions.function_that_takes_one_parameter', [1]);
|
||||||
|
compare(result, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user