Browse Source

fix #14, add unit tests for VersionSelector class

master
Niklas Rosenstein 1 year ago
parent
commit
8110e8314c
No known key found for this signature in database GPG Key ID: 6D269B33D25F6C6
2 changed files with 13 additions and 0 deletions
  1. + 5
    - 0
      src/shore/model.py
  2. + 8
    - 0
      src/test/shore/util/test_version.py

+ 5
- 0
src/shore/model.py

@ -79,8 +79,13 @@ class VersionSelector(object):
- `^X.Y.Z` -> `>=X.Y.Z,<X+1.0.0`
- `~X.Y.Z` -> `>=X.Y.Z,<X.Y+1.0`
- `X.Y.Z -> ==X.Y.Z`
"""
# Poor-mans test if this looks like the form 'X.Y.Z' without anything around it.
if not ',' in self._string and self._string[0].isdigit():
return '==' + self._string
regex = r'[~^](\d+\.\d+(\.\d+)?[.\-\w]*)'
def sub(match):
index = {'^': 0, '~': 1}[match.group(0)[0]]

+ 8
- 0
src/test/shore/util/test_version.py

@ -1,5 +1,6 @@
from shore.util.version import Version
from shore.model import VersionSelector
import pytest
@ -33,3 +34,10 @@ def test_comparison():
assert not (Version(b) < Version(a))
assert Version(b) > Version(a)
assert not (Version(a) > Version(b))
def test_version_selector():
assert VersionSelector('1.0.0').to_setuptools() == '==1.0.0'
assert VersionSelector('~1.0.0').to_setuptools() == '>=1.0.0,<1.1.0'
assert VersionSelector('^1.0.0').to_setuptools() == '>=1.0.0,<2.0.0'
assert VersionSelector('<=1.0.0,>0.5.0').to_setuptools() == '<=1.0.0,>0.5.0'

Loading…
Cancel
Save