Skip to content

Commit b33dd8e

Browse files
authored
Merge pull request #8 from grumBit/Fix-year-checking
Fix year checking
2 parents b0b8249 + 3f4c699 commit b33dd8e

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"folders": [
3-
{
4-
"path": "."
5-
},
6-
],
7-
"settings": {
8-
"python.dataScience.debugJustMyCode": false
9-
}
2+
"folders": [
3+
{
4+
"path": "."
5+
}
6+
],
7+
"settings": {
8+
"python.linting.flake8Enabled": false
9+
}
1010
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "aws_cron_expression_validator"
7-
version = "1.1.2"
7+
version = "1.1.3"
88
authors = [
99
{ name="Graham Coster", email="bitjugglers@gmail.com" },
1010
]

src/aws_cron_expression_validator/validator.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class AWSCronExpressionValidator:
5555
day_of_week_values = r"([1-7]|SUN|MON|TUE|WED|THU|FRI|SAT)" # 1-7 or SAT-SUN
5656
day_of_week_hash = rf"({day_of_week_values}#[1-5])" # Day of the week in the Nth week of the month
5757
year_values = r"((19[7-9][0-9])|(2[0-1][0-9][0-9]))" # 1970-2199
58+
natural_number = r"([0-9]*[1-9][0-9]*)" # Integers greater than 0
5859

5960
@classmethod
6061
def validate(cls, expression: str) -> str:
@@ -100,8 +101,8 @@ def list_regex(cls, values: str) -> str:
100101
@classmethod
101102
def slash_regex(cls, values: str) -> str:
102103
range_ = cls.range_regex(values)
103-
return rf"((\*|{range_}|{values})\/[0-9]*[1-9][0-9]*)"
104-
# Slash can be preceded by *, range, or a valid value and must be followed by an natural
104+
return rf"((\*|{range_}|{values})\/{cls.natural_number})"
105+
# Slash can be preceded by *, range, or a valid value and must be followed by a natural
105106
# number as the increment.
106107

107108
@classmethod
@@ -132,4 +133,4 @@ def day_of_week_regex(cls):
132133

133134
@classmethod
134135
def year_regex(cls):
135-
return rf"^({cls.common_regex(cls.year_values)}|\?|L)$" # values , - * /
136+
return rf"^({cls.common_regex(cls.year_values)})$" # values , - * /

tests/aws_cron_expression_validator/test_validator.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ def test_minute_regex(self):
7171
given_regex = validator.AWSCronExpressionValidator.minute_regex()
7272

7373
given_valid_matches = ["*", "0", "1", "01", "10", "59"]
74-
given_invalid_matches = ["60", "600", "-1", ""]
74+
given_invalid_matches = ["60", "600", "-1", "", "?", "L", "W", "#"]
7575

7676
self._then_matches(given_regex, given_valid_matches)
7777
self._then_does_not_match(given_regex, given_invalid_matches)
7878

7979
def test_hour_regex(self):
8080
given_regex = validator.AWSCronExpressionValidator.hour_regex()
8181
given_valid_matches = ["*", "0", "1", "01", "10", "23"]
82-
given_invalid_matches = ["24", "600", "001", "-1"]
82+
given_invalid_matches = ["24", "600", "001", "-1", "?", "L", "W", "#"]
8383
self._then_matches(given_regex, given_valid_matches)
8484
self._then_does_not_match(given_regex, given_invalid_matches)
8585

@@ -103,6 +103,7 @@ def test_day_of_month_regex(self):
103103
"*/8W",
104104
"?W",
105105
"",
106+
"#",
106107
]
107108

108109
self._then_matches(given_regex, given_valid_matches)
@@ -112,7 +113,7 @@ def test_month_regex(self):
112113
given_regex = validator.AWSCronExpressionValidator.month_regex()
113114

114115
given_valid_matches = ["*", "1", "01", "10", "12", "JAN", "FEB", "DEC", "JAN-MAR", "02-MAR", "*-MAR", "FEB/2"]
115-
given_invalid_matches = ["0", "13", "600", "-1", "XZY", "JANUARY", "", "2/FEB"]
116+
given_invalid_matches = ["0", "13", "600", "-1", "XZY", "JANUARY", "", "2/FEB", "?", "L", "W", "#"]
116117

117118
self._then_matches(given_regex, given_valid_matches)
118119
self._then_does_not_match(given_regex, given_invalid_matches)
@@ -148,6 +149,7 @@ def test_day_of_week_regex(self):
148149
"3#2,5#3",
149150
"3#2-4#2",
150151
"",
152+
"W",
151153
]
152154
self._then_matches(given_regex, given_valid_matches)
153155
self._then_does_not_match(given_regex, given_invalid_matches)
@@ -156,7 +158,22 @@ def test_year_regex(self):
156158
given_regex = validator.AWSCronExpressionValidator.year_regex()
157159

158160
given_valid_matches = ["*", "1970", "2199", "2022", "1992"]
159-
given_invalid_matches = ["1969", "2200", "2222", "1111", "20221", "0", "1", "", "*1970", "19*70"]
161+
given_invalid_matches = [
162+
"1969",
163+
"2200",
164+
"2222",
165+
"1111",
166+
"20221",
167+
"0",
168+
"1",
169+
"",
170+
"*1970",
171+
"19*70",
172+
"?",
173+
"L",
174+
"W",
175+
"#",
176+
]
160177

161178
self._then_matches(given_regex, given_valid_matches)
162179
self._then_does_not_match(given_regex, given_invalid_matches)

0 commit comments

Comments
 (0)