weeknum testing

This commit is contained in:
Manuel Barkhau 2020-10-02 22:44:13 +00:00
parent 7b06012180
commit ec4d051e7c
4 changed files with 125 additions and 93 deletions

View file

@ -23,27 +23,12 @@ The recommended approach to using `pylint-ignore` is:
# Overview
- [W0511: fixme (7x)](#w0511-fixme)
- [W0511: fixme (5x)](#w0511-fixme)
- [W0703: broad-except (1x)](#w0703-broad-except)
# W0511: fixme
## File test/test_patterns.py - Line 14 - W0511 (fixme)
- `message: TODO (mb 2020-09-06): test for v2patterns`
- `author : Manuel Barkhau <mbarkhau@gmail.com>`
- `date : 2020-09-18T17:01:05`
```
12: from pycalver import v2patterns
13:
> 14: # TODO (mb 2020-09-06): test for v2patterns
15:
16: V2_PART_PATTERN_CASES = [
```
## File src/pycalver/vcs.py - Line 80 - W0511 (fixme)
- `message: TODO (mb 2018-11-15): Detect encoding of output? Use chardet?`
@ -61,23 +46,6 @@ The recommended approach to using `pylint-ignore` is:
```
## File test/test_version.py - Line 168 - W0511 (fixme)
- `message: TODO (mb 2020-09-06): add tests for new style patterns`
- `author : Manuel Barkhau <mbarkhau@gmail.com>`
- `date : 2020-09-18T17:01:05`
```
163: def vnfo(**field_values):
...
166:
167: PARSE_VERSION_TEST_CASES = [
> 168: # TODO (mb 2020-09-06): add tests for new style patterns
169: # ["YYYY.MM.DD" , "2017.06.07", vnfo(year="2017", month="06", dom="07")],
170: ["{year}.{month}.{dom}" , "2017.06.07", vnfo(year="2017", month="06", dom="07")],
```
## File test/test_config.py - Line 170 - W0511 (fixme)
- `message: TODO (mb 2020-09-18):`
@ -90,25 +58,8 @@ The recommended approach to using `pylint-ignore` is:
168: assert "setup.cfg" in cfg.file_patterns
169:
> 170: # TODO (mb 2020-09-18):
171: # raw_patterns_by_file = _parse_raw_patterns_by_file(cfg)
172: # assert raw_patterns_by_file["setup.py" ] == ["vYYYY0M.BUILD[-RELEASE]", "YYYY0M.BLD[PYTAGNUM]"]
```
## File src/pycalver/__main__.py - Line 259 - W0511 (fixme)
- `message: TODO (mb 2020-09-18): Investigate error messages`
- `author : Manuel Barkhau <mbarkhau@gmail.com>`
- `date : 2020-09-19T16:24:10`
```
231: def _bump(
...
257: sys.exit(1)
258: except Exception as ex:
> 259: # TODO (mb 2020-09-18): Investigate error messages
260: logger.error(str(ex))
261: sys.exit(1)
171: # raw_patterns_by_filepath = _parse_raw_patterns_by_filepath(cfg)
172: # assert raw_patterns_by_filepath["setup.py" ] == ["vYYYY0M.BUILD[-RELEASE]", "YYYY0M.BLD[PYTAGNUM]"]
```
@ -129,7 +80,24 @@ The recommended approach to using `pylint-ignore` is:
```
## File src/pycalver/v2version.py - Line 616 - W0511 (fixme)
## File src/pycalver/__main__.py - Line 300 - W0511 (fixme)
- `message: TODO (mb 2020-09-18): Investigate error messages`
- `author : Manuel Barkhau <mbarkhau@gmail.com>`
- `date : 2020-09-19T16:24:10`
```
270: def _bump(
...
298: sys.exit(1)
299: except Exception as ex:
> 300: # TODO (mb 2020-09-18): Investigate error messages
301: logger.error(str(ex))
302: sys.exit(1)
```
## File src/pycalver/v2version.py - Line 617 - W0511 (fixme)
- `message: TODO (mb 2020-09-20): New Rollover Behaviour:`
- `author : Manuel Barkhau <mbarkhau@gmail.com>`
@ -138,29 +106,30 @@ The recommended approach to using `pylint-ignore` is:
```
578: def incr(
...
614: )
615:
> 616: # TODO (mb 2020-09-20): New Rollover Behaviour:
617: # Reset major, minor, patch to zero if any part to the left of it is incremented
618:
615: )
616:
> 617: # TODO (mb 2020-09-20): New Rollover Behaviour:
618: # Reset major, minor, patch to zero if any part to the left of it is incremented
619:
```
# W0703: broad-except
## File src/pycalver/__main__.py - Line 258 - W0703 (broad-except)
## File src/pycalver/__main__.py - Line 299 - W0703 (broad-except)
- `message: Catching too general exception Exception`
- `author : Manuel Barkhau <mbarkhau@gmail.com>`
- `date : 2020-09-05T14:30:17`
```
231: def _bump(
270: def _bump(
...
256: logger.error(str(ex))
257: sys.exit(1)
> 258: except Exception as ex:
259: # TODO (mb 2020-09-18): Investigate error messages
260: logger.error(str(ex))
297: logger.error(str(ex))
298: sys.exit(1)
> 299: except Exception as ex:
300: # TODO (mb 2020-09-18): Investigate error messages
301: logger.error(str(ex))
```

View file

@ -66,13 +66,13 @@ VALID_RELEASE_VALUES = ("alpha", "beta", "dev", "rc", "post", "final")
_current_date = dt.date.today().isoformat()
def _validate_date(date: typ.Optional[str], pin_date: bool) -> dt.date:
def _validate_date(date: typ.Optional[str], pin_date: bool) -> typ.Optional[dt.date]:
if date and pin_date:
logger.error(f"Can only use either --pin-date or --date='{date}', not both.")
sys.exit(1)
if date is None:
return
return None
try:
dt_val = dt.datetime.strptime(date, "%Y-%m-%d")

View file

@ -109,12 +109,12 @@ def test_incr_default(runner):
cmd = ['test', "-vv", "--pin-date", "--release", "beta", old_version]
result = runner.invoke(cli, cmd)
assert result.exit_code == 0
assert f"Version: v201701.0005-beta\n" in result.output
assert "Version: v201701.0005-beta\n" in result.output
cmd = ['test', "-vv", "--pin-date", "--release", "beta", old_version, "vYYYY0M.BUILD[-RELEASE]"]
cmd = ['test', "-vv", "--pin-date", "--release", "beta", old_version, "vYYYY0M.BUILD[-RELEASE]"]
result = runner.invoke(cli, cmd)
assert result.exit_code == 0
assert f"Version: v201701.1005-beta\n" in result.output
assert "Version: v201701.1005-beta\n" in result.output
def test_incr_pin_date(runner):
@ -613,6 +613,58 @@ def test_v2_get_diff(runner):
assert '+current_version = "v202010.1003-beta"' in diff_lines
WEEKNUM_TEST_CASES = [
# 2020-12-26 Sat
("2020-12-26", "YYYY.0W", "2020.51"),
("2020-12-26", "YYYY.0U", "2020.51"),
("2020-12-26", "GGGG.0V", "2020.52"),
# 2020-12-27 Sun
("2020-12-27", "YYYY.0W", "2020.51"),
("2020-12-27", "YYYY.0U", "2020.52"),
("2020-12-27", "GGGG.0V", "2020.52"),
# 2020-12-28 Mon
("2020-12-28", "YYYY.0W", "2020.52"),
("2020-12-28", "YYYY.0U", "2020.52"),
("2020-12-28", "GGGG.0V", "2020.53"),
# 2020-12-29 Tue
("2020-12-29", "YYYY.0W", "2020.52"),
("2020-12-29", "YYYY.0U", "2020.52"),
("2020-12-29", "GGGG.0V", "2020.53"),
# 2020-12-30 Wed
("2020-12-30", "YYYY.0W", "2020.52"),
("2020-12-30", "YYYY.0U", "2020.52"),
("2020-12-30", "GGGG.0V", "2020.53"),
# 2020-12-31 Thu
("2020-12-31", "YYYY.0W", "2020.52"),
("2020-12-31", "YYYY.0U", "2020.52"),
("2020-12-31", "GGGG.0V", "2020.53"),
# 2021-01-01 Fri
("2021-01-01", "YYYY.0W", "2021.00"),
("2021-01-01", "YYYY.0U", "2021.00"),
("2021-01-01", "GGGG.0V", "2020.53"),
# 2021-01-02 Sat
("2021-01-02", "YYYY.0W", "2021.00"),
("2021-01-02", "YYYY.0U", "2021.00"),
("2021-01-02", "GGGG.0V", "2020.53"),
# 2021-01-03 Sun
("2021-01-03", "YYYY.0W", "2021.00"),
("2021-01-03", "YYYY.0U", "2021.01"),
("2021-01-03", "GGGG.0V", "2020.53"),
# 2021-01-04 Mon
("2021-01-04", "YYYY.0W", "2021.01"),
("2021-01-04", "YYYY.0U", "2021.01"),
("2021-01-04", "GGGG.0V", "2021.01"),
]
@pytest.mark.parametrize("date, pattern, expected", WEEKNUM_TEST_CASES)
def test_weeknum(date, pattern, expected, runner):
cmd = shlex.split(f"test -vv --date {date} 2020.40 {pattern}")
result = runner.invoke(cli, cmd)
assert result.exit_code == 0
assert "New Version: " + expected in result.output
def test_hg_commit_message(runner, caplog):
_add_project_files("README.md", "setup.cfg")
result = runner.invoke(cli, ['init', "-vv"])

View file

@ -13,8 +13,7 @@ from pycalver import version
from pycalver import v1version
from pycalver import v2version
from pycalver import v1patterns
# import pycalver2.patterns as v2patterns
from pycalver import v2patterns
# pylint:disable=protected-access ; allowed for test code
@ -160,46 +159,58 @@ def test_part_field_mapping_v1():
assert not any(b_extra_fields), sorted(b_extra_fields)
def vnfo(**field_values):
def v1vnfo(**field_values):
return v1version._parse_field_values(field_values)
PARSE_VERSION_TEST_CASES = [
# TODO (mb 2020-09-06): add tests for new style patterns
# ["YYYY.MM.DD" , "2017.06.07", vnfo(year="2017", month="06", dom="07")],
["{year}.{month}.{dom}" , "2017.06.07", vnfo(year="2017", month="06", dom="07")],
["{year}.{month}.{dom_short}" , "2017.06.7" , vnfo(year="2017", month="06", dom="7" )],
["{year}.{month}.{dom_short}" , "2017.06.7" , vnfo(year="2017", month="06", dom="7" )],
["{year}.{month_short}.{dom_short}", "2017.6.7" , vnfo(year="2017", month="6" , dom="7" )],
def v2vnfo(**field_values):
return v2version._parse_version_info(field_values)
PARSE_V1_VERSION_TEST_CASES = [
["{year}.{month}.{dom}" , "2017.06.07", v1vnfo(year="2017", month="06", dom="07")],
["{year}.{month}.{dom_short}" , "2017.06.7" , v1vnfo(year="2017", month="06", dom="7" )],
["{year}.{month}.{dom_short}" , "2017.06.7" , v1vnfo(year="2017", month="06", dom="7" )],
["{year}.{month_short}.{dom_short}", "2017.6.7" , v1vnfo(year="2017", month="6" , dom="7" )],
["{year}.{month}.{dom}" , "2017.6.07" , None],
["{year}.{month}.{dom}" , "2017.06.7" , None],
["{year}.{month_short}.{dom}" , "2017.06.7" , None],
["{year}.{month}.{dom_short}" , "2017.6.07" , None],
["{year}.{month_short}.{MINOR}" , "2017.6.7" , vnfo(year="2017", month="6" , minor="7" )],
["{year}.{month}.{MINOR}" , "2017.06.7" , vnfo(year="2017", month="06", minor="7" )],
["{year}.{month}.{MINOR}" , "2017.06.07", vnfo(year="2017", month="06", minor="07")],
["{year}.{month_short}.{MINOR}" , "2017.6.7" , v1vnfo(year="2017", month="6" , minor="7" )],
["{year}.{month}.{MINOR}" , "2017.06.7" , v1vnfo(year="2017", month="06", minor="7" )],
["{year}.{month}.{MINOR}" , "2017.06.07", v1vnfo(year="2017", month="06", minor="07")],
["{year}.{month}.{MINOR}" , "2017.6.7" , None],
["YYYY.0M.0D" , "2017.06.07", v2vnfo(year_y="2017", month="06", dom="07")],
["YYYY.MM.DD" , "2017.6.7" , v2vnfo(year_y="2017", month="6" , dom="7" )],
["YYYY.MM.MD" , "2017.06.07", None],
["YYYY.0M.0D" , "2017.6.7" , None],
]
@pytest.mark.parametrize("pattern_str, line, expected_vinfo", PARSE_VERSION_TEST_CASES)
@pytest.mark.parametrize("pattern_str, line, expected_vinfo", PARSE_V1_VERSION_TEST_CASES)
def test_v1_parse_versions(pattern_str, line, expected_vinfo):
pattern = v1patterns.compile_pattern(pattern_str)
version_match = pattern.regexp.search(line)
if "{" in pattern_str:
pattern = v1patterns.compile_pattern(pattern_str)
version_match = pattern.regexp.search(line)
else:
pattern = v2patterns.compile_pattern(pattern_str)
version_match = pattern.regexp.search(line)
if expected_vinfo is None:
assert version_match is None
return
else:
assert version_match is not None
assert version_match is not None
version_str = version_match.group(0)
version_str = version_match.group(0)
version_info = v1version.parse_version_info(version_str, pattern_str)
assert version_info == expected_vinfo
if "{" in pattern_str:
version_info = v1version.parse_version_info(version_str, pattern_str)
assert version_info == expected_vinfo
else:
version_info = v2version.parse_version_info(version_str, pattern_str)
assert version_info == expected_vinfo
# def test_v2_parse_versions(pattern_str, line, expected_vinfo):
def test_v2_parse_versions():
_vnfo = v2version.parse_version_info("v201712.0033", raw_pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
fvals = {'year_y': 2017, 'month': 12, 'bid': "0033"}