Skip to content

Conversation

@nadavo
Copy link
Owner

@nadavo nadavo commented Aug 7, 2025

The existing tests for the Timer module were not robust and lacked assertions. This change rewrites the tests using pytest to properly verify the timer's functionality.

The new tests cover:

  • The Timer class as a context manager and a standalone object.
  • The @Timer decorator with and without arguments.
  • Correct formatting of elapsed time in milliseconds, seconds, minutes, and hours.
  • Custom logger usage.

While writing the tests, a bug was found in the hours formatting where the minutes were incorrectly calculated. This has been fixed.

The existing tests for the Timer module were not robust and lacked assertions. This change rewrites the tests using pytest to properly verify the timer's functionality.

The new tests cover:
- The Timer class as a context manager and a standalone object.
- The @Timer decorator with and without arguments.
- Correct formatting of elapsed time in milliseconds, seconds, minutes, and hours.
- Custom logger usage.

While writing the tests, a bug was found in the hours formatting where the minutes were incorrectly calculated. This has been fixed.
Add dedicated tests for the `init_logger` static method in the Timer module. These tests cover cases where a logger is provided and where one is not.

A bug was discovered in `init_logger` where it would not add a handler if a parent logger (like the root logger) had a handler. This was due to using `logger.hasHandlers()` which checks the hierarchy. This is fixed by checking `logger.handlers` instead, which only checks the specific logger instance.
Adds docstrings to the following methods in `timer_module.py`:
- `__init__`
- `__enter__`
- `__exit__`
- `_start`
- `stop`
- `init_logger`
- `get_default_timestamp`

This improves the documentation and maintainability of the code.
Bumps the version of the module from 0.4.5 to 0.5.0 to reflect the recent bug fixes, test improvements, and documentation additions.
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.

2 participants