File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -175,6 +175,14 @@ def __lt__(self, other):
175175 # Revision is the same, so ignore it for comparison purposes.
176176 return self ._base_semver < other ._base_semver
177177
178+ def __hash__ (self ):
179+ return hash (
180+ (
181+ self ._base_semver .to_tuple (),
182+ self ._revision ,
183+ )
184+ )
185+
178186 @classmethod
179187 def from_string (cls , str_version ):
180188 if not str_version :
Original file line number Diff line number Diff line change 1919
2020import unittest
2121
22+ from univers .nuget import Version
2223from univers .versions import NugetVersion
2324
2425
@@ -77,3 +78,13 @@ def test_less(self):
7778 self .check_order (self .assertLess , "1.0.0-pre" , "1.0.0.1-alpha" )
7879 self .check_order (self .assertLess , "1.0.0" , "1.0.0.1-alpha" )
7980 self .check_order (self .assertLess , "0.9.9.1" , "1.0.0" )
81+
82+ def test_NugetVersion_hash (self ):
83+ vers1 = NugetVersion ("1.0.1+23" )
84+ vers2 = NugetVersion ("1.0.1+23" )
85+ assert hash (vers1 ) == hash (vers2 )
86+
87+ def test_nuget_semver_hash (self ):
88+ vers1 = Version .from_string ("51.0.0+2" )
89+ vers2 = Version .from_string ("51.0.0+2" )
90+ assert hash (vers1 ) == hash (vers2 )
Original file line number Diff line number Diff line change 1+ #
2+ # Copyright (c) nexB Inc. and others.
3+ # SPDX-License-Identifier: Apache-2.0
4+ #
5+ # Visit https://aboutcode.org and https://github.com/nexB/univers for support and download.
6+
7+ from unittest import TestCase
8+
9+ import semver
10+
11+
12+ class TestPythonSemver (TestCase ):
13+ def test_semver_hash (self ):
14+ # python-semver doesn't consider build while hashing
15+ vers1 = semver .VersionInfo .parse ("1.2.3" )
16+ vers2 = semver .VersionInfo .parse ("1.2.3+1" )
17+ assert hash (vers1 ) == hash (vers2 )
You can’t perform that action at this time.
0 commit comments