Skip to content

Fix track number 0 not displaying in chat announcements #1205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2025
Merged

Conversation

aw-was-here
Copy link
Collaborator

@aw-was-here aw-was-here commented Jun 21, 2025

Root cause: metadata.py:577 used truthiness check getattr(tag, key) which excluded track=0 from processing. Template finalizers also converted 0 to empty string.

Changes:

  • metadata.py: Change getattr(tag, key) to getattr(tag, key) is not None
  • chat.py (Twitch/Kick): Change if variable: to if variable is not None:
  • utils.py: Change if variable: to if variable is not None:

Testing:

  • Add parameterized test for metadata processing of 0 values
  • Add parameterized test for template rendering of track=0/disc=0
  • All tests pass, pylint clean

Fixes issue where track 0 (common for pre-gap tracks, singles) was not announced in Twitch/Kick chat despite being valid metadata.

Summary by Sourcery

Fix track number zero not displaying in chat announcements by updating conditional checks to treat 0 as a valid value and adding tests to cover zero and None cases.

Bug Fixes:

  • Preserve track=0 and disc=0 in metadata processing by replacing truthiness checks with explicit 'is not None' comparisons
  • Prevent template finalizers in Twitch, Kick, and utility modules from dropping zero values

Tests:

  • Add parameterized tests for metadata processing of zero values
  • Add parameterized tests for template rendering of track=0/disc=0

Copy link

sourcery-ai bot commented Jun 21, 2025

Reviewer's Guide

This PR replaces truthiness-based filtering with explicit is not None checks across metadata parsing and chat/template finalizers to allow zero-value fields, and introduces parameterized tests to verify correct handling of track=0 and disc=0 in both metadata and template rendering.

Class diagram for updated _finalize methods and metadata parsing

classDiagram
    class MetadataHandler {
        +_got_tag(tag)
        metadata
    }
    class TwitchChat {
        +_finalize(variable)
    }
    class KickChat {
        +_finalize(variable)
    }
    class Utils {
        +_finalize(variable)
    }
    MetadataHandler <|-- TwitchChat
    MetadataHandler <|-- KickChat
    MetadataHandler <|-- Utils

    %% Highlight the change: _finalize and _got_tag now use `is not None`
    note for MetadataHandler "_got_tag: now uses `getattr(tag, key) is not None` to allow 0 values"
    note for TwitchChat "_finalize: now uses `if variable is not None` to allow 0 values"
    note for KickChat "_finalize: now uses `if variable is not None` to allow 0 values"
    note for Utils "_finalize: now uses `if variable is not None` to allow 0 values"
Loading

File-Level Changes

Change Details Files
Replace truthiness checks with explicit None comparisons
  • Use getattr(tag, key) is not None in metadata processing loop
  • Update _finalize in Twitch and Kick chat modules to if variable is not None:
  • Update _finalize in utils to if variable is not None:
nowplaying/metadata.py
nowplaying/twitch/chat.py
nowplaying/kick/chat.py
nowplaying/utils.py
Add parameterized tests for zero-value metadata and template rendering
  • Introduce test_metadata_handles_zero_values in tests/test_metadata.py
  • Add test_track_disc_handling in tests/test_templatehandler.py
tests/test_metadata.py
tests/test_templatehandler.py

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 @aw-was-here - I've reviewed your changes and they look great!


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.

Comment on lines +140 to +142
if track_value is not None:
metadata['track'] = track_value
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Avoid conditionals in tests. (no-conditionals-in-tests)

ExplanationAvoid complex code, like conditionals, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Comment on lines +142 to +144
if disc_value is not None:
metadata['disc'] = disc_value
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Avoid conditionals in tests. (no-conditionals-in-tests)

ExplanationAvoid complex code, like conditionals, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Comment on lines +151 to +155
if expected_track:
assert f'Track: {track_value}' in content
else:
assert 'Track:' not in content
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Avoid conditionals in tests. (no-conditionals-in-tests)

ExplanationAvoid complex code, like conditionals, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Comment on lines +156 to +160
if expected_disc:
assert f'Disc: {disc_value}' in content
else:
assert 'Disc:' not in content
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Avoid conditionals in tests. (no-conditionals-in-tests)

ExplanationAvoid complex code, like conditionals, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Root cause: metadata.py:577 used truthiness check `getattr(tag, key)` which
excluded track=0 from processing. Template finalizers also converted 0 to
empty string.

Changes:
- metadata.py: Change `getattr(tag, key)` to `getattr(tag, key) is not None`
- chat.py (Twitch/Kick): Change `if variable:` to `if variable is not None:`
- utils.py: Change `if variable:` to `if variable is not None:`

Testing:
- Add parameterized test for metadata processing of 0 values
- Add parameterized test for template rendering of track=0/disc=0
- All tests pass, pylint clean

Fixes issue where track 0 (common for pre-gap tracks, singles) was not
announced in Twitch/Kick chat despite being valid metadata.
Copy link

codecov bot commented Jun 21, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 66.48%. Comparing base (e9202c9) to head (af1365d).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
nowplaying/twitch/chat.py 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1205      +/-   ##
==========================================
- Coverage   66.56%   66.48%   -0.08%     
==========================================
  Files          63       63              
  Lines       10697    10697              
==========================================
- Hits         7120     7112       -8     
- Misses       3577     3585       +8     
Flag Coverage Δ
unittests 66.48% <66.66%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
nowplaying/kick/chat.py 71.32% <100.00%> (ø)
nowplaying/metadata.py 82.05% <100.00%> (ø)
nowplaying/twitch/chat.py 29.20% <0.00%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aw-was-here aw-was-here merged commit 2396972 into main Jun 21, 2025
15 checks passed
@aw-was-here aw-was-here deleted the track_zero branch June 21, 2025 14:19
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.

1 participant