Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.

Conversation

@ikostan
Copy link
Member

@ikostan ikostan commented Feb 18, 2025

Summary by Sourcery

This pull request includes a new kata solution, test improvements, refactorings for readability, and updates to the build and CI pipelines. It introduces a solution for the 'Replace With Alphabet Position' kata and enhances existing tests with parameterized tests and edge cases. The build process is updated to use Python 3.12 and Ubuntu 24.04, and includes new PyType linting workflows. The CI pipeline is configured to ignore specific branches for pull requests and to run pytest after PyType linting.

New Features:

  • Adds a solution for the 'Replace With Alphabet Position' kata.
  • Adds tests for the 'Replace With Alphabet Position' kata, including edge cases.

Enhancements:

  • Refactors the Sudoku test cases to use parameterized tests for better readability and maintainability.
  • Refactors the is_prime test cases to use parameterized tests for better readability and maintainability.
  • Refactors the gen_primes test cases to use parameterized tests for better readability and maintainability.
  • Improves the readability of the 'make_spiral' solution by extracting conditional logic into separate functions.
  • Improves the readability of the 'battleship_field_validator' solution by using the all() function.
  • Simplifies the calculation of combinations in the 'easy_line' solution.
  • Adds type hints to the __calc_rgb method in the Potion class.

Build:

  • Updates GitHub Actions workflows to use Python 3.12 and Ubuntu 24.04.
  • Updates GitHub Actions workflows to install dependencies using python -m pip.
  • Updates GitHub Actions workflows to run linters and type checkers using python -m.
  • Updates GitHub Actions workflows to include a timeout of 10 minutes.
  • Updates GitHub Actions workflows to run pytest with coverage reporting.
  • Updates GitHub Actions workflows to report coverage to Codacy.
  • Adds new GitHub Actions workflows for PyType linting for kyu2, kyu3, kyu6, kyu7, and kyu8.
  • Removes the workflow for MyPy and replaces it with individual workflows for each kyu.
  • Removes the workflow for PyType and replaces it with individual workflows for each kyu.
  • Adds a workflow for testing the utils directory.

CI:

  • Configures the main build pipeline to ignore the master branch and kyu branches for pull requests.
  • Configures the main build pipeline to run PyType linting for kyu2, kyu3, kyu6, kyu7, and kyu8.
  • Configures the main build pipeline to run pytest after PyType linting.

Tests:

  • Adds test cases for empty strings, numbers, special characters, and mixed alphanumeric input to the 'Replace With Alphabet Position' kata.
  • Adds a test case for the print_log function.

Chores:

  • Removes the pytest skip mark from the line_safari_is_that_a_line test.
  • Removes the copy_allure_history.py script.
ikostan and others added 30 commits February 1, 2025 23:03
Merge pull request #624 from iKostanOrg/master
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Using config file /home/runner/work/codewars/codewars/.pylintrc ************* Module kyu_6.replace_with_alphabet_position.test_replace_with_alphabet_position kyu_6/replace_with_alphabet_position/test_replace_with_alphabet_position.py:68:0: C0304: Final newline missing (missing-final-newline) ************* Module kyu_6.replace_with_alphabet_position.solution kyu_6/replace_with_alphabet_position/solution.py:13:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation) kyu_6/replace_with_alphabet_position/solution.py:19:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
./kyu_6/replace_with_alphabet_position/solution.py:1 at module level: D400: First line should end with a period (not 'n') The [first line of a] docstring is a phrase ending in a period. ./kyu_6/replace_with_alphabet_position/__init__.py:1 at module level: D400: First line should end with a period (not 'n')
bad-indentation / W0311 Message emitted: Bad indentation. Found %s %s, expected %s Description: Used when an unexpected number of indentation's tabulations or spaces has been found. Problematic code: if input(): print('yes') # [bad-indentation] Correct code: if input(): print("yes") Additional details: The option --indent-string can be used to set the indentation unit for this check.
The error you're getting is "bad-indentation (W0311)". Since you want tabs, your "editor.insertSpaces": true, should instead be "editor.insertSpaces": false,, and to make pylint accept your usage of tabs for indentation, you need to put the following in a .pylintrc file in the root of your workspace folder: [FORMAT] indent-string=\t
@codacy-production
Copy link

codacy-production bot commented Feb 18, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 2c9ab621 96.55%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (2c9ab62) Report Missing Report Missing Report Missing
Head commit (3b484c0) 2644 2485 93.99%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#656) 58 56 96.55%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 18, 2025

Reviewer's Guide by Sourcery

This pull request includes several enhancements and refactorings across multiple modules. Key changes include improving test coverage with parameterized tests, enhancing code readability by extracting conditional logic and assigning intermediate calculations to variables, and optimizing performance with memoization. Additionally, new GitHub Actions workflows have been added for improved CI/CD.

Sequence diagram for Potion mixing

sequenceDiagram participant Potion1 participant Potion2 Potion1->>Potion1: mix(Potion2) Potion1->>Potion1: __calc_rgb(Potion2, new_volume) Potion1->>Potion1: Calculate new RGB values Potion1-->>Potion1: Return new Potion with mixed color and volume 
Loading

File-Level Changes

Change Details Files
Refactor test cases to use parameterized tests for IsPrimeTestCase and GenPrimesTestCase to improve readability and maintainability.
  • Replaced individual test methods with parameterized tests.
  • Added parameterized tests for both positive and negative test cases.
  • Improved test descriptions and logging for parameterized tests.
utils/primes/test_is_prime.py
utils/primes/test_primes_generator.py
Consolidated and enhanced test cases for the Sudoku class using parameterized tests to cover a wider range of scenarios.
  • Combined multiple test cases into a single parameterized test method.
  • Added more test data to cover edge cases and invalid scenarios.
  • Improved test descriptions and logging for parameterized tests.
kyu_4/validate_sudoku_with_size/test_sudoku.py
Refactored the make_spiral solution to improve readability and reduce complexity by extracting conditional logic into separate functions.
  • Extracted multiple conditional checks in the right function into separate functions (get_condition_0 to get_condition_5).
  • Improved code readability by reducing the length and complexity of the right function.
  • No logic was changed.
kyu_3/make_spiral/solution.py
Improved readability in the validate_battlefield solution by using all instead of chained and conditions.
  • Replaced chained and conditions with the all function for conciseness.
  • No logic was changed.
kyu_3/battleship_field_validator/validator.py
Enhanced the Potion class by adding a helper method to calculate RGB values and improving type hinting.
  • Added a private helper method __calc_rgb to encapsulate RGB calculation logic.
  • Improved type hinting for the color property and the mix method.
  • No logic was changed.
kyu_6/potion_class_101/potion.py
Updated GitHub Actions workflows to use specific branch names instead of patterns, added timeout-minutes, and improved dependency management.
  • Replaced branch patterns with specific branch names in workflow triggers.
  • Added timeout-minutes to prevent jobs from running indefinitely.
  • Improved dependency installation and version checking in workflows.
  • Added new workflows for pytype for kyu2, kyu3, kyu6, kyu7, and kyu8.
  • Added new workflows for pytest for utils, kyu3, kyu4, kyu5, kyu6, and kyu7.
.github/workflows/lint_test_build_pipeline.yml
.github/workflows/pytype_kyu6.yml
.github/workflows/flake8_kyu6.yml
.github/workflows/flake8_kyu7.yml
.github/workflows/mypy_kyu4.yml
.github/workflows/mypy_kyu5.yml
.github/workflows/mypy_kyu6.yml
.github/workflows/mypy_kyu7.yml
.github/workflows/flake8_kyu8.yml
.github/workflows/pydocstyle_kyu6.yml
.github/workflows/pytype_kyu7.yml
.github/workflows/pytype_kyu8.yml
.github/workflows/mypy.yml
.github/workflows/pydocstyle_kyu5.yml
.github/workflows/pydocstyle_kyu7.yml
.github/workflows/pylint_kyu6.yml
.github/workflows/pylint_kyu7.yml
.github/workflows/flake8_kyu3.yml
.github/workflows/pydocstyle_kyu3.yml
.github/workflows/pydocstyle_kyu4.yml
.github/workflows/pylint_kyu4.yml
.github/workflows/flake8_kyu4.yml
.github/workflows/flake8_kyu5.yml
.github/workflows/pydocstyle.yml
.github/workflows/pylint_kyu5.yml
.github/workflows/pytype_kyu2.yml
.github/workflows/mypy_kyu3.yml
.github/workflows/pylint_kyu3.yml
.github/workflows/flake8.yml
.github/workflows/flake8_kyu2.yml
.github/workflows/pytest_kyu2.yml
Refactored the epidemic solution to improve readability by assigning intermediate calculations to variables.
  • Assigned intermediate calculations for susceptible and infected individuals to variables.
  • Improved code readability by making the calculations more explicit.
  • No logic was changed.
kyu_6/disease_spread/epidemic.py
Added a new solution for the 'Replace With Alphabet Position' kata and included comprehensive unit tests.
  • Implemented the alphabet_position function to replace letters with their alphabet position.
  • Created a test suite with parameterized tests for various scenarios, including edge cases.
  • Added a README file with a description and example.
kyu_6/replace_with_alphabet_position/test_replace_with_alphabet_position.py
kyu_6/replace_with_alphabet_position/solution.py
kyu_6/replace_with_alphabet_position/README.md
Refactored the calculate solution to improve readability by assigning the result of the evaluation to a variable.
  • Assigned the result of aeval.eval(s) to a variable named result.
  • Improved code readability by making the evaluation more explicit.
  • No logic was changed.
kyu_7/basic_math_add_or_subtract/calculate.py
Refactored the sol_equa solution to improve readability by using a conditional expression for the start value.
  • Replaced the if statement with a conditional expression for the start value.
  • Improved code readability by making the condition more concise.
  • No logic was changed.
kyu_5/diophantine_equation/solution.py
Refactored the calculate_damage test to improve readability by assigning the test data to variables.
  • Assigned the test data to variables.
  • Improved code readability by making the test data more explicit.
  • No logic was changed.
kyu_6/pokemon_damage_calculator/test_calculate_damage.py
Refactored the done_or_not solution to improve readability by using backslashes for line continuation.
  • Used backslashes for line continuation.
  • Improved code readability by making the conditions more explicit.
  • No logic was changed.
kyu_5/did_i_finish_my_sudoku/is_sudoku_done.py
Refactored the __update_experience solution to improve readability by using backslashes for line continuation.
  • Used backslashes for line continuation.
  • Improved code readability by making the conditions more explicit.
  • No logic was changed.
kyu_4/the_greatest_warrior/warrior.py
Refactored the is_data_valid solution to improve readability by using backslashes for line continuation.
  • Used backslashes for line continuation.
  • Improved code readability by making the conditions more explicit.
  • No logic was changed.
kyu_4/validate_sudoku_with_size/sudoku.py
Refactored the calc_combination_per_row_item solution to improve readability by removing unnecessary variables.
  • Removed unnecessary variables.
  • Improved code readability by making the calculation more concise.
  • No logic was changed.
kyu_7/easy_line/easyline.py
Refactored the is_prime solution to improve performance by adding memoization.
  • Added memoization to the is_prime function.
  • Improved performance by caching the results of previous calculations.
  • No logic was changed.
kyu_5/master_your_primes_sieve_with_memoization/primes.py
Added new files for utils and primes.
  • Added new files for utils and primes.
  • No logic was changed.
utils/__init__.py
utils/primes/__init__.py
utils/primes/is_prime.py
Added new files for test_log_func.
  • Added new files for test_log_func.
  • No logic was changed.
utils/test_log_func.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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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
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 @ikostan - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The addition of parameterized tests makes the test suite more concise and readable.
  • Consider adding a workflow to run tests on the utils directory.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 3 issues found
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

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.

def test_sudoku_class(self):
@parameterized.expand([
([[1]], True, 'Testing valid 1x1'),
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (testing): Duplicated test case

The test case ([[1]], True, 'Testing valid 1x1') appears to be duplicated. Please remove one instance.

@qltysh
Copy link

qltysh bot commented Feb 18, 2025

❌ 58 blocking issues (71 total)

Tool Category Rule Count
prettier Style Incorrect formatting, autoformat by running `qlty fmt`. 58
qlty Structure Function with high complexity (count = 16): ship_counter_by_row 7
qlty Structure Deeply nested control flow (level = 4) 2
qlty Duplication Found 17 lines of similar code in 2 locations (mass = 74) 2
qlty Structure High total complexity (count = 62) 1
qlty Structure Function with many returns (count = 4): is_prime 1

@qltysh one-click actions:

  • Auto-fix formatting (qlty fmt && git push)
    qlty successfully analyzed this pull request in 4m.
kyu_4/validate_sudoku_with_size/test_sudoku.py @@ -30,7 +31,85 @@ class SudokuTestCase(unittest.TestCase): """Testing Sudoku class.""" def test_sudoku_class(self): @parameterized.expand([ ([[1]], True, 'Testing valid 1x1'), Contributor @sourcery-ai sourcery-ai bot 3 minutes ago issue (testing): Duplicated test case The test case ([[1]], True, 'Testing valid 1x1') appears to be duplicated. Please remove one instance.
kyu_4/validate_sudoku_with_size/test_sudoku.py Comment on lines +39 to +48 ([[7, 8, 4, 1, 5, 9, 3, 2, 6], [5, 3, 9, 6, 7, 2, 8, 4, 1], [6, 1, 2, 4, 3, 8, 7, 5, 9], [9, 2, 8, 7, 1, 5, 4, 6, 3], [3, 5, 7, 8, 4, 6, 1, 9, 2], [4, 6, 1, 9, 2, 3, 5, 8, 7], [8, 7, 6, 3, 9, 4, 2, 1, 5], [2, 4, 3, 5, 6, 1, 9, 7, 8], [1, 9, 5, 2, 8, 7, 6, 3, 4]], True, 'Testing valid 9x9'), ([[1, 4, 2, 3], Contributor @sourcery-ai sourcery-ai bot 5 minutes ago issue (testing): Duplicated test cases Several test cases for valid 9x9 and 4x4 Sudokus, as well as some invalid cases, seem to be duplicated. This redundancy doesn't add value and can increase maintenance effort. Please remove the duplicates.
suggestion (testing): Add test cases with different capitalization and special characters Include test cases with a mix of uppercase and lowercase letters, as well as special characters within and around letters, to ensure correct handling of various input formats. Suggested implementation: @parameterized.expand([ ("", ""), ("123", ""), ("!@#$%^&*()", ""), ("a1!b", "1 2"), ("AbZ!", "1 2 26"), ("Hello World!", "8 5 12 12 15 23 15 18 12 4"), ("TeStInG 123", "20 5 19 20 9 14 7") ]) These changes ensure that test cases now include scenarios with mixed capitalization and special characters, as requested in the comment.
kyu_8/dalmatians_101_squash_bugs/README.md The asteval module allows you to evaluate a large subset of the Python language from within a python program, without using `eval()`. It is, in effect, a restricted version of Python’s built-in `eval()`, forbidding several actions, and using from within a python program, without using ` eval() `. It is, in effect, a restricted Contributor @sourcery-ai sourcery-ai bot 10 minutes ago nitpick (typo): Extra space around eval() There's an extra space before and after the backticks around 'eval()'. It should be eval(). Suggested implementation: without using `eval()` Python’s built-in `eval()`
@ikostan ikostan merged commit 17ac98e into kyu2 Feb 18, 2025
32 checks passed
ikostan added a commit that referenced this pull request Feb 18, 2025
Merge pull request #656 from iKostanOrg/master
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.