File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Expand file tree Collapse file tree 3 files changed +35
-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
2121from univers .versions import NugetVersion
22+ from univers .nuget import Version
2223
2324
2425class NuGetTest (unittest .TestCase ):
@@ -76,3 +77,13 @@ def test_less(self):
7677 self .check_order (self .assertLess , "1.0.0-pre" , "1.0.0.1-alpha" )
7778 self .check_order (self .assertLess , "1.0.0" , "1.0.0.1-alpha" )
7879 self .check_order (self .assertLess , "0.9.9.1" , "1.0.0" )
80+
81+ def test_NugetVersion_hash (self ):
82+ vers1 = NugetVersion ("1.0.1+23" )
83+ vers2 = NugetVersion ("1.0.1+23" )
84+ assert hash (vers1 ) == hash (vers2 )
85+
86+ def test_nuget_semver_hash (self ):
87+ vers1 = Version .from_string ("51.0.0+2" )
88+ vers2 = Version .from_string ("51.0.0+2" )
89+ 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+ import semver
9+
10+
11+ class TestPythonSemver (TestCase ):
12+ def test_semver_hash (self ):
13+ # python-semver doesn't consider build while hashing
14+ vers1 = semver .VersionInfo .parse ("1.2.3" )
15+ vers2 = semver .VersionInfo .parse ("1.2.3+1" )
16+ assert hash (vers1 ) == hash (vers2 )
You can’t perform that action at this time.
0 commit comments