@@ -1511,3 +1511,38 @@ def test_contains_with_compatible_operator(self):
15111511 combination = SpecifierSet ("~=1.18.0" ) & SpecifierSet ("~=1.18" )
15121512 assert "1.19.5" not in combination
15131513 assert "1.18.0" in combination
1514+
1515+ @pytest .mark .parametrize (
1516+ ("spec1" , "spec2" , "input_versions" ),
1517+ [
1518+ # Test zero padding
1519+ ("===1.0" , "===1.0.0" , ["1.0" , "1.0.0" ]),
1520+ ("===1.0.0" , "===1.0" , ["1.0" , "1.0.0" ]),
1521+ ("===1.0" , "===1.0.0" , ["1.0.0" , "1.0" ]),
1522+ ("===1.0.0" , "===1.0" , ["1.0.0" , "1.0" ]),
1523+ # Test local versions
1524+ ("===1.0" , "===1.0+local" , ["1.0" , "1.0+local" ]),
1525+ ("===1.0+local" , "===1.0" , ["1.0" , "1.0+local" ]),
1526+ ("===1.0" , "===1.0+local" , ["1.0+local" , "1.0" ]),
1527+ ("===1.0+local" , "===1.0" , ["1.0+local" , "1.0" ]),
1528+ ],
1529+ )
1530+ def test_arbitrary_equality_is_intersection_preserving (
1531+ self , spec1 , spec2 , input_versions
1532+ ):
1533+ """
1534+ In general we expect for two specifiers s1 and s2, that the two statements
1535+ are equivalent:
1536+ * set((s1, s2).filter(versions))
1537+ * set(s1.filter(versions)) & set(s2.filter(versions)).
1538+
1539+ This is tricky with the arbitrary equality operator (===) since it does
1540+ not follow normal version comparison rules.
1541+ """
1542+ s1 = Specifier (spec1 )
1543+ s2 = Specifier (spec2 )
1544+ versions1 = set (s1 .filter (input_versions ))
1545+ versions2 = set (s2 .filter (input_versions ))
1546+ combined_versions = set (SpecifierSet (f"{ spec1 } ,{ spec2 } " ).filter (input_versions ))
1547+
1548+ assert versions1 & versions2 == combined_versions
0 commit comments