Skip to content

🧪 [testing] add read_lines edge case tests and fix sanitize_filename test#144

Closed
Ven0m0 wants to merge 1 commit into
mainfrom
testing-improvement-read-lines-1655711732854780604
Closed

🧪 [testing] add read_lines edge case tests and fix sanitize_filename test#144
Ven0m0 wants to merge 1 commit into
mainfrom
testing-improvement-read-lines-1655711732854780604

Conversation

@Ven0m0
Copy link
Copy Markdown
Owner

@Ven0m0 Ven0m0 commented Mar 8, 2026

I have improved the test coverage for Scripts/common.py by adding unit tests for the read_lines function.

Changes:

  • Added test_read_lines: Verifies that read_lines correctly reads an existing file and strips trailing whitespace from each line.
  • Added test_read_lines_file_not_found: Specifically addresses the requested edge case. It uses unittest.mock.patch to verify that when a non-existent file is passed, the function returns None and prints a descriptive error message to stderr.
  • Fixed test_sanitize_filename_without_name_special_urls: During testing, I discovered an existing test failure where a URL with a port (:8080) was expected to keep the colon in the filename. Since sanitize_filename replaces colons with hyphens, I updated the test assertion to match the correct behavior (example-com-8080- instead of example-com:8080-).
  • Cleaned up imports: Consolidated imports in Scripts/test_common.py by moving tempfile to the top level and adding io and patch.

All 30 tests in the Scripts/ directory now pass successfully.


PR created automatically by Jules for task 1655711732854780604 started by @Ven0m0

…test

- Added test_read_lines to verify happy path and line stripping.
- Added test_read_lines_file_not_found to cover the OSError catch block in read_lines, asserting it returns None and logs to stderr.
- Fixed test_sanitize_filename_without_name_special_urls which had an incorrect assertion for URLs with ports (colons are sanitized to hyphens).
- Updated Scripts/test_common.py imports to include io, tempfile, and patch.

Co-authored-by: Ven0m0 <82972344+Ven0m0@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 8, 2026 09:25
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@aviator-app
Copy link
Copy Markdown

aviator-app Bot commented Mar 8, 2026

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This PR is currently in state closed (PR closed manually).


See the real-time status of this PR on the Aviator webapp.
Use the Aviator Chrome Extension to see the status of your PR within GitHub.

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness of the Scripts/common.py utility functions by significantly improving test coverage for the read_lines function, ensuring it handles both successful file reads and file-not-found scenarios gracefully. Additionally, it corrects an assertion in an existing test for sanitize_filename, aligning the test with the function's actual behavior.

Highlights

  • Test Coverage for read_lines: New unit tests were added for the read_lines function in Scripts/common.py, including a test for successful file reading and another for handling the edge case where a file is not found.
  • sanitize_filename Test Fix: An existing test, test_sanitize_filename_without_name_special_urls, was fixed to correctly assert the behavior of sanitize_filename when processing URLs containing port numbers, specifically how colons are replaced with hyphens.
  • Import Cleanup: Imports in Scripts/test_common.py were consolidated and organized, moving tempfile to the top level and adding io and patch as needed for the new tests.
Changelog
  • Scripts/test_common.py
    • Added io, tempfile, and patch imports for new tests.
    • Imported read_lines from common.py.
    • Updated test_sanitize_filename_without_name_special_urls to reflect the correct filename sanitization for URLs with ports.
    • Introduced test_read_lines to verify the read_lines function correctly reads file content and strips whitespace.
    • Added test_read_lines_file_not_found to test the read_lines function's behavior when a specified file does not exist.
    • Removed a redundant tempfile import within test_write_lines_atomic.
Activity
  • PR created automatically by Jules for task 1655711732854780604, started by @Ven0m0.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 8, 2026

Warning

Rate limit exceeded

@Ven0m0 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 17 minutes and 28 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fa23f55b-8378-43c5-a7a8-a65dcff79057

📥 Commits

Reviewing files that changed from the base of the PR and between 7ae0716 and 80f032c.

📒 Files selected for processing (1)
  • Scripts/test_common.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch testing-improvement-read-lines-1655711732854780604

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the test suite for Scripts/common.py by adding tests for the read_lines function and correcting an assertion in an existing test. The changes improve test coverage as intended. My review includes a suggestion to add one more edge case test for the read_lines function to make the error handling validation more robust.

Comment thread Scripts/test_common.py
Comment on lines +102 to +110
def test_read_lines_file_not_found(self):
with tempfile.TemporaryDirectory() as temp_dir:
temp_dir_path = Path(temp_dir)
non_existent = temp_dir_path / "missing.txt"

with patch("sys.stderr", new_callable=io.StringIO) as mock_stderr:
lines = read_lines(non_existent)
self.assertIsNone(lines)
self.assertIn(f"Error reading {non_existent}", mock_stderr.getvalue())
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.

medium

The read_lines function catches both OSError and UnicodeError. While this test covers the OSError case (via FileNotFoundError), the UnicodeError path remains untested. To ensure complete coverage of the error handling, please consider adding a test case for a file with invalid UTF-8 encoding. You could add a new method like this:

    def test_read_lines_unicode_error(self):
        """Test that read_lines returns None on a UnicodeDecodeError."""
        with tempfile.TemporaryDirectory() as temp_dir:
            target_file = Path(temp_dir) / "bad_encoding.txt"
            with open(target_file, "wb") as f:
                f.write(b"this is not valid utf-8 \xff")

            with patch("sys.stderr", new_callable=io.StringIO) as mock_stderr:
                lines = read_lines(target_file)
                self.assertIsNone(lines)
                self.assertIn(f"Error reading {target_file}", mock_stderr.getvalue())

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Mar 8, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 0

Analysis

The PR makes the following changes:

  1. Import additions - Added io, tempfile, patch imports and imported read_lines from common.py

  2. Test fix - Updated test_sanitize_filename_without_name_special_urls to use example-com-8080- instead of example-com:8080-

    • This fix is correct: sanitize_filename() replaces colons with hyphens: domain.group(1).replace(".", "-").replace(":", "-")
    • The old test assertions were incorrect and didn't match the function's actual behavior
  3. New tests - Added test_read_lines and test_read_lines_file_not_found to properly test the read_lines function

    • Tests verify successful file reading with various line endings
    • Tests verify proper error handling when file is not found

Files Reviewed (1 file)

  • Scripts/test_common.py - All changes verified

The changes are clean, well-tested, and fix an existing incorrect test assertion. No concerns identified.

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 improves the unit test coverage for Scripts/common.py by adding tests for read_lines() error/success paths and correcting an existing sanitize_filename() test expectation for URLs containing ports.

Changes:

  • Add test_read_lines to verify read_lines() returns stripped lines from a real file.
  • Add test_read_lines_file_not_found to verify read_lines() returns None and logs an error to stderr for missing files.
  • Fix sanitize_filename port handling expectation (colon replaced with hyphen) and clean up related imports in the test module.

@Ven0m0 Ven0m0 closed this Mar 9, 2026
@Ven0m0 Ven0m0 deleted the testing-improvement-read-lines-1655711732854780604 branch March 9, 2026 05:17
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