Skip to content

Implement stopwatch feature #157

Open
Themanwhosmellslikesugar wants to merge 4 commits intorelease1from
feature/stopwatch
Open

Implement stopwatch feature #157
Themanwhosmellslikesugar wants to merge 4 commits intorelease1from
feature/stopwatch

Conversation

@Themanwhosmellslikesugar
Copy link
Copy Markdown
Collaborator

No description provided.

@Themanwhosmellslikesugar Themanwhosmellslikesugar requested a review from a team December 19, 2024 14:16
@Themanwhosmellslikesugar Themanwhosmellslikesugar force-pushed the feature/stopwatch branch 4 times, most recently from 2741ed5 to 3d73d73 Compare December 19, 2024 14:32
@warewarewapain warewarewapain force-pushed the feature/stopwatch branch 3 times, most recently from 04fd3f8 to 8b5e421 Compare January 23, 2025 11:56
@warewarewapain warewarewapain force-pushed the feature/stopwatch branch 3 times, most recently from a5abbfb to 406901f Compare March 11, 2025 10:38
@Themanwhosmellslikesugar Themanwhosmellslikesugar force-pushed the feature/stopwatch branch 2 times, most recently from 114394f to 3150978 Compare January 15, 2026 08:24
@Themanwhosmellslikesugar Themanwhosmellslikesugar force-pushed the feature/stopwatch branch 3 times, most recently from 53e02b1 to 3f71e48 Compare January 22, 2026 11:48
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about using self.assertEqual here?

@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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

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 (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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)
Copy link
Copy Markdown
Contributor

@warewarewapain warewarewapain Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants