From 22f6b70a7674cdd9ec5fe926db99f329ee0308dd Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Thu, 19 Feb 2026 17:58:16 -0800 Subject: [PATCH] Change style of test files to eliminate ruff warnings This results in some simplifications. --- urpm/tests/test_cli.py | 1 + urpm/tests/test_database.py | 4 +++- urpm/tests/test_download.py | 28 +++++++++++++++------------- urpm/tests/test_rpmsrate.py | 6 ++++-- urpm/tests/test_suggests.py | 20 ++++++++------------ urpm/tests/test_synthesis.py | 3 +-- 6 files changed, 32 insertions(+), 30 deletions(-) diff --git a/urpm/tests/test_cli.py b/urpm/tests/test_cli.py index 22fad2a..1bea8ac 100644 --- a/urpm/tests/test_cli.py +++ b/urpm/tests/test_cli.py @@ -1,6 +1,7 @@ """Tests for CLI""" import pytest + from urpm.cli.main import create_parser diff --git a/urpm/tests/test_database.py b/urpm/tests/test_database.py index 120cacb..0c30267 100644 --- a/urpm/tests/test_database.py +++ b/urpm/tests/test_database.py @@ -1,8 +1,10 @@ """Tests for SQLite database""" -import pytest import tempfile from pathlib import Path + +import pytest + from urpm.core.database import PackageDatabase diff --git a/urpm/tests/test_download.py b/urpm/tests/test_download.py index 7a5dd98..637cdbd 100644 --- a/urpm/tests/test_download.py +++ b/urpm/tests/test_download.py @@ -1,8 +1,8 @@ import time -from urpm.cli.display import DownloadProgressDisplay, format_size -from urpm.core.download import DownloadProgress, Downloader, DownloadItem, DownloadResult -import pytest -from pathlib import Path + +from urpm.cli.display import DownloadProgressDisplay +from urpm.core.download import DownloadProgress + def test_download_progress_samples_and_speed(): # Test 1: Create DownloadProgress instance @@ -100,6 +100,7 @@ def test_download_progress_samples_and_speed(): print(f"Rapid sample speed: {rapid_speed:.2f} bytes/sec") print() + def test_download_progress_display(): # Initialisation du display display = DownloadProgressDisplay(num_workers=4, bar_width=20, name_width=20) @@ -134,10 +135,10 @@ def get_speed(self): (3, progress3) ] result = display.render(2, 4, 2700000, 10000000, slots_status, global_speed=180000.5) - assert("[2/4] 27% 175.8KB/s" in result) - assert("neovim-data" in result) - assert("blablabla" in result) - assert("prout" in result) + assert "[2/4] 27% 175.8KB/s" in result + assert "neovim-data" in result + assert "blablabla" in result + assert "prout" in result print(result) # Test 3: Affichage avec des noms longs (troncature) @@ -146,8 +147,8 @@ def get_speed(self): progress4 = MockProgress(long_name, 500000, 1000000, 50000.0) slots_status = [(0, progress4)] result = display.render(1, 1, 500000, 1000000, slots_status) - assert("very-long-package-n…" in result) - assert("[██████████░░░░░░░░░░]" in result) + assert "very-long-package-n…" in result + assert "[██████████░░░░░░░░░░]" in result # Test 4: Affichage avec des vitesses différentes print("Test 4: Vitesses différentes") @@ -155,8 +156,8 @@ def get_speed(self): slow_progress = MockProgress("slow-pkg", 10000, 1000000, 1000.0) slots_status = [(0, fast_progress), (2, slow_progress)] result = display.render(0, 2, 110000, 2000000, slots_status) - assert("97.7KB/976.6KB (fr2.rpmfind.net)" in result) - assert("9.8KB/976.6KB (fr2.rpmfind.net)" in result) + assert "97.7KB/976.6KB (fr2.rpmfind.net)" in result + assert "9.8KB/976.6KB (fr2.rpmfind.net)" in result print(result) # Test 5: Affichage avec des tailles différentes @@ -167,5 +168,6 @@ def get_speed(self): result = display.render(0, 2, 50500000, 200000000, slots_status) print(result) + if __name__ == "__main__": - test_download_progress_display() \ No newline at end of file + test_download_progress_display() diff --git a/urpm/tests/test_rpmsrate.py b/urpm/tests/test_rpmsrate.py index f29021e..6198a23 100644 --- a/urpm/tests/test_rpmsrate.py +++ b/urpm/tests/test_rpmsrate.py @@ -1,8 +1,9 @@ """Tests for rpmsrate parser""" +from pathlib import Path import pytest -from pathlib import Path -from urpm.core.rpmsrate import RpmsrateParser, PackageEntry, Section + +from urpm.core.rpmsrate import RpmsrateParser # Sample rpmsrate content for testing @@ -165,6 +166,7 @@ def real_parser(self): p.parse() return p pytest.skip("Real rpmsrate-raw file not found") + return None def test_real_file_has_install_section(self, real_parser): """Test that real file has INSTALL section.""" diff --git a/urpm/tests/test_suggests.py b/urpm/tests/test_suggests.py index 68e4502..de62015 100644 --- a/urpm/tests/test_suggests.py +++ b/urpm/tests/test_suggests.py @@ -9,13 +9,11 @@ 6. Cycle detection (A->B->C->A) """ -import pytest -from unittest.mock import Mock, MagicMock, patch -from typing import List, Dict, Set +from typing import Dict, List import solv -from urpm.core.resolver import Resolver, Alternative, PackageAction +from urpm.core.resolver import Resolver class MockSolvable: @@ -36,9 +34,9 @@ def lookup_deparray(self, dep_type): """Return dependencies based on type.""" if dep_type == solv.SOLVABLE_SUGGESTS: return [MockDep(s) for s in self._suggests] - elif dep_type == solv.SOLVABLE_REQUIRES: + if dep_type == solv.SOLVABLE_REQUIRES: return [MockDep(r) for r in self._requires] - elif dep_type == solv.SOLVABLE_PROVIDES: + if dep_type == solv.SOLVABLE_PROVIDES: return [MockDep(p) for p in self._provides] return [] @@ -309,7 +307,7 @@ def test_iterative_finds_suggests_of_suggests(self): # Simulate iterative collection (like main.py should do) all_suggests = [] packages_to_check = ['pkg-a'] - checked = set(['pkg-a']) + checked = {'pkg-a'} max_iter = 5 for _ in range(max_iter): @@ -349,12 +347,10 @@ def test_iterative_handles_cycle(self): # Simulate iterative collection all_suggests = [] packages_to_check = ['pkg-a'] - checked = set(['pkg-a']) # pkg-a is the initial package + checked = {'pkg-a'} # pkg-a is the initial package max_iter = 5 - iterations = 0 - for _ in range(max_iter): - iterations += 1 + for _iteration, _ in enumerate(range(max_iter)): suggests, alts = resolver.find_available_suggests( packages_to_check, resolved_packages=list(checked) ) @@ -373,7 +369,7 @@ def test_iterative_handles_cycle(self): break # Should complete without hitting max_iter due to infinite loop - assert iterations < max_iter, "Possible infinite loop detected" + assert _iteration < max_iter, "Possible infinite loop detected" suggest_names = [s.name for s in all_suggests] assert 'pkg-b' in suggest_names diff --git a/urpm/tests/test_synthesis.py b/urpm/tests/test_synthesis.py index 5b812e8..f9a775f 100644 --- a/urpm/tests/test_synthesis.py +++ b/urpm/tests/test_synthesis.py @@ -1,7 +1,6 @@ """Tests for synthesis parser""" -import pytest -from urpm.core.synthesis import parse_nevra, parse_dependency +from urpm.core.synthesis import parse_dependency, parse_nevra class TestParseNevra: