-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Hack-The-Travel/develop
Release 0.2.1 - fix uptime
- Loading branch information
Showing
6 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# general things to ignore | ||
*.py[cod] | ||
.pytest_cache/ | ||
|
||
conf.py | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# -*- coding: utf-8 -*- | ||
from .test_utils import TestUtils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
import pytest | ||
import datetime | ||
from utils import uptime | ||
|
||
|
||
now = datetime.datetime.utcnow() | ||
|
||
|
||
class TestUtils(): | ||
@pytest.mark.parametrize( | ||
'start, check, uptime_str', ( | ||
(now, now + datetime.timedelta(hours=0.5), 'Up 0 hours.'), | ||
(now, now + datetime.timedelta(days=1), 'Up 1 day.'), | ||
(now, now + datetime.timedelta(days=1, hours=1), 'Up 1 day, 1 hour.'), | ||
(now, now + datetime.timedelta(days=1, hours=2), 'Up 1 day, 2 hours.'), | ||
(now, now + datetime.timedelta(days=2), 'Up 2 days.'), | ||
(now, now + datetime.timedelta(days=2, hours=1), 'Up 2 days, 1 hour.'), | ||
(now, now + datetime.timedelta(days=2, hours=2), 'Up 2 days, 2 hours.'), | ||
)) | ||
def test_runtime(self, start, check, uptime_str): | ||
assert uptime(start, check) == uptime_str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
from typing import List | ||
import datetime | ||
|
||
|
||
def uptime(start: datetime.datetime, check: datetime.datetime) -> str: | ||
delta: datetime.timedelta = check - start | ||
delta_days: int = delta.days | ||
delta_hours: int = delta.seconds // 3600 | ||
up: List[str] = [] | ||
if delta_days > 0: | ||
up.append('{} day{}'.format(delta_days, '' if delta_days == 1 else 's')) | ||
if delta_hours > 0: | ||
up.append('{} hour{}'.format(delta_hours, '' if delta_hours == 1 else 's')) | ||
if len(up) == 0: | ||
return 'Up 0 hours.' | ||
return 'Up {}.'.format(', '.join(up)) |