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 19, 2025

Summary by Sourcery

Refactor test cases to use parameterized tests, optimize functions for performance, and enhance CI workflows with timeouts and consistent tool usage. Add new test cases for edge cases and utility functions, and clean up the codebase by removing unused code and adding necessary package files.

Enhancements:

  • Refactor test cases in multiple test files to use parameterized tests for better readability and maintainability.
  • Refactor the mix method in potion.py to separate RGB calculation into a new method for clarity.
  • Simplify the done_or_not function in is_sudoku_done.py by using line continuation for conditions.
  • Optimize the sol_equa function in solution.py by simplifying the calculation of the start variable.
  • Improve the is_prime function in primes.py by adding a check for already known primes to enhance performance.

CI:

  • Add timeout to CI workflows to prevent jobs from running indefinitely.
  • Update CI workflows to use python -m for running tools like flake8, mypy, and pydocstyle for consistency.
  • Add new CI workflows for testing and linting specific branches with pytest, flake8, pylint, and pytype.
  • Remove redundant post-coverage report step from the pytest workflow.

Tests:

  • Add new test cases for edge cases in test_replace_with_alphabet_position.py to ensure robustness.
  • Add a new test file test_log_func.py to test the print_log utility function.

Chores:

  • Remove unused code and comments from various files to clean up the codebase.
  • Add __init__.py files to utils and primes directories to make them Python packages.
ikostan and others added 30 commits February 1, 2025 23:03
Run flake8 --count --select=E9,F63,F7,F82 --doctests --show-source --statistics ./kyu_4 0 ./kyu_4/the_greatest_warrior/warrior.py:89:17: W503 line break before binary operator or self.experience + experience > MAX_EXPERIENCE): ^ ./kyu_4/validate_sudoku_with_size/sudoku.py:61:35: W504 line break after binary operator if (len(self.__data) == 1 and ^ 1 W503 line break before binary operator 1 W504 line break after binary operator 0.15 seconds elapsed
suggestion: Consider handling evaluation errors from asteval. Directly returning the result from asteval.eval(s) may propagate exceptions for invalid expressions. It might be worthwhile to catch errors and return an appropriate message or handle the exception in a controlled manner.
suggestion (testing): Test case for empty string is missing. Add a test case with an empty string ("") to verify the function handles it correctly and returns an empty string.
A backtick is missing before "eval()". It should be "eval()". Suggested implementation: from within a python program, without using `eval()` If there are similar occurrences of eval() in the file that aren't properly wrapped in backticks, consider updating them following the same pattern.
suggestion (code-quality): We've found these issues: Move setting of default value for variable into else branch (introduce-default-else) Replace if statement with if expression (assign-if-exp) Suggested change start = n // 2 if n % 2 != 0: start = n // 2 + 1 start = n // 2 + 1 if n % 2 != 0 else n // 2
Run flake8 --count --select=E9,F63,F7,F82 --doctests --show-source --statistics ./kyu_5 0 ./kyu_5/did_i_finish_my_sudoku/is_sudoku_done.py:27:13: W503 line break before binary operator and assert_sudoku_by_row(board) ^ ./kyu_5/did_i_finish_my_sudoku/is_sudoku_done.py:28:13: W503 line break before binary operator and assert_sudoku_by_region(board)): ^ 2 W503 line break before binary operator 0.395 seconds elapsed
./kyu_6/disease_spread/epidemic.py:48:33: W504 line break after binary operator susceptible[k] - dt * ^ ./kyu_6/disease_spread/epidemic.py:49:25: W504 line break after binary operator kwargs['b'] * ^ ./kyu_6/disease_spread/epidemic.py:50:28: W504 line break after binary operator susceptible[k] * ^ ./kyu_6/disease_spread/epidemic.py:54:31: W504 line break after binary operator infecteds[k] + dt * ^ ./kyu_6/disease_spread/epidemic.py:55:26: W504 line break after binary operator (kwargs['b'] * ^ ./kyu_6/disease_spread/epidemic.py:56:29: W504 line break after binary operator susceptible[k] * ^ ./kyu_6/disease_spread/epidemic.py:57:41: W504 line break after binary operator infecteds[k] - kwargs['a'] *
Run python -m flake8 ./kyu_6 --count --benchmark --show-source --statistics ./kyu_6/disease_spread/epidemic.py:48:17: E126 continuation line over-indented for hanging indent susceptible[k] - dt * kwargs['b'] * susceptible[k] * infecteds[k] ^ ./kyu_6/disease_spread/epidemic.py:53:17: E126 continuation line over-indented for hanging indent infecteds[k] + dt * ^ ./kyu_6/disease_spread/epidemic.py:53:35: W504 line break after binary operator infecteds[k] + dt * ^
Run python -m flake8 ./kyu_6 --count --benchmark --show-source --statistics ./kyu_6/disease_spread/epidemic.py:53:31: W504 line break after binary operator infecteds[k] + dt * ^
Run python -m flake8 ./kyu_6 --count --benchmark --show-source --statistics ./kyu_6/potion_class_101/potion.py:52:24: W503 line break before binary operator * self.volume) / (other.volume + self.volume)) ^ ./kyu_6/potion_class_101/potion.py:54:24: W503 line break before binary operator * self.volume) / (other.volume + self.volume)) ^ ./kyu_6/potion_class_101/potion.py:56:24: W503 line break before binary operator * self.volume) / (other.volume + self.volume)) ^ 3 W503 line break before binary operator 0.313 seconds elapsed
Run python -m flake8 ./kyu_6 --count --benchmark --show-source --statistics ./kyu_6/potion_class_101/potion.py:52:75: W504 line break after binary operator (other.color[0] * other.volume + self.color[0] * self.volume) / ^ ./kyu_6/potion_class_101/potion.py:56:75: W504 line break after binary operator (other.color[1] * other.volume + self.color[1] * self.volume) / ^ ./kyu_6/potion_class_101/potion.py:60:75: W504 line break after binary operator (other.color[2] * other.volume + self.color[2] * self.volume) / ^ 3 W504 line break after binary operator 0.319 seconds elapsed
Run python -m flake8 ./kyu_6 --count --benchmark --show-source --statistics ./kyu_6/potion_class_101/potion.py:10:1: F401 'typing.ClassVar' imported but unused from typing import Tuple, ClassVar ^ 1 F401 'typing.ClassVar' imported but unused 0.32 seconds elapsed
./kyu_6/potion_class_101/potion.py:63 in private method `__calc_rgb`: D205: 1 blank line required between summary line and description (found 0) Multi-line docstrings consist of a summary line just like a one-line docstring, followed by a blank line, followed by a more elaborate description. The summary line may be used by automatic indexing tools; it is important that it fits on one line and is separated from the rest of the docstring by a blank line.
ikostan and others added 18 commits February 16, 2025 17:25
Merge pull request #651 from iKostanOrg/utils
Merge pull request #653 from iKostanOrg/utils
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()`
Merge pull request #656 from iKostanOrg/master
@ikostan ikostan added the kyu_3 label Feb 19, 2025
@ikostan ikostan self-assigned this Feb 19, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 19, 2025

Reviewer's Guide by Sourcery

This pull request includes several enhancements and refactorings across multiple files. It focuses on improving test coverage by implementing parameterized tests, enhancing code readability through simplification of expressions and line continuations, and updating GitHub Actions workflows for better CI/CD practices. Additionally, it addresses performance concerns by adding a check for existing prime numbers in the is_prime function.

Sequence diagram for Potion mixing

sequenceDiagram participant Potion1 participant Potion2 Potion1->>Potion1: new_volume = self.volume + other.volume Potion1->>Potion1: __calc_rgb(other, new_volume) Potion1->>Potion1: r = math.ceil((other.color[0] * other.volume + self.color[0] * self.volume) / new_volume) Potion1->>Potion1: g = math.ceil((other.color[1] * other.volume + self.color[1] * self.volume) / new_volume) Potion1->>Potion1: b = math.ceil((other.color[2] * other.volume + self.color[2] * self.volume) / new_volume) Potion1->>Potion1: return r, g, b Potion1->>Potion1: return Potion((r, g, b), new_volume) 
Loading

Sequence diagram for Disease Spread calculation

sequenceDiagram participant Epidemic Epidemic->>Epidemic: for k in range(kwargs['n']) Epidemic->>Epidemic: calc_susceptible = susceptible[k] - dt * kwargs['b'] * susceptible[k] * infecteds[k] Epidemic->>Epidemic: susceptible.append(calc_susceptible) Epidemic->>Epidemic: calc_infecteds = infecteds[k] + dt * (kwargs['b'] * susceptible[k] * infecteds[k] - kwargs['a'] * infecteds[k]) Epidemic->>Epidemic: infecteds.append(calc_infecteds) Epidemic->>Epidemic: return int(max(infecteds)) 
Loading

File-Level Changes

Change Details Files
Refactored test cases to use parameterized tests for SudokuTestCase and CalcTestCase to improve readability and maintainability.
  • Replaced individual test methods with a single parameterized test method.
  • Added multiple test cases within the parameterized test.
  • Improved test coverage and clarity.
kyu_4/validate_sudoku_with_size/test_sudoku.py
kyu_2/evaluate_mathematical_expression/test_evaluate.py
Implemented parameterized tests for IsPrimeTestCase and added more test coverage.
  • Converted test_is_prime_positive and test_is_prime_negative to parameterized tests.
  • Expanded test data to include a wider range of prime and non-prime numbers.
  • Improved test coverage and reduced code duplication.
utils/primes/test_is_prime.py
utils/primes/test_primes_generator.py
Added edge case tests for the alphabet_position function.
  • Created a new test method test_alphabet_position_edge_cases.
  • Included test cases for empty strings, numbers, special characters, and mixed alphanumeric input.
  • Improved the robustness of the test suite.
kyu_6/replace_with_alphabet_position/test_replace_with_alphabet_position.py
Improved the mix method in the Potion class to correctly calculate RGB values and added type hinting.
  • Added type hinting to the mix method and color property.
  • Created a private method __calc_rgb to encapsulate RGB calculation logic.
  • Ensured correct RGB value calculation using ceiling and integer division.
kyu_6/potion_class_101/potion.py
Refactored the epidemic function for better readability.
  • Calculations for susceptible and infected individuals are now stored in temporary variables before being appended to their respective lists.
  • This change improves the readability of the code by breaking down the complex calculations into smaller, more manageable steps.
kyu_6/disease_spread/epidemic.py
Updated GitHub Actions workflows to use Python 3.11 and 3.12, added timeout-minutes, and improved linting and testing configurations.
  • Updated Python versions in GitHub Actions workflows.
  • Added timeout-minutes to prevent jobs from running indefinitely.
  • Improved linting and testing configurations for flake8, mypy, pydocstyle, pylint, and pytest.
  • Added codacy coverage reporter.
.github/workflows/flake8_kyu7.yml
.github/workflows/mypy_kyu4.yml
.github/workflows/mypy_kyu5.yml
.github/workflows/mypy_kyu7.yml
.github/workflows/flake8_kyu8.yml
.github/workflows/pydocstyle_kyu5.yml
.github/workflows/pydocstyle_kyu7.yml
.github/workflows/pylint_kyu7.yml
.github/workflows/pytest_kyu6.yml
.github/workflows/pydocstyle_kyu4.yml
.github/workflows/pylint_kyu4.yml
.github/workflows/flake8_kyu4.yml
.github/workflows/flake8_kyu5.yml
.github/workflows/pylint_kyu5.yml
.github/workflows/lint_test_build_pipeline.yml
.github/workflows/flake8_kyu6.yml
.github/workflows/pytype_kyu7.yml
.github/workflows/pytype_kyu8.yml
Refactored the calculate function in basic_math_add_or_subtract to directly return the evaluated result.
  • Removed unnecessary variable assignment and directly returned the result of aeval.eval(s).
  • This simplifies the code and makes it more readable.
kyu_7/basic_math_add_or_subtract/calculate.py
Simplified the calc_combination_per_row_item function in easy_line by removing unnecessary type conversions.
  • Removed int() type conversions from the factorial calculations.
  • This makes the code more concise and readable without affecting its functionality.
kyu_7/easy_line/easyline.py
Improved the done_or_not function in is_sudoku_done by using implicit line continuation.
  • Replaced explicit line continuation with implicit line continuation within the if statement.
  • This improves the readability of the code by reducing visual clutter.
kyu_5/did_i_finish_my_sudoku/is_sudoku_done.py
Simplified the sol_equa function in solution.py by using a conditional expression for the start value.
  • Replaced the if statement with a conditional expression to determine the start value for the x loop.
  • This makes the code more concise and readable.
kyu_5/diophantine_equation/solution.py
Added a check for existing prime numbers in the is_prime function to improve performance.
  • Added a check to see if the digit is already in the primes list.
  • If the digit is in the primes list, return True.
kyu_5/master_your_primes_sieve_with_memoization/primes.py
Added documentation to utils and primes packages.
  • Added init.py files to utils and primes packages.
  • Added docstrings to init.py files.
utils/__init__.py
utils/primes/__init__.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

@codacy-production
Copy link

codacy-production bot commented Feb 19, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for b2c8b271 95.45%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (b2c8b27) Report Missing Report Missing Report Missing
Head commit (7e6a7a4) 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 (#658) 22 21 95.45%

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.

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:

  • Consider adding type hints to the __calc_rgb method in kyu_6/potion_class_101/potion.py for better readability.
  • The parameterized tests are a great addition, but consider adding a test case with a larger Sudoku grid to kyu_4/validate_sudoku_with_size/test_sudoku.py.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 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.
@qltysh
Copy link

qltysh bot commented Feb 19, 2025

❌ 45 blocking issues (48 total)

Tool Category Rule Count
prettier Style Incorrect formatting, autoformat by running `qlty fmt`. 45
qlty Structure Function with high complexity (count = 8): sol_equa 2
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.
suggestion (testing): Test cases for invalid sizes are missing. It would be beneficial to add tests for invalid sizes like rectangular or non-square matrices, such as 2x3 or 3x4. This would ensure more comprehensive test coverage. Depending on where you insert these changes in your parameterized test list (e.g., near the top or in the middle), ensure that the commas and brackets match the existing code structure.
@ikostan ikostan merged commit 8882279 into kyu3 Feb 19, 2025
32 checks passed
ikostan added a commit that referenced this pull request Feb 21, 2025
Merge pull request #658 from iKostanOrg/master
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

2 participants