From cd3e8437036fa03a282206de55875a98af058e21 Mon Sep 17 00:00:00 2001 From: DavidoTek <54072917+DavidoTek@users.noreply.github.com> Date: Sat, 27 Jul 2024 14:00:42 +0200 Subject: [PATCH] Add Unit Testing Workflow using PyTest (#400) * Add PyTest CI workflow * Add initial Unit Test * Testing-CI: Cache Python Pip dependencies * Testing-CI: Add Qt dependencies --- .github/workflows/testing-ci.yml | 44 ++++++++++++++++++++++++++++++++ tests/test_util.py | 22 ++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 .github/workflows/testing-ci.yml create mode 100644 tests/test_util.py diff --git a/.github/workflows/testing-ci.yml b/.github/workflows/testing-ci.yml new file mode 100644 index 00000000..7ff4aca5 --- /dev/null +++ b/.github/workflows/testing-ci.yml @@ -0,0 +1,44 @@ +name: Test using Pytest + +on: + push: + branches: + - main + pull_request: + +jobs: + tests: + name: "Run PyTest" + runs-on: ubuntu-22.04 + strategy: + matrix: + python-version: ["3.10"] + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: "${{ matrix.python-version }}" + cache: "pip" + + - name: Install dependencies + run: | + sudo apt install -y libegl1 libxkbcommon0 + pip install pytest pytest-md pytest-emoji + + - name: Install ProtonUp-Qt + run: pip install -e . + + - name: Run pytest + uses: pavelzw/pytest-action@v2 + env: + QT_QPA_PLATFORM: "offscreen" + with: + verbose: true + emoji: true + job-summary: true + custom-arguments: '-q' + click-to-expand: true + report-title: 'ProtonUp-Qt Test Report' diff --git a/tests/test_util.py b/tests/test_util.py new file mode 100644 index 00000000..46b510c7 --- /dev/null +++ b/tests/test_util.py @@ -0,0 +1,22 @@ +from pupgui2.util import * + +from pupgui2.datastructures import SteamApp, LutrisGame, HeroicGame + + +def test_get_random_game_name(): + """ test whether get_random_game_name returns a valid game name """ + names = ["game", "A super cool game", "A game with a very long name that is very long", "0123456789"] + + steam_app = [SteamApp() for _ in range(len(names))] + lutris_game = [LutrisGame() for _ in range(len(names))] + heroic_game = [HeroicGame() for _ in range(len(names))] + + for i, name in enumerate(names): + steam_app[i].game_name = name + lutris_game[i].name = name + heroic_game[i].title = name + + for i in range(10): + assert get_random_game_name(steam_app) in names + assert get_random_game_name(lutris_game) in names + assert get_random_game_name(heroic_game) in names