Le lanceur ne prenait que sept préfixes de noms, « le reste demandant une base de données » : les 3703 tests du répertoire passent avec PostgreSQL injoignable, et la suite n'en exécutait que 1131. Il balaie test/test_*.py. Deux formes rendent un fichier muet sans erreur : unittest.main() posé en plein milieu, qui sort avant que la seconde moitié soit définie (quatre fichiers, 87 tests), et l'absence de bloc __main__, qui compte zéro (huit fichiers, 174 tests). Une garde refuse ces deux formes et le retour d'une liste de préfixes. --- EN --- The runner took seven filename prefixes only, "the rest needing a database": all 3703 tests in the directory pass with PostgreSQL unreachable, and the suite ran 1131 of them. It now globs test/test_*.py. Two shapes make a file silent without error: unittest.main() placed mid-file, which exits before the second half is defined (four files, 87 tests), and no __main__ block at all, which counts zero (eight files, 174 tests). A guard now refuses both shapes and the return of a prefix list. Assisted-by: Claude Opus 5 (cherry picked from commit db71b333cc08ae0fce4ddaaf037357648b10236b)
98 lines
3.1 KiB
Python
98 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
# © 2026 TechnoLibre (http://www.technolibre.ca)
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
|
|
|
import unittest
|
|
|
|
from packaging.version import Version
|
|
|
|
from script.poetry.iscompatible import (
|
|
iscompatible,
|
|
parse_requirements,
|
|
string_to_tuple,
|
|
)
|
|
|
|
|
|
class TestStringToTuple(unittest.TestCase):
|
|
def test_three_parts(self):
|
|
self.assertEqual(string_to_tuple("1.0.0"), (1, 0, 0))
|
|
|
|
def test_two_parts(self):
|
|
self.assertEqual(string_to_tuple("2.5"), (2, 5))
|
|
|
|
def test_single_part(self):
|
|
self.assertEqual(string_to_tuple("3"), (3,))
|
|
|
|
def test_large_numbers(self):
|
|
self.assertEqual(string_to_tuple("10.20.300"), (10, 20, 300))
|
|
|
|
|
|
class TestParseRequirements(unittest.TestCase):
|
|
def test_exact_match(self):
|
|
result = parse_requirements("foo==1.0.0")
|
|
self.assertEqual(result, [("==", "1.0.0")])
|
|
|
|
def test_greater_equal(self):
|
|
result = parse_requirements("foo>=1.1.0")
|
|
self.assertEqual(result, [(">=", "1.1.0")])
|
|
|
|
def test_multiple_constraints(self):
|
|
result = parse_requirements("foo>=1.1.0, <1.2")
|
|
self.assertEqual(result, [(">=", "1.1.0"), ("<", "1.2")])
|
|
|
|
def test_not_equal(self):
|
|
result = parse_requirements("bar!=2.0")
|
|
self.assertEqual(result, [("!=", "2.0")])
|
|
|
|
def test_less_equal(self):
|
|
result = parse_requirements("baz<=3.0.0")
|
|
self.assertEqual(result, [("<=", "3.0.0")])
|
|
|
|
def test_no_version_returns_empty(self):
|
|
result = parse_requirements("foo")
|
|
self.assertEqual(result, [])
|
|
|
|
def test_with_comment(self):
|
|
result = parse_requirements("foo>=1.0 # some comment")
|
|
self.assertEqual(result, [(">=", "1.0")])
|
|
|
|
|
|
class TestIsCompatible(unittest.TestCase):
|
|
def test_exact_match_true(self):
|
|
self.assertTrue(iscompatible("foo==1.0.0", Version("1.0.0")))
|
|
|
|
def test_exact_match_false(self):
|
|
self.assertFalse(iscompatible("foo==1.0.0", Version("1.0.1")))
|
|
|
|
def test_greater_equal_true(self):
|
|
self.assertTrue(iscompatible("foo>=5", Version("5.6.1")))
|
|
|
|
def test_greater_equal_false(self):
|
|
self.assertFalse(iscompatible("foo>=5.6.1, <5.7", Version("5.0.0")))
|
|
|
|
def test_range_true(self):
|
|
self.assertTrue(iscompatible("foo>=1.1, <2.1", Version("2.0.0")))
|
|
|
|
def test_range_false(self):
|
|
self.assertFalse(iscompatible("foo>=1.1, <2.0", Version("2.0.0")))
|
|
|
|
def test_less_equal(self):
|
|
self.assertTrue(iscompatible("foo<=1", Version("0.9.0")))
|
|
|
|
def test_greater_than(self):
|
|
self.assertTrue(iscompatible("foo>1.0", Version("1.0.1")))
|
|
|
|
def test_greater_than_equal(self):
|
|
# Version (1,0,0) > (1,0) is True because tuple comparison
|
|
# extends shorter tuple, so this is actually compatible
|
|
self.assertTrue(iscompatible("foo>1.0", Version("1.0.0")))
|
|
|
|
def test_not_equal_true(self):
|
|
self.assertTrue(iscompatible("foo!=1.0.0", Version("1.0.1")))
|
|
|
|
def test_not_equal_false(self):
|
|
self.assertFalse(iscompatible("foo!=1.0.0", Version("1.0.0")))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|