Skip to content

Conversation

@SehajModi
Copy link

@SehajModi SehajModi commented Dec 15, 2025

Fixes #257

Summary
The test suite was failing to collect tests on fresh installations because test_spi.py and test_uart.py were attempting to perform arithmetic on class properties (SPIMaster._frequency and UART._baudrate) which are not callable constants in the test environment.

Changes

  • Updated tests/test_spi.py to use a hardcoded 1MHz value for PWM_FERQUENCY instead of accessing the class property.
  • Updated tests/test_uart.py to use a hardcoded 1MHz value for PWM_FERQUENCY.

Verification

  • Ran python -m pytest tests/test_spi.py tests/test_uart.py --collect-only locally.
  • Confirmed that pytest can now successfully collect these tests without crashing.

Summary by Sourcery

Stabilize SPI and UART tests by decoupling them from runtime hardware configuration values.

Tests:

  • Update SPI tests to use a fixed 1MHz-derived PWM frequency constant instead of SPIMaster._frequency.
  • Update UART tests to use a fixed 1MHz-derived PWM frequency constant instead of UART._baudrate to avoid collection-time errors.

@sourcery-ai
Copy link

sourcery-ai bot commented Dec 15, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts SPI and UART test constants to use hardcoded 1MHz-derived PWM_FERQUENCY values instead of accessing hardware class attributes, preventing TypeErrors during test collection in environments where those attributes are not callable/constants.

File-Level Changes

Change Details Files
Decouple SPI timing test from SPIMaster._frequency by hardcoding the PWM_FERQUENCY used in expected timing calculations.
  • Replace PWM_FERQUENCY assignment that referenced SPIMaster._frequency with a constant 1MHz-based expression
  • Document the rationale in a nearby comment to clarify that the value is hardcoded for testing
tests/test_spi.py
Decouple UART timing test from UART._baudrate by hardcoding the PWM_FERQUENCY used for test timing expectations.
  • Replace PWM_FERQUENCY assignment that referenced UART._baudrate with a constant 1MHz-based expression
  • Document the rationale in a nearby comment to clarify that the value is hardcoded for testing
tests/test_uart.py

Assessment against linked issues

Issue Objective Addressed Explanation
#257 Update tests/test_spi.py so that PWM_FERQUENCY does not perform arithmetic on SPIMaster._frequency (a method), allowing pytest to collect and run the SPI tests without a TypeError.
#257 Update tests/test_uart.py so that PWM_FERQUENCY does not perform arithmetic on UART._baudrate (a method), allowing pytest to collect and run the UART tests without a TypeError.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • In both test_spi.py and test_uart.py, consider centralizing the 1MHz test frequency into a shared constant (or helper) to avoid duplicating the magic number and to make future changes easier.
  • The hardcoded PWM_FERQUENCY values use different numeric types (1000000.0 vs 1000000); if the tests don’t depend on float vs int semantics, it may be clearer to use the same type in both places for consistency.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In both `test_spi.py` and `test_uart.py`, consider centralizing the `1MHz` test frequency into a shared constant (or helper) to avoid duplicating the magic number and to make future changes easier.
- The hardcoded `PWM_FERQUENCY` values use different numeric types (`1000000.0` vs `1000000`); if the tests don’t depend on float vs int semantics, it may be clearer to use the same type in both places for consistency.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

Tests failing on fresh install: TypeError in test_spi.py and test_uart.py

1 participant