From a4b4adb392f2dd0e1be8a6da44faf4602b734d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Sun, 21 Jun 2026 14:17:14 +0200 Subject: [PATCH] test(sorting): tidy re import + guard tbody match (#68) Co-Authored-By: Claude Opus 4.8 --- tests/test_sorting.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/test_sorting.py b/tests/test_sorting.py index 3312957..295af8b 100644 --- a/tests/test_sorting.py +++ b/tests/test_sorting.py @@ -1,5 +1,6 @@ """Tests for the list-view sorting system (games/sorting.py).""" +import re from datetime import datetime from zoneinfo import ZoneInfo @@ -10,8 +11,6 @@ from django.test import RequestFactory from django.urls import reverse from games.filters import FindFilter -import re - from games.models import Game, Platform, Purchase, Session from games.sorting import ( GAME_DEFAULT_SORT, @@ -185,8 +184,6 @@ class TestListGamesSort: class TestListSessionsSort: def test_sort_by_duration_descending(self, logged_client, two_games): - import re - alpha, beta = two_games Session.objects.create( game=alpha, @@ -251,7 +248,9 @@ class TestListPurchasesSort: ) assert response.status_code == 200 body = response.content.decode() - tbody = re.search(r"]*>(.*?)", body, re.DOTALL).group(1) + tbody_match = re.search(r"]*>(.*?)", body, re.DOTALL) + assert tbody_match + tbody = tbody_match.group(1) assert tbody.index("Beta") < tbody.index("Alpha") # 90 before 10 def test_name_aggregate_sort_no_duplicate_rows(self, logged_client, two_purchases):