From 61055f036538dd2a22df568246a32171357b0cc6 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Fri, 9 Aug 2024 10:09:53 +0200 Subject: [PATCH] fix: union of constraints of unequal clauses --- .../version_solver/helper.py | 4 ++-- tests/version_solver/test_range.py | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/version_solver/test_range.py diff --git a/idf_component_manager/version_solver/helper.py b/idf_component_manager/version_solver/helper.py index 1508466..ddd98fd 100644 --- a/idf_component_manager/version_solver/helper.py +++ b/idf_component_manager/version_solver/helper.py @@ -48,7 +48,7 @@ def parse_single_constraint( elif _range.operator == _range.OP_GTE: return Range(min=version, include_min=True, string=str(_range)) elif _range.operator == _range.OP_NEQ: - return Union(Range(min=version, string=str(_range)), Range(max=version, string=str(_range))) + return Union(Range(max=version, string=str(_range)), Range(min=version, string=str(_range))) else: return Range(version, version, True, True, str(_range)) @@ -168,7 +168,7 @@ def convert_dependency(self, dependency: Dependency) -> Constraint: ) for r in dependency.constraint.ranges ] - constraint = Union.of(ranges) + constraint = Union.of(*ranges) else: raise ValueError('should be "Union" or "Range"') diff --git a/tests/version_solver/test_range.py b/tests/version_solver/test_range.py new file mode 100644 index 0000000..cec7d66 --- /dev/null +++ b/tests/version_solver/test_range.py @@ -0,0 +1,22 @@ +# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 + +from idf_component_manager.version_solver.helper import parse_constraint + + +def test_parse_union_of_multiple_unequal(): + assert parse_constraint('!=5.0.2,!=5.1.3,!=5.2.1') + + +def test_union_of_multiple_unequal(): + a = parse_constraint('!=5.0.2') + b = parse_constraint('!=5.1.3') + c = parse_constraint('!=5.2.1') + + d = a.intersect(b).intersect(c) + + assert str(d) == '<5.0.2 || >5.0.2,<5.1.3 || >5.1.3,<5.2.1 || >5.2.1' + assert d.ranges[0] == parse_constraint('<5.0.2') + assert d.ranges[1] == parse_constraint('>5.0.2,<5.1.3') + assert d.ranges[2] == parse_constraint('>5.1.3,<5.2.1') + assert d.ranges[3] == parse_constraint('>5.2.1')