From 0325eea9e181533de35182ffb96a00dfa8e8c8fa Mon Sep 17 00:00:00 2001 From: Aradhya Tiwari <82563152+AradhyaTiwari10@users.noreply.github.com> Date: Wed, 11 Nov 2026 13:38:34 +0530 Subject: [PATCH] Migrate RPM version comparison tests to vers test schema #166 Convert the RPMVERCMP cases from tests/data/rpmvercmp.at into tests/data/schema/rpm_version_cmp.json and run them through SchemaDrivenVersTest with univers.versions.RpmVersion, like the other ecosystem tests. The cases commented out upstream with "dnl" are kept, as before, and labelled as upstream oddities in their description. Reference: https://github.com/aboutcode-org/univers/issues/166 Signed-off-by: Aradhya Tiwari <82563152+AradhyaTiwari10@users.noreply.github.com> --- tests/data/schema/rpm_version_cmp.json | 1521 ++++++++++++++++++++++++ tests/test_rpm_vercmp.py | 115 +- 2 files changed, 1538 insertions(+), 98 deletions(-) create mode 100644 tests/data/schema/rpm_version_cmp.json diff --git a/tests/data/schema/rpm_version_cmp.json b/tests/data/schema/rpm_version_cmp.json new file mode 100644 index 00000000..ff049bd7 --- /dev/null +++ b/tests/data/schema/rpm_version_cmp.json @@ -0,0 +1,1521 @@ +[ + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0", + "1.0" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0", + "2.0" + ] + }, + "expected_output": [ + "1.0", + "2.0" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "2.0", + "1.0" + ] + }, + "expected_output": [ + "1.0", + "2.0" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "2.0.1", + "2.0.1" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "2.0", + "2.0.1" + ] + }, + "expected_output": [ + "2.0", + "2.0.1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "2.0.1", + "2.0" + ] + }, + "expected_output": [ + "2.0", + "2.0.1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "2.0.1a", + "2.0.1a" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "2.0.1a", + "2.0.1" + ] + }, + "expected_output": [ + "2.0.1", + "2.0.1a" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "2.0.1", + "2.0.1a" + ] + }, + "expected_output": [ + "2.0.1", + "2.0.1a" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "5.5p1", + "5.5p1" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "5.5p1", + "5.5p2" + ] + }, + "expected_output": [ + "5.5p1", + "5.5p2" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "5.5p2", + "5.5p1" + ] + }, + "expected_output": [ + "5.5p1", + "5.5p2" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "5.5p10", + "5.5p10" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "5.5p1", + "5.5p10" + ] + }, + "expected_output": [ + "5.5p1", + "5.5p10" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "5.5p10", + "5.5p1" + ] + }, + "expected_output": [ + "5.5p1", + "5.5p10" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "10xyz", + "10.1xyz" + ] + }, + "expected_output": [ + "10xyz", + "10.1xyz" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "10.1xyz", + "10xyz" + ] + }, + "expected_output": [ + "10xyz", + "10.1xyz" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "xyz10", + "xyz10" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "xyz10", + "xyz10.1" + ] + }, + "expected_output": [ + "xyz10", + "xyz10.1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "xyz10.1", + "xyz10" + ] + }, + "expected_output": [ + "xyz10", + "xyz10.1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "xyz.4", + "xyz.4" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "xyz.4", + "8" + ] + }, + "expected_output": [ + "xyz.4", + "8" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "8", + "xyz.4" + ] + }, + "expected_output": [ + "xyz.4", + "8" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "xyz.4", + "2" + ] + }, + "expected_output": [ + "xyz.4", + "2" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "2", + "xyz.4" + ] + }, + "expected_output": [ + "xyz.4", + "2" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "5.5p2", + "5.6p1" + ] + }, + "expected_output": [ + "5.5p2", + "5.6p1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "5.6p1", + "5.5p2" + ] + }, + "expected_output": [ + "5.5p2", + "5.6p1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "5.6p1", + "6.5p1" + ] + }, + "expected_output": [ + "5.6p1", + "6.5p1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "6.5p1", + "5.6p1" + ] + }, + "expected_output": [ + "5.6p1", + "6.5p1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "6.0.rc1", + "6.0" + ] + }, + "expected_output": [ + "6.0", + "6.0.rc1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "6.0", + "6.0.rc1" + ] + }, + "expected_output": [ + "6.0", + "6.0.rc1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "10b2", + "10a1" + ] + }, + "expected_output": [ + "10a1", + "10b2" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "10a2", + "10b2" + ] + }, + "expected_output": [ + "10a2", + "10b2" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0aa", + "1.0aa" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0a", + "1.0aa" + ] + }, + "expected_output": [ + "1.0a", + "1.0aa" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0aa", + "1.0a" + ] + }, + "expected_output": [ + "1.0a", + "1.0aa" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "10.0001", + "10.0001" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "10.0001", + "10.1" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "10.1", + "10.0001" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "10.0001", + "10.0039" + ] + }, + "expected_output": [ + "10.0001", + "10.0039" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "10.0039", + "10.0001" + ] + }, + "expected_output": [ + "10.0001", + "10.0039" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "4.999.9", + "5.0" + ] + }, + "expected_output": [ + "4.999.9", + "5.0" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "5.0", + "4.999.9" + ] + }, + "expected_output": [ + "4.999.9", + "5.0" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "20101121", + "20101121" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "20101121", + "20101122" + ] + }, + "expected_output": [ + "20101121", + "20101122" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "20101122", + "20101121" + ] + }, + "expected_output": [ + "20101121", + "20101122" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "2_0", + "2_0" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "2.0", + "2_0" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "2_0", + "2.0" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "a", + "a" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "a+", + "a+" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "a+", + "a_" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "a_", + "a+" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "+a", + "+a" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "+a", + "_a" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "_a", + "+a" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "+_", + "+_" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "_+", + "+_" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "_+", + "_+" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "+", + "_" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "_", + "+" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0~rc1", + "1.0~rc1" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0~rc1", + "1.0" + ] + }, + "expected_output": [ + "1.0~rc1", + "1.0" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0", + "1.0~rc1" + ] + }, + "expected_output": [ + "1.0~rc1", + "1.0" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0~rc1", + "1.0~rc2" + ] + }, + "expected_output": [ + "1.0~rc1", + "1.0~rc2" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0~rc2", + "1.0~rc1" + ] + }, + "expected_output": [ + "1.0~rc1", + "1.0~rc2" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0~rc1~git123", + "1.0~rc1~git123" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0~rc1~git123", + "1.0~rc1" + ] + }, + "expected_output": [ + "1.0~rc1~git123", + "1.0~rc1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0~rc1", + "1.0~rc1~git123" + ] + }, + "expected_output": [ + "1.0~rc1~git123", + "1.0~rc1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0^", + "1.0^" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0^", + "1.0" + ] + }, + "expected_output": [ + "1.0", + "1.0^" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0", + "1.0^" + ] + }, + "expected_output": [ + "1.0", + "1.0^" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0^git1", + "1.0^git1" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0^git1", + "1.0" + ] + }, + "expected_output": [ + "1.0", + "1.0^git1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0", + "1.0^git1" + ] + }, + "expected_output": [ + "1.0", + "1.0^git1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0^git1", + "1.0^git2" + ] + }, + "expected_output": [ + "1.0^git1", + "1.0^git2" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0^git2", + "1.0^git1" + ] + }, + "expected_output": [ + "1.0^git1", + "1.0^git2" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0^git1", + "1.01" + ] + }, + "expected_output": [ + "1.0^git1", + "1.01" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.01", + "1.0^git1" + ] + }, + "expected_output": [ + "1.0^git1", + "1.01" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0^20160101", + "1.0^20160101" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0^20160101", + "1.0.1" + ] + }, + "expected_output": [ + "1.0^20160101", + "1.0.1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0.1", + "1.0^20160101" + ] + }, + "expected_output": [ + "1.0^20160101", + "1.0.1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0^20160101^git1", + "1.0^20160101^git1" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0^20160102", + "1.0^20160101^git1" + ] + }, + "expected_output": [ + "1.0^20160101^git1", + "1.0^20160102" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0^20160101^git1", + "1.0^20160102" + ] + }, + "expected_output": [ + "1.0^20160101^git1", + "1.0^20160102" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0~rc1^git1", + "1.0~rc1^git1" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0~rc1^git1", + "1.0~rc1" + ] + }, + "expected_output": [ + "1.0~rc1", + "1.0~rc1^git1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0~rc1", + "1.0~rc1^git1" + ] + }, + "expected_output": [ + "1.0~rc1", + "1.0~rc1^git1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0^git1~pre", + "1.0^git1~pre" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0^git1", + "1.0^git1~pre" + ] + }, + "expected_output": [ + "1.0^git1~pre", + "1.0^git1" + ] + }, + { + "description": "Comparison test for RPM version.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.0^git1~pre", + "1.0^git1" + ] + }, + "expected_output": [ + "1.0^git1~pre", + "1.0^git1" + ] + }, + { + "description": "Comparison test for RPM version oddity, commented out in upstream rpmvercmp.at.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "1b.fc17", + "1b.fc17" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version oddity, commented out in upstream rpmvercmp.at.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1b.fc17", + "1.fc17" + ] + }, + "expected_output": [ + "1b.fc17", + "1.fc17" + ] + }, + { + "description": "Comparison test for RPM version oddity, commented out in upstream rpmvercmp.at.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.fc17", + "1b.fc17" + ] + }, + "expected_output": [ + "1b.fc17", + "1.fc17" + ] + }, + { + "description": "Comparison test for RPM version oddity, commented out in upstream rpmvercmp.at.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "1g.fc17", + "1g.fc17" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version oddity, commented out in upstream rpmvercmp.at.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1g.fc17", + "1.fc17" + ] + }, + "expected_output": [ + "1.fc17", + "1g.fc17" + ] + }, + { + "description": "Comparison test for RPM version oddity, commented out in upstream rpmvercmp.at.", + "test_group": "basic", + "test_type": "comparison", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.fc17", + "1g.fc17" + ] + }, + "expected_output": [ + "1.fc17", + "1g.fc17" + ] + }, + { + "description": "Comparison test for RPM version oddity, commented out in upstream rpmvercmp.at.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.1.α", + "1.1.α" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version oddity, commented out in upstream rpmvercmp.at.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.1.α", + "1.1.β" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version oddity, commented out in upstream rpmvercmp.at.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.1.β", + "1.1.α" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version oddity, commented out in upstream rpmvercmp.at.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.1.αα", + "1.1.α" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version oddity, commented out in upstream rpmvercmp.at.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.1.α", + "1.1.ββ" + ] + }, + "expected_output": true + }, + { + "description": "Comparison test for RPM version oddity, commented out in upstream rpmvercmp.at.", + "test_group": "basic", + "test_type": "equality", + "input": { + "input_scheme": "rpm", + "versions": [ + "1.1.ββ", + "1.1.αα" + ] + }, + "expected_output": true + } +] \ No newline at end of file diff --git a/tests/test_rpm_vercmp.py b/tests/test_rpm_vercmp.py index 3f2b1f36..3113caf0 100644 --- a/tests/test_rpm_vercmp.py +++ b/tests/test_rpm_vercmp.py @@ -6,109 +6,28 @@ # # Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. -import io -import os -import re -import unittest +import json +from pathlib import Path -from univers import rpm as vercmp +import pytest -get_vercmp_test = re.compile( - r"(.*)" r"RPMVERCMP\(" r"([^, ]*) *, *" r"([^, ]*) *, *" r"([^\)]*)" r"\).*" -).match +from tests import SchemaDrivenVersTest +from univers.versions import RpmVersion +TEST_DATA = Path(__file__).parent / "data" / "schema" / "rpm_version_cmp.json" -def parse_rpmvercmp_tests(fobj, with_buggy_comparisons=True): - """ - Yield triples (version1, version2, comparison result) describing the RPM - version comparison tests found in the rpmvercmp.at test file-like object at - ``fobj`` Optionally include "buggy" upstream tests. - """ - for line in fobj: - line = line.strip() - if not line: - continue - if not with_buggy_comparisons and line.startswith("dnl"): - continue - match = get_vercmp_test(line) - if not match: - continue - yield match.group(2), match.group(3), int(match.group(4)) +class RpmVersionComp(SchemaDrivenVersTest): + def equality(self): + """Compare version1 and version2 are equal.""" + return RpmVersion(self.input_version1) == RpmVersion(self.input_version2) -class ParserTest(unittest.TestCase): - def test_parse_without_buggy(self): - fobj = io.StringIO( - """ -bla -bla -RPMVERCMP(1, 2, -1) -dnl RPMVERCMP(1a, 1b, -1) -""" - ) - parser = parse_rpmvercmp_tests(fobj, with_buggy_comparisons=False) - expected = [("1", "2", -1)] - assert list(parser) == expected + def comparison(self): + """Sort versions and return them in the correct order.""" + return [v.string for v in sorted(map(RpmVersion, self.input["versions"]))] - def test_parse_with_buggy(self): - fobj = io.StringIO( - """ -bla -bla -RPMVERCMP(1, 2, -1) -dnl RPMVERCMP(1a, 1b, -1) -""" - ) - parser = parse_rpmvercmp_tests(fobj, with_buggy_comparisons=True) - expected = [("1", "2", -1), ("1a", "1b", -1)] - assert list(parser) == expected - -class VersionCompareTest(unittest.TestCase): - pass - - -def create_test_function(ver1, ver2, expected, name): - """ - Return a test function closed on test arguments. - """ - - def test_rpm_version(self): - ver1_str = str(ver1).encode("utf-8") - ver2_str = str(ver2).encode("utf-8") - print(f"testing (ver1={ver1_str}, ver2={ver2_str}, expected=expected{expected}") - result = vercmp.vercmp(ver1, ver2) - if result != expected: - assert result == (expected, ver1, ver2) - - test_rpm_version.__name__ = name - return test_rpm_version - - -def get_tests(): - """ - Yield test function from rpmvercmp.at data. - """ - test_file = os.path.join(os.path.dirname(__file__), "data", "rpmvercmp.at") - - with io.open(test_file, encoding="utf-8") as rpmtests: - tests = list(parse_rpmvercmp_tests(rpmtests, with_buggy_comparisons=True)) - for test_count, (ver1, ver2, expected) in enumerate(tests, 1): - name = f"test_rpm_version_{test_count}" - yield create_test_function(ver1, ver2, expected, name) - - # Make sure we still test something, in case the m4 file drops - # content this will fail the test - assert test_count > 20 - - -def build_tests(): - """ - Create tests from rpmvercmp.at data and attach them to a test class. - """ - for i, test_func in enumerate(get_tests()): - name = f"test_rpm_version_{i}" - setattr(VersionCompareTest, name, test_func) - - -build_tests() +@pytest.mark.parametrize("test_case", json.load(open(TEST_DATA, encoding="utf-8"))) +def test_rpm_vers_cmp(test_case): + rvc = RpmVersionComp.from_data(data=test_case) + rvc.assert_result()