jackdewinter / pymarkdown

MIT License
75 stars 17 forks source link

https://github.com/jackdewinter/pymarkdown/issues/1208 #1253

Closed jackdewinter closed 1 week ago

jackdewinter commented 1 week ago

https://github.com/jackdewinter/pymarkdown/issues/1208

Summary by Sourcery

Refactor MD012 rule tests to use parameterized tests and add new test cases. Fix issue with blank lines separated by pragmas not being recognized correctly. Update changelog to reflect the fix.

Bug Fixes:

Enhancements:

Documentation:

Tests:

sourcery-ai[bot] commented 1 week ago

Reviewer's Guide by Sourcery

This PR refactors the test suite for rule MD012 (multiple consecutive blank lines) and fixes a bug where blank lines separated by pragmas were not being properly handled. The changes include converting individual test functions into parameterized tests and adding new test cases for pragma-related scenarios.

Class diagram for test suite refactoring in test_md012.py

classDiagram
    class MarkdownScanner {
        +invoke_main(arguments: List[str])
        +assert_results(expected_output: str, expected_error: str, expected_return_code: int)
    }
    class pluginRuleTest {
        +name: str
        +source_file_name: str
        +scan_expected_return_code: int
        +scan_expected_output: str
    }
    class pluginConfigErrorTest {
        +name: str
        +use_strict_config: bool
        +set_args: List[str]
        +expected_error: str
    }
    class test_md012 {
        +test_md012_scan(test: pluginRuleTest)
        +test_md012_config(test: pluginConfigErrorTest)
    }
    MarkdownScanner --> pluginRuleTest
    MarkdownScanner --> pluginConfigErrorTest
    test_md012 --> pluginRuleTest
    test_md012 --> pluginConfigErrorTest
    note for test_md012 "Refactored to use parameterized tests for better maintainability"

Class diagram for rule_md_012.py changes

classDiagram
    class PluginScanContext {
    }
    class MarkdownToken {
        +is_blank_line: bool
        +line_number: int
    }
    class RuleMd012 {
        -__last_blank_line: MarkdownToken
        -__blank_line_count: int
        +next_token(context: PluginScanContext, token: MarkdownToken)
        -__check_for_excess_blank_lines(context: PluginScanContext)
    }
    RuleMd012 --> MarkdownToken
    RuleMd012 --> PluginScanContext
    note for RuleMd012 "Fixed handling of blank lines separated by pragmas"

File-Level Changes

Change Details Files
Refactored test suite to use parameterized tests
  • Converted individual test functions into parameterized test cases
  • Added test configuration array with predefined test scenarios
  • Implemented test helper functions for better code organization
  • Reduced code duplication by consolidating test logic
test/rules/test_md012.py
Fixed bug in blank line handling with pragmas
  • Added logic to reset blank line count when lines are not consecutive
  • Added check for line number differences between blank lines
  • Added new test cases for pragma-separated blank lines
pymarkdown/plugins/rule_md_012.py
Updated documentation and metadata
  • Added changelog entry for Issue 1208 fix
  • Updated test coverage metrics
  • Updated test result counts
newdocs/src/changelog.md
publish/coverage.json
publish/test-results.json

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. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a 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. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) 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 - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).
codecov[bot] commented 1 week ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.98%. Comparing base (2a9931e) to head (ecba0a5). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1253 +/- ## ======================================= Coverage 99.98% 99.98% ======================================= Files 191 191 Lines 21194 21197 +3 Branches 2715 2716 +1 ======================================= + Hits 21190 21193 +3 Misses 1 1 Partials 3 3 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.