Skip to content

Update for kwargs on artifact upload#91

Merged
mshriver merged 2 commits into
ibutsu:mainfrom
mshriver:sender-kwargs-spec
Oct 21, 2025
Merged

Update for kwargs on artifact upload#91
mshriver merged 2 commits into
ibutsu:mainfrom
mshriver:sender-kwargs-spec

Conversation

@mshriver
Copy link
Copy Markdown
Contributor

@mshriver mshriver commented Oct 20, 2025

Pairs with:

ibutsu/ibutsu-server#735
ibutsu/ibutsu-client-python#38

Summary by Sourcery

Use keyword arguments for artifact upload in sender.py and adjust tests and dependencies accordingly

Enhancements:

  • Refactor upload_artifact calls to use keyword arguments for filename and file data
  • Pass prepared_data directly to the API instead of positional arguments

Build:

  • Bump ibutsu-client dependency to >=3.1.1
  • Add pytest-xdist, python-jose, pytest-cov, and coverage[toml] to test environment

Tests:

  • Update tests to capture file data from kwargs rather than positional args
  • Modify test assertions to check kwargs['filename'] instead of args[1]

Copilot AI review requested due to automatic review settings October 20, 2025 12:58
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Oct 20, 2025

Reviewer's Guide

This PR refactors the artifact upload flow to use explicit keyword arguments for filename and file, updates test cases to capture and assert on those kwargs instead of positional args, and expands project dependencies in pyproject.toml to support new test tooling.

Sequence diagram for updated artifact upload with keyword arguments

sequenceDiagram
    participant Sender
    participant ArtifactAPI
    participant Handler
    Sender->>Handler: Get prepared_data
    Sender->>ArtifactAPI: upload_artifact(filename=filename, file=prepared_data, **kwargs)
    ArtifactAPI-->>Sender: Response
Loading

Class diagram for updated _upload_artifact method in Sender

classDiagram
    class Sender {
        _upload_artifact(filename, handler, **kwargs)
    }
    class Handler {
        prepared_data
    }
    class ArtifactAPI {
        upload_artifact(filename, file, **kwargs)
    }
    Sender --> Handler : uses
    Sender --> ArtifactAPI : calls
Loading

File-Level Changes

Change Details Files
Refactor artifact upload to keyword-only args
  • Remove positional filename and data args
  • Pass filename and file via named parameters
  • Eliminate intermediate processed_data variable
src/pytest_ibutsu/sender.py
Update tests to use kwargs for file and filename
  • Modify capture_data to extract data from kwargs["file"]
  • Change assertions to validate kwargs["filename"] instead of args[1]
  • Adjust multi-call capture to record data_content from kwargs
tests/test_sender.py
Expand test and client dependencies
  • Bump ibutsu-client constraint to >=3.1.1
  • Add pytest-xdist, python-jose, pytest-cov, coverage[toml] to extra-dependencies
pyproject.toml

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

@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 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the artifact upload functionality to use keyword arguments instead of positional arguments, addressing compatibility issues with API changes. The changes align with corresponding updates in the ibutsu-server and ibutsu-client-python repositories.

  • Modified artifact upload method to pass filename and file as keyword arguments
  • Added type ignore comments to suppress type checking warnings
  • Updated test dependencies in pyproject.toml to include explicit testing packages

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/pytest_ibutsu/sender.py Updated artifact upload to use kwargs and added type ignore comments
pyproject.toml Replaced generic test dependency with explicit testing packages

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/pytest_ibutsu/sender.py Outdated
Comment thread src/pytest_ibutsu/sender.py Outdated
Comment thread src/pytest_ibutsu/sender.py Outdated
Comment thread src/pytest_ibutsu/sender.py Outdated
@mshriver mshriver marked this pull request as draft October 20, 2025 13:04
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@26cbf7c). Learn more about missing BASE report.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #91   +/-   ##
=======================================
  Coverage        ?   91.63%           
=======================================
  Files           ?        6           
  Lines           ?      992           
  Branches        ?      149           
=======================================
  Hits            ?      909           
  Misses          ?       51           
  Partials        ?       32           
Flag Coverage Δ
unittests 91.63% <ø> (?)

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

Files with missing lines Coverage Δ
src/pytest_ibutsu/sender.py 84.93% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mshriver mshriver marked this pull request as ready for review October 21, 2025 14:00
Copy link
Copy Markdown
Contributor

@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 and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `tests/test_sender.py:481-485` </location>
<code_context>
-        assert args[1] == "none_data.txt"
+        assert kwargs["filename"] == "none_data.txt"
         # None gets converted to "None" string
         assert sender._captured_data_content() == "None"

</code_context>

<issue_to_address>
**suggestion (testing):** Consider adding a test for uploading artifact with empty bytes.

A test for uploading empty bytes (b'') is missing. Please add one to ensure correct handling.

```suggestion
        assert kwargs["filename"] == "empty.txt"
        # Verify the data content was captured correctly - empty string passed as string
        assert sender._captured_data_content() == ""  # Empty string passed directly

        sender._make_call.assert_called_once()
        args, kwargs = sender._make_call.call_args
        assert args[0] == sender.artifact_api.upload_artifact
        assert kwargs["filename"] == "none_data.txt"
        # None gets converted to "None" string

def test_upload_artifact_with_empty_bytes(sender):
    """
    Test uploading an artifact with empty bytes (b'').
    """
    captured_data_content = None

    def capture_data(*args, **kwargs):
        nonlocal captured_data_content
        captured_data_content = kwargs.get("file", captured_data_content)

    sender._make_call = Mock(side_effect=capture_data)
    sender._captured_data_content = lambda: captured_data_content

    sender.upload_artifact(filename="empty_bytes.txt", file=b"")

    sender._make_call.assert_called_once()
    args, kwargs = sender._make_call.call_args
    assert args[0] == sender.artifact_api.upload_artifact
    assert kwargs["filename"] == "empty_bytes.txt"
    # Verify the data content was captured correctly - empty bytes passed as empty string
    assert sender._captured_data_content() == b"" or sender._captured_data_content() == ""  # Accept both representations
```
</issue_to_address>

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 thread tests/test_sender.py
@mshriver mshriver merged commit 5bc0043 into ibutsu:main Oct 21, 2025
9 checks passed
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