-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add configurable first day of the week #294
Conversation
75af2a3
to
916b30e
Compare
@sandrobonazzola thank you for this PR. Can you please add tests to it? |
Fixes psss#293 Signed-off-by: Sandro Bonazzola <[email protected]>
Signed-off-by: Sandro Bonazzola <[email protected]>
916b30e
to
d74d90c
Compare
@kwk done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for adding the tests.
@@ -267,7 +281,7 @@ def test_get_token_plain_different_name(self): | |||
token = str(uuid4()) | |||
config = {"mytoken": token} | |||
self.assertIsNone(get_token(config)) | |||
self.assertEqual(get_token(config, token_key="mytoken"), token) | |||
self.assertEqual(get_token(config, token_key="mytoken"), token) # nosec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this slipped in from your other PR #297 .
self.assertEqual(get_token(config, token_key="mytoken"), token) # nosec | |
self.assertEqual(get_token(config, token_key="mytoken"), token) |
@@ -278,7 +292,7 @@ def test_get_token_file(self): | |||
|
|||
def test_get_token_file_empty(self): | |||
""" Test getting a token from a file with just whitespace. """ | |||
token_in_file = " " | |||
token_in_file = " " # nosec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this slipped in from your other PR #297 .
token_in_file = " " # nosec | |
token_in_file = " " |
@@ -296,7 +310,7 @@ def test_get_token_file_different_name(self): | |||
token_in_file = str(uuid4()) | |||
with self.get_token_as_file(token_in_file) as filename: | |||
config = {"mytoken_file": filename} | |||
self.assertEqual( | |||
self.assertEqual( # nosec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this slipped in from your other PR #297 .
self.assertEqual( # nosec | |
self.assertEqual( |
@@ -125,6 +124,17 @@ def quarter(self): | |||
f"Invalid quarter start '{month}', should be integer.") | |||
return month | |||
|
|||
@property | |||
def week(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this called week
when it is really the first day of the week?
def week(self): | |
def first_day_of_week(self) -> int: |
""" The first day of the week, 0 (Monday) by default""" | ||
week = self.parser.get("general", "week", fallback=0) | ||
try: | ||
week = int(week) % 7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to have a string in the config rather than an int. Transferring to an int internally is fine though. I think of something like this:
#!/bin/env python
WEEKDAYS = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
config_first_day_of_week = "WednES"
# Default first day of the week:
first_day_of_week = 0
# This should allow anything from: "Mon", "mon", "mond", "monda", "monday", "MON",
# but not "mo", "MO" or "M" because it is too short.
if len(config_first_day_of_week) > 3:
for idx, weekday in enumerate(WEEKDAYS):
if weekday.lower().startswith(config_first_day_of_week.lower()):
first_day_of_week = idx
print(first_day_of_week)
Sorry, no time to keep working on this, abandoning |
Fixes #293
Add configurable first day of the week:
Signed-off-by: Sandro Bonazzola [email protected]