Skip to content

Commit

Permalink
Merge branch 'feat/datetime-helper'
Browse files Browse the repository at this point in the history
  • Loading branch information
arifer612 committed Jul 21, 2024
2 parents 7986485 + 7ee36a3 commit 7c7723e
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docker_tag_updater/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@

from .lscr import lscrRules
from .regex_rules import DefaultRules, RegexRules
from .datetime import yymmddRules, yyyymmddRules

rules: RegexRules = DefaultRules + lscrRules
rules: RegexRules = \
DefaultRules + lscrRules + yymmddRules + yyyymmddRules
"""The most general set of rules.
Supports:
- Default semantic versions
- Linuxserver semantic versions
- Datetime-like version strings
See also
--------
regex_rules.DefaultRules : For the aliases for the default set of rules.
lscr.lscrRules : For the aliases for the Linuxserver set of rules.
datetime.yymmddRules: For the aliases for the datetime-like set of rules.
datetime.yyyymmddRules: For the aliases for the datetime-like set of rules.
"""

Expand Down
28 changes: 28 additions & 0 deletions docker_tag_updater/helpers/datetime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""RegexRules object for datetime-like versions."""

from .regex_rules import RegexRules

yymmddRules: RegexRules = RegexRules(
rules = {
"yymmdd": r".*(?P<major>\d{2})(?P<minor>\d{2})(?P<patch>\d{2})"
}
)
"""RegexRules for version strings of the type YYMMDD.
This object has the following equivalent aliases: yymmdd and YYMMDD.
"""

yymmddRules.add_alias("yymmdd", "YYMMDD")


yyyymmddRules: RegexRules = RegexRules(
rules = {
"yyyymmdd": r".*(?P<major>\d{4})(?P<minor>\d{2})(?P<patch>\d{2})"
}
)
"""RegexRules for version strings of the type YYYYMMDD.
This object has the following equivalent aliases: yyyymmdd and YYYYMMDD.
"""

yyyymmddRules.add_alias("yyyymmdd", "YYYYMMDD")
64 changes: 64 additions & 0 deletions tests/test_helper_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,67 @@ def test_lscr_parser_as_default():
"minor": "2",
"patch": "3",
}


def test_yymmdd_parser_standard():
"""Parse a standard YYMMDD version string with the yymmdd rule."""
vstring = "24.06.01"
assert helpers.parse_version(vstring, helpers.rules, "yymmdd") == {
"major": "24",
"minor": "06",
"patch": "01",
}

def test_yymmdd_parser_longstring():
"""Parse a standard YYYYMMDD version string with the yymmdd rule."""
vstring = "20240601"
assert helpers.parse_version(vstring, helpers.rules, "yymmdd") == {
"major": "24",
"minor": "06",
"patch": "01",
}

def test_yymmdd_parser_invalid_string_length():
"""Parse an invalid MMDD version string with the yymmdd rule."""
vstring = "0601"
with pytest.raises(ValueError):
helpers.parse_version(vstring, helpers.rules, "yymmdd")

def test_yymmdd_parser_semver_string():
"""Parse an semantic version string with the yymmdd rule."""
vstring = "version-1.2.3-ls789"
assert helpers.parse_version(vstring, helpers.rules, "yymmdd") == {
"major": "1",
"minor": "2",
"patch": "3",
}

def test_yyyymmdd_parser_standard():
"""Parse a standard YYYYMMDD version string with the yyyymmdd rule."""
vstring = "20240601"
assert helpers.parse_version(vstring, helpers.rules, "yyyymmdd") == {
"major": "2024",
"minor": "06",
"patch": "01",
}

def test_yyyymmdd_parser_longstring():
"""Parse a standard YYYYYYMMDD version string with the yyyymmdd rule."""
vstring = "240601"
with pytest.raises(ValueError):
assert helpers.parse_version(vstring, helpers.rules, "yyyymmdd")

def test_yyyymmdd_parser_invalid_string_length():
"""Parse an invalid MMDD version string with the yyyymmdd rule."""
vstring = "0601"
with pytest.raises(ValueError):
helpers.parse_version(vstring, helpers.rules, "yyyymmdd")

def test_yyyymmdd_parser_semver_string():
"""Parse an semantic version string with the yyyymmdd rule."""
vstring = "version-1.2.3-ls789"
assert helpers.parse_version(vstring, helpers.rules, "yyyymmdd") == {
"major": "1",
"minor": "2",
"patch": "3",
}

0 comments on commit 7c7723e

Please sign in to comment.