Skip to content

Commit 1ec005b

Browse files
authored
Merge pull request #41 from mathisloge/test/integration_python
Add python bdd integration test
2 parents 5349eec + bd8393e commit 1ec005b

File tree

16 files changed

+137
-12
lines changed

16 files changed

+137
-12
lines changed

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
default_install_hook_types:
2+
- pre-commit
3+
- commit-msg
4+
15
repos:
6+
- repo: https://github.com/compilerla/conventional-pre-commit
7+
rev: v4.2.0
8+
hooks:
9+
- id: conventional-pre-commit
10+
stages: [commit-msg]
11+
args: [--no-color]
212
- repo: https://github.com/pre-commit/pre-commit-hooks
313
rev: v5.0.0
414
hooks:

.vscode/settings.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"python.analysis.extraPaths": [
44
"./build/test",
55
"./python",
6-
"./build/test/python"
6+
"./build/test/python",
7+
"./build/integration_test/qt/python_test"
78
],
8-
"svg.preview.background": "custom"
9+
"svg.preview.background": "custom",
10+
"python-envs.pythonProjects": []
911
}

REUSE.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ path = "**.feature"
3838
SPDX-FileCopyrightText = "2025 Mathis Logemann <[email protected]>"
3939
SPDX-License-Identifier = "MIT"
4040

41+
[[annotations]]
42+
path = "**.ini"
43+
SPDX-FileCopyrightText = "2025 Mathis Logemann <[email protected]>"
44+
SPDX-License-Identifier = "MIT"
45+
4146
[[annotations]]
4247
path = [
4348
"package-lock.json",

integration_test/qt/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ target_include_directories(test_bdd_paths INTERFACE ${CMAKE_CURRENT_BINARY_DIR})
99

1010
add_subdirectory(test_application)
1111
add_subdirectory(cpp_test)
12+
add_subdirectory(python_test)

integration_test/qt/cpp_test/test_manage_todo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static suite<"integration manage todo"> _ = [] { // NOLINT
2121
auto probe = probe_manager.launch_probe_application("test_application", kTestApplicationPath);
2222
probe.wait_for_connected(std::chrono::seconds{5});
2323
steps.scenario("*") = [&] {};
24-
steps.given("I have entered '{todoText}' into the todo input field") = [&](std::string todoText) {
24+
steps.when("I have entered '{todoText}' into the todo input field") = [&](std::string todoText) {
2525
auto input_obj =
2626
probe.find_object(quite::make_query().with_property("objectName", std::string{"inputField"}));
2727
input_obj.property("text").write(std::move(todoText));
@@ -32,7 +32,7 @@ static suite<"integration manage todo"> _ = [] { // NOLINT
3232
btn_obj.mouse_action();
3333
};
3434

35-
steps.then("the todo list should display '{expectdTodoText}' as a new item") = [&](std::string todoText) {
35+
steps.then("the todo list should display '{expectedTodoText}' as a new item") = [&](std::string todoText) {
3636
auto delegate_query = quite::make_query().with_property("text", todoText).with_type("SwipeDelegate");
3737
auto delegate_text = probe.try_find_object(delegate_query, std::chrono::seconds{2}).property("text");
3838
expect(std::holds_alternative<std::string>(delegate_text.value()));
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Feature: Managing todo items
22

33
Scenario: Adding a new todo item to the list
4-
Given I have entered 'Buy groceries' into the todo input field
4+
When I have entered 'Buy groceries' into the todo input field
55
When I click the 'Add' button
66
Then the todo list should display 'Buy groceries' as a new item
7-
Given I have entered 'Buy groceries 2' into the todo input field
7+
When I have entered 'Buy groceries 2' into the todo input field
88
When I click the 'Add' button
99
Then the todo list should display 'Buy groceries 2' as a new item
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SPDX-FileCopyrightText: 2025 Mathis Logemann <[email protected]>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
find_package(Python REQUIRED COMPONENTS Interpreter)
6+
add_test(
7+
NAME python_integration_test
8+
COMMAND ${Python_EXECUTABLE} -m pytest -s ${CMAKE_CURRENT_SOURCE_DIR}
9+
)
10+
set_tests_properties(
11+
python_integration_test
12+
PROPERTIES
13+
ENVIRONMENT
14+
"PYTHONPATH=$<TARGET_FILE_DIR:_quite>/../:${CMAKE_CURRENT_BINARY_DIR}"
15+
)
16+
file(
17+
GENERATE OUTPUT
18+
test_paths/__init__.py
19+
CONTENT
20+
[[
21+
APP_PATH = "$<TARGET_FILE:test_application>"
22+
]]
23+
TARGET test_application
24+
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
bdd_features_base_dir = ../
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# SPDX-FileCopyrightText: 2025 Mathis Logemann <[email protected]>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
from __future__ import annotations
6+
7+
from datetime import timedelta
8+
9+
import pytest
10+
import test_paths
11+
from pytest_bdd import parsers, scenario, then, when
12+
13+
from quite import Probe, ProbeManager, make_query
14+
15+
16+
@pytest.fixture
17+
def application():
18+
"""Test article."""
19+
return ProbeManager().launch_qt_probe_application(
20+
name="todo-app", path_to_application=test_paths.APP_PATH
21+
)
22+
23+
24+
@scenario("manage_todo.feature", "Adding a new todo item to the list")
25+
def test_add_todo():
26+
pass
27+
28+
29+
@when(parsers.parse("I have entered '{todo_text}' into the todo input field"))
30+
def enter_todo_text(application: Probe, todo_text: str):
31+
input_field = application.find_object(
32+
object_query=make_query().with_property("objectName", "inputField")
33+
)
34+
input_field.property("text").write(todo_text)
35+
36+
37+
@when("I click the 'Add' button")
38+
def click_add_button(application: Probe):
39+
button = application.find_object(
40+
object_query=make_query().with_property("objectName", "addButton")
41+
)
42+
button.mouse_action()
43+
44+
45+
@then(
46+
parsers.parse("the todo list should display '{expected_todo_text}' as a new item")
47+
)
48+
def verify_new_todo_exists(application: Probe, expected_todo_text: str):
49+
list_item = application.find_object(
50+
object_query=make_query().with_property("objectName", "listView")
51+
)
52+
new_item_index = list_item.property("count").value() - 1
53+
todo_list_item = application.try_find_object(
54+
object_query=make_query()
55+
.with_property("index", new_item_index)
56+
.with_type("SwipeDelegate"),
57+
timeout=timedelta(seconds=1),
58+
)
59+
assert todo_list_item.property("text").value() == expected_todo_text

integration_test/qt/test_application/main.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Page {
2626

2727
Button {
2828
objectName: "addButton"
29-
text: "+"
29+
text: "+" + listView.count
3030
onClicked: {
3131
if (inputField.text.trim() !== "") {
3232
todoModel.append({

0 commit comments

Comments
 (0)