diff options
Diffstat (limited to 'tools/qtpy2cpp_lib/tests')
| -rw-r--r-- | tools/qtpy2cpp_lib/tests/baseline/basic_test.cpp | 62 | ||||
| -rw-r--r-- | tools/qtpy2cpp_lib/tests/baseline/basic_test.py | 44 | ||||
| -rw-r--r-- | tools/qtpy2cpp_lib/tests/test_qtpy2cpp.py | 54 |
3 files changed, 0 insertions, 160 deletions
diff --git a/tools/qtpy2cpp_lib/tests/baseline/basic_test.cpp b/tools/qtpy2cpp_lib/tests/baseline/basic_test.cpp deleted file mode 100644 index 8ee7be31e..000000000 --- a/tools/qtpy2cpp_lib/tests/baseline/basic_test.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -// Converted from basic_test.py -#include <QtCore/Qt> -#include <QtGui/QColor> -#include <QtGui/QPainter> -#include <QtGui/QPaintEvent> -#include <QtGui/QShortcut> -#include <QtWidgets/QApplication> -#include <QtWidgets/QWidget> - -class Window : public QWidget -{ -public: - - Window(QWidget * parent = nullptr) - { - super()->__init__(parent); - } - - void paintEvent(QPaintEvent * e) - { - paint("bla"); - } - - void paint(const QString & what, color = Qt::blue) - { - { // Converted from context manager - p = QPainter(); - p->setPen(QColor(color)); - rect = rect(); - w = rect->width(); - h = rect->height(); - p->drawLine(0, 0, w, h); - p->drawLine(0, h, w, 0); - p->drawText(rect->center(), what); - } - } - - void sum() - { - values = {1, 2, 3}; - result = 0; - for (v: values) { - result += v - } - return result; - } -}; - -int main(int argc, char *argv[]) -{ - QApplication app(sys->argv); - window = Window(); - auto *sc = new QShortcut((Qt::CTRL | Qt::Key_Q), window); - sc->activated->connect(window->close); - window->setWindowTitle("Test"); - window->show(); - sys->exit(app.exec()); - return 0; -} diff --git a/tools/qtpy2cpp_lib/tests/baseline/basic_test.py b/tools/qtpy2cpp_lib/tests/baseline/basic_test.py deleted file mode 100644 index 10dc73767..000000000 --- a/tools/qtpy2cpp_lib/tests/baseline/basic_test.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -import sys - -from PySide6.QtCore import qVersion, Qt -from PySide6.QtGui import QColor, QPainter, QPaintEvent, QShortcut -from PySide6.QtWidgets import QApplication, QWidget - - -class Window(QWidget): - def __init__(self, parent: QWidget = None): - super().__init__(parent) - - def paintEvent(self, e: QPaintEvent): - self.paint("bla") - - def paint(self, what: str, color: Qt.GlobalColor = Qt.blue): - with QPainter(self) as p: - p.setPen(QColor(color)) - rect = self.rect() - w = rect.width() - h = rect.height() - p.drawLine(0, 0, w, h) - p.drawLine(0, h, w, 0) - p.drawText(rect.center(), what) - - def sum(self): - values = [1, 2, 3] - result = 0 - for v in values: - result += v - return result - - -if __name__ == '__main__': - app = QApplication(sys.argv) - window = Window() - sc = QShortcut(Qt.CTRL | Qt.Key_Q, window) - sc.activated.connect(window.close) - window.setWindowTitle("Test") - window.show() - sys.exit(app.exec()) diff --git a/tools/qtpy2cpp_lib/tests/test_qtpy2cpp.py b/tools/qtpy2cpp_lib/tests/test_qtpy2cpp.py deleted file mode 100644 index f9f921705..000000000 --- a/tools/qtpy2cpp_lib/tests/test_qtpy2cpp.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -import subprocess -import tempfile -import sys -from pathlib import Path - -# run pytest-3 - - -def diff_code(actual_code, expected_file): - """Helper to run diff if something fails (Linux only).""" - with tempfile.NamedTemporaryFile(suffix=".cpp") as tf: - tf.write(actual_code.encode('utf-8')) - tf.flush() - diff_cmd = ["diff", "-u", expected_file, tf.name] - subprocess.run(diff_cmd) - - -def run_converter(tool, file): - """Run the converter and return C++ code generated from file.""" - cmd = [sys.executable, tool, "--stdout", file] - output = "" - with subprocess.Popen(cmd, stdout=subprocess.PIPE) as proc: - output_b, errors_b = proc.communicate() - output = output_b.decode('utf-8') - if errors_b: - print(errors_b.decode('utf-8'), file=sys.stderr) - return output - - -def test_examples(): - dir = Path(__file__).resolve().parent - tool = dir.parents[1] / "qtpy2cpp.py" - assert(tool.is_file) - for test_file in (dir / "baseline").glob("*.py"): - assert(test_file.is_file) - expected_file = test_file.parent / (test_file.stem + ".cpp") - if expected_file.is_file(): - actual_code = run_converter(tool, test_file) - assert(actual_code) - expected_code = expected_file.read_text() - # Strip the license - code_start = expected_code.find("// Converted from") - assert(code_start != -1) - expected_code = expected_code[code_start:] - - if actual_code != expected_code: - diff_code(actual_code, expected_file) - assert(actual_code == expected_code) - else: - print(f"Warning, {test_file} is missing a .cpp file.", - file=sys.stderr) |
