Correctly parse 2-digit minor versions (py3.10)

This commit is contained in:
Batuhan Taskaya
2020-05-21 15:46:14 +03:00
committed by Dave Halter
parent caadf3bf4c
commit 34b8b7dd79
3 changed files with 23 additions and 2 deletions

View File

@@ -50,6 +50,7 @@ Daniel Fiterman (@dfit99) <fitermandaniel2@gmail.com>
Simon Ruggier (@sruggier) Simon Ruggier (@sruggier)
Élie Gouzien (@ElieGouzien) Élie Gouzien (@ElieGouzien)
Tim Gates (@timgates42) <tim.gates@iress.com> Tim Gates (@timgates42) <tim.gates@iress.com>
Batuhan Taskaya (@isidentical) <isidentical@gmail.com>
Note: (@user) means a github user name. Note: (@user) means a github user name.

View File

@@ -129,7 +129,7 @@ def version_info():
def _parse_version(version): def _parse_version(version):
match = re.match(r'(\d+)(?:\.(\d)(?:\.\d+)?)?$', version) match = re.match(r'(\d+)(?:\.(\d{1,2})(?:\.\d+)?)?$', version)
if match is None: if match is None:
raise ValueError('The given version is not in the right format. ' raise ValueError('The given version is not in the right format. '
'Use something like "3.8" or "3".') 'Use something like "3.8" or "3".')

View File

@@ -1,6 +1,11 @@
from codecs import BOM_UTF8 from codecs import BOM_UTF8
from parso.utils import split_lines, python_bytes_to_unicode from parso.utils import (
split_lines,
parse_version_string,
python_bytes_to_unicode,
)
import parso import parso
import pytest import pytest
@@ -77,3 +82,18 @@ def test_bytes_to_unicode_failing_encoding(code, errors):
python_bytes_to_unicode(code, errors=errors) python_bytes_to_unicode(code, errors=errors)
else: else:
python_bytes_to_unicode(code, errors=errors) python_bytes_to_unicode(code, errors=errors)
@pytest.mark.parametrize(
('version_str', 'version'), [
('3', (3,)),
('3.6', (3, 6)),
('3.6.10', (3, 6)),
('3.10', (3, 10)),
]
)
def test_parse_version_string(version_str, version):
parsed_version = parse_version_string(version_str)
if len(version) == 1:
assert parsed_version[0] == version[0]
else:
assert parsed_version == version