Implement stopwatch feature #157
Open
Themanwhosmellslikesugar wants to merge 4 commits intorelease1from
Open
Conversation
2741ed5 to
3d73d73
Compare
eugulixes
reviewed
Jan 16, 2025
eugulixes
reviewed
Jan 16, 2025
eugulixes
reviewed
Jan 16, 2025
eugulixes
reviewed
Jan 16, 2025
eugulixes
reviewed
Jan 16, 2025
eugulixes
reviewed
Jan 16, 2025
eugulixes
reviewed
Jan 16, 2025
eugulixes
reviewed
Jan 16, 2025
eugulixes
reviewed
Jan 16, 2025
eugulixes
reviewed
Jan 16, 2025
eugulixes
reviewed
Jan 16, 2025
eugulixes
reviewed
Jan 16, 2025
3d73d73 to
9756192
Compare
04fd3f8 to
8b5e421
Compare
a5abbfb to
406901f
Compare
114394f to
3150978
Compare
3150978 to
c071e3c
Compare
warewarewapain
approved these changes
Jan 16, 2026
c071e3c to
dde0dff
Compare
warewarewapain
approved these changes
Jan 16, 2026
53e02b1 to
3f71e48
Compare
tests/test_stopwatch_stats.py
Outdated
Comment on lines
+64
to
+68
| self.assertIn(f'{handler_name}:\n', output) | ||
| self.assertIn(' CPU time: 1.0\n', output) | ||
| self.assertIn(' Select time: 0.5\n', output) | ||
| self.assertIn(' Other IO time: 0.25\n', output) | ||
| self.assertIn(' Real time: 2.0\n', output) |
Contributor
There was a problem hiding this comment.
What do you think about using self.assertEqual here?
3f71e48 to
49f6bfa
Compare
hammett/stopwatch/stats.py
Outdated
| @classmethod | ||
| async def on_exit(cls) -> None: | ||
| """Dump the accumulated stats into a file.""" | ||
| # we can't use async writing to a file because it won't execute in time |
Contributor
There was a problem hiding this comment.
Suggested change
| # we can't use async writing to a file because it won't execute in time | |
| # We can't use async writing to a file because it won't execute in time |
tests/test_bot_stopwatch.py
Outdated
Comment on lines
+62
to
+65
| @override_settings(HANDLERS_STOPWATCH=True) | ||
| def test_setup_sets_event_loop_policy_when_stopwatch_enabled(self): | ||
| """Test _setup sets event loop policy when stopwatch is enabled.""" | ||
| bot = object.__new__(Bot) |
Contributor
There was a problem hiding this comment.
Suggested change
| @override_settings(HANDLERS_STOPWATCH=True) | |
| def test_setup_sets_event_loop_policy_when_stopwatch_enabled(self): | |
| """Test _setup sets event loop policy when stopwatch is enabled.""" | |
| bot = object.__new__(Bot) | |
| @override_settings(HANDLERS_STOPWATCH=True, TOKEN='secret') | |
| def test_setup_sets_event_loop_policy_when_stopwatch_enabled(self): | |
| """Test _setup sets event loop policy when stopwatch is enabled.""" | |
| bot = get_bot() |
tests/test_bot_stopwatch.py
Outdated
Comment on lines
+48
to
+53
| @override_settings(HANDLERS_STOPWATCH=False) | ||
| def test_setup_does_not_set_event_loop_policy_when_disabled(self): | ||
| """Test _setup skips setting the event loop policy when disabled.""" | ||
| bot = object.__new__(Bot) | ||
|
|
||
| with ( |
Contributor
There was a problem hiding this comment.
Suggested change
| @override_settings(HANDLERS_STOPWATCH=False) | |
| def test_setup_does_not_set_event_loop_policy_when_disabled(self): | |
| """Test _setup skips setting the event loop policy when disabled.""" | |
| bot = object.__new__(Bot) | |
| with ( | |
| @override_settings(HANDLERS_STOPWATCH=False, TOKEN='secret') | |
| def test_setup_does_not_set_event_loop_policy_when_disabled(self): | |
| """Test _setup skips setting the event loop policy when disabled.""" | |
| bot = get_bot() | |
| with ( |
Comment on lines
+41
to
+44
| with patch('hammett.stopwatch.collect_handler_stats') as mock_collect_handler_stats: | ||
| mock_collect_handler_stats.side_effect = lambda handler: handler | ||
|
|
||
| get_bot() |
Contributor
There was a problem hiding this comment.
Suggested change
| with patch('hammett.stopwatch.collect_handler_stats') as mock_collect_handler_stats: | |
| mock_collect_handler_stats.side_effect = lambda handler: handler | |
| get_bot() | |
| with patch('hammett.stopwatch.collect_handler_stats') as mock_collect_handler_stats: | |
| mock_collect_handler_stats.side_effect = lambda handler: handler | |
| get_bot() |
Collaborator
Author
There was a problem hiding this comment.
This does not affect the readability of the code and there is no point in arguing over this empty line. I suggest leaving it as it is
tests/utils/test_handler.py
Outdated
Comment on lines
+10
to
+28
| def test_wraps_handler_preserves_assigned_attributes(self): | ||
| """Test preserving wrapper assignments from the wrapped handler.""" | ||
|
|
||
| def original_handler(): | ||
| """Represent a stub handler for the testing purposes.""" | ||
| return 'original' | ||
|
|
||
| def wrapper_handler(): | ||
| """Represent a wrapper handler for the testing purposes.""" | ||
| return 'wrapper' | ||
|
|
||
| wrapped_handler = wraps_handler(original_handler)(wrapper_handler) | ||
|
|
||
| self.assertIs(wrapped_handler, wrapper_handler) | ||
| self.assertEqual(wrapped_handler.__name__, original_handler.__name__) | ||
| self.assertEqual(wrapped_handler.__qualname__, original_handler.__qualname__) | ||
| self.assertEqual(wrapped_handler.__module__, original_handler.__module__) | ||
| self.assertEqual(wrapped_handler.__doc__, original_handler.__doc__) | ||
| self.assertIs(wrapped_handler.__wrapped__, original_handler) |
Contributor
There was a problem hiding this comment.
What do you think about this? I believe we can still combine the two tests, and it won’t look complicated.
def test_wraps_handler_preserves_assigned_attributes(self):
"""Test preserving wrapper assignments from the wrapped handler."""
class TestScreen:
"""The class implements a test screen for testing purposes."""
def handler(self):
"""Represent a stub handler for the testing purposes."""
return 'original'
def wrapper_handler():
"""Represent a wrapper handler for the testing purposes."""
return 'wrapper'
screen = TestScreen()
handler = screen.handler
wrapped_handler = wraps_handler(handler)(wrapper_handler)
self.assertIs(wrapped_handler, wrapper_handler)
self.assertEqual(wrapped_handler.__name__, handler.__name__)
self.assertEqual(wrapped_handler.__qualname__, handler.__qualname__)
self.assertEqual(wrapped_handler.__module__, handler.__module__)
self.assertEqual(wrapped_handler.__doc__, handler.__doc__)
self.assertIs(wrapped_handler.__wrapped__, handler)
self.assertIs(wrapped_handler.__self__, screen)
49f6bfa to
3433ad3
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.