Skip to content

Commit

Permalink
Fix test_progress for Python 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoMi committed Jun 14, 2022
1 parent 07bd34a commit 4621b00
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions python/publish_unit_test_results.py
Expand Up @@ -103,6 +103,7 @@ def main(settings: Settings, gha: GithubAction) -> None:
logger.info(f'Available memory to read files: {avail_mem}')

# log the progress
# https://github.com/EnricoMi/publish-unit-test-result-action/issues/304
with progress_logger(items=len(files),
interval_seconds=10,
progress_template='Read {progress} files in {time}',
Expand Down
10 changes: 5 additions & 5 deletions python/test/test_progress.py
@@ -1,5 +1,5 @@
import unittest
from datetime import datetime
from datetime import datetime, timezone

import mock

Expand Down Expand Up @@ -32,15 +32,15 @@ def test(self):
logger = mock.MagicMock(info=mock.Mock())
plogger = ProgressLogger(progress, 60, 'progress: {progress} in {time}', logger)
try:
ts = datetime.fromisoformat('2022-06-01 12:34:56')
ts = datetime(2022, 6, 1, 12, 34, 56, tzinfo=timezone.utc)
with mock.patch('publish.progress.datetime', utcnow=mock.Mock(return_value=ts)):
plogger.start()
logger.info.assert_not_called()

progress.observe('item')
logger.info.assert_not_called()

ts = datetime.fromisoformat('2022-06-01 12:35:00')
ts = datetime(2022, 6, 1, 12, 35, 00, tzinfo=timezone.utc)
with mock.patch('publish.progress.datetime', utcnow=mock.Mock(return_value=ts)):
plogger._log_progress()
self.assertEqual([mock.call('progress: 1 of 10 in 4 seconds')], logger.info.call_args_list)
Expand All @@ -50,13 +50,13 @@ def test(self):
progress.observe('item')
logger.info.assert_not_called()

ts = datetime.fromisoformat('2022-06-01 12:40:00')
ts = datetime(2022, 6, 1, 12, 40, 00, tzinfo=timezone.utc)
with mock.patch('publish.progress.datetime', utcnow=mock.Mock(return_value=ts)):
plogger._log_progress()
self.assertEqual([mock.call('progress: 3 of 10 in 5 minutes and 4 seconds')], logger.info.call_args_list)
logger.info.reset_mock()
finally:
ts = datetime.fromisoformat('2022-06-01 12:41:23')
ts = datetime(2022, 6, 1, 12, 41, 23, tzinfo=timezone.utc)
with mock.patch('publish.progress.datetime', utcnow=mock.Mock(return_value=ts)):
plogger.finish('finished: {observations} of {items} in {duration}')
self.assertEqual([mock.call('finished: 3 of 10 in 6 minutes and 27 seconds')], logger.info.call_args_list)
Expand Down

0 comments on commit 4621b00

Please sign in to comment.