eranheres / cli_snake_game_self

0 stars 0 forks source link

Sweep: write unit testing for snake.py #28

Closed eranheres closed 11 months ago

eranheres commented 11 months ago

Details

No response

Checklist - [X] Create `tests/test_snake.py` ✓ https://github.com/eranheres/cli_snake_game_self/commit/5a9d8a3e3bd747ad727d6ee904fdfb85149ea0e8 - [X] Check `tests/test_snake.py` ✗ - [X] Modify `tests/test_snake.py` ✓ https://github.com/eranheres/cli_snake_game_self/commit/aaa1dfd94c1ff31acae874c1627073a8e7bbbc4f - [X] Check `tests/test_snake.py` ✓ https://github.com/eranheres/cli_snake_game_self/commit/6d60eeb81360f034a2758623eda22348af98a1db - [X] Check `tests/test_snake.py` ✓ ![Flowchart](https://raw.githubusercontent.com/eranheres/cli_snake_game_self/sweep/assets/50f00cf33f413efa80ca6514a288aaec215c8515f7ad815fe82455509406521d_28_flowchart.svg)
sweep-mine[bot] commented 11 months ago

Here's the PR! https://github.com/eranheres/cli_snake_game_self/pull/37.

💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets.

Actions (click)

Sandbox Execution ✓

Here are the sandbox execution logs prior to making any changes:

Sandbox logs for 0fac756
trunk init 1/5 ✓
⡿ Downloading Trunk 1.17.2...
⡿ Downloading Trunk 1.17.2...
⢿ Downloading Trunk 1.17.2...
⣻ Downloading Trunk 1.17.2...
⣽ Downloading Trunk 1.17.2...
⣾ Downloading Trunk 1.17.2...
⣷ Downloading Trunk 1.17.2...
⣯ Downloading Trunk 1.17.2...
✔ Downloading Trunk 1.17.2... done
⡿ Verifying Trunk sha256...
✔ Verifying Trunk sha256... done
⡿ Unpacking Trunk...
✔ Unpacking Trunk... done

✔ 17 linters were enabled (.trunk/trunk.yaml)
  actionlint 1.6.26 (1 github-workflow file)
  bandit 1.7.5 (8 python files)
  black 23.9.1 (6 python files)
  checkov 3.0.34 (3 yaml files)
  git-diff-check (36 files)
  isort 5.12.0 (8 python files) (created .isort.cfg)
  markdownlint 0.37.0 (4 markdown files) (created .markdownlint.yaml)
  osv-scanner 1.4.3 (1 lockfile file)
  oxipng 9.0.0 (3 png files)
  prettier 3.1.0 (4 markdown, 3 yaml files)
  ruff 0.1.5 (8 python files) (created ruff.toml)
  shellcheck 0.9.0 (1 shell file) (created .shellcheckrc)
  shfmt 3.6.0 (1 shell file)
  svgo 3.0.3 (3 svg files) (created svgo.config.js)
  trivy 0.47.0 (3 yaml files)
  trufflehog 3.62.1 (36 files)
  yamllint 1.33.0 (3 yaml files) (created .yamllint.yaml)
Next Steps
 1. Read documentation
    Our documentation can be found at https://docs.trunk.io
 2. Get help and give feedback
    Join the Trunk community at https://slack.trunk.io
pip install -r requirements.txt 2/5 ✓
Collecting arrow==1.3.0
  Downloading arrow-1.3.0-py3-none-any.whl (66 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 66.4/66.4 KB 1.8 MB/s eta 0:00:00
Collecting iniconfig==2.0.0
  Downloading iniconfig-2.0.0-py3-none-any.whl (5.9 kB)
Collecting packaging==23.2
  Downloading packaging-23.2-py3-none-any.whl (53 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 53.0/53.0 KB 3.2 MB/s eta 0:00:00
Collecting pluggy==1.3.0
  Downloading pluggy-1.3.0-py3-none-any.whl (18 kB)
Collecting pygame==2.5.2
  Downloading pygame-2.5.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.0/14.0 MB 28.4 MB/s eta 0:00:00
Collecting pytest==7.4.3
  Downloading pytest-7.4.3-py3-none-any.whl (325 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 325.1/325.1 KB 28.6 MB/s eta 0:00:00
Collecting python-dateutil==2.8.2
  Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 247.7/247.7 KB 28.4 MB/s eta 0:00:00
Collecting python-time==0.3.0
  Downloading python-time-0.3.0.tar.gz (2.6 kB)
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Collecting six==1.16.0
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting types-python-dateutil==2.8.19.14
  Downloading types_python_dateutil-2.8.19.14-py3-none-any.whl (9.4 kB)
Collecting exceptiongroup>=1.0.0rc8
  Downloading exceptiongroup-1.1.3-py3-none-any.whl (14 kB)
Requirement already satisfied: tomli>=1.0.0 in /usr/local/lib/python3.10/dist-packages (from pytest==7.4.3->-r requirements.txt (line 6)) (2.0.1)
Building wheels for collected packages: python-time
  Building wheel for python-time (setup.py): started
  Building wheel for python-time (setup.py): finished with status 'done'
  Created wheel for python-time: filename=python_time-0.3.0-py3-none-any.whl size=2778 sha256=a712e8c3873a64535dae7881795adb2fb827f199ec609f3c7a26589ff0a96c1b
  Stored in directory: /root/.cache/pip/wheels/85/52/46/37a3e8822ab091294b0335e12ebe76e04d19f07be1bd519918
Successfully built python-time
Installing collected packages: types-python-dateutil, six, pygame, pluggy, packaging, iniconfig, exceptiongroup, python-dateutil, pytest, arrow, python-time
  Attempting uninstall: packaging
    Found existing installation: packaging 23.1
    Uninstalling packaging-23.1:
      Successfully uninstalled packaging-23.1
Successfully installed arrow-1.3.0 exceptiongroup-1.1.3 iniconfig-2.0.0 packaging-23.2 pluggy-1.3.0 pygame-2.5.2 pytest-7.4.3 python-dateutil-2.8.2 python-time-0.3.0 six-1.16.0 types-python-dateutil-2.8.19.14
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
trunk fmt tests/test_snake.py || return 0 3/5 ✓
  NOTICES  
 tests/test_snake.py  ignored empty file [black]
 Hint: use --force to check ignored files
Checked 1 file
✔ No issues
trunk check --fix --print-failures tests/test_snake.py 4/5 ✓
  NOTICES  
 tests/test_snake.py  ignored empty file [black]
 Hint: use --force to check ignored files
Checked 1 file
✔ No issues
pytest 5/5 ✓
============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-7.4.3, pluggy-1.3.0
rootdir: /repo
collected 4 items
tests/test_empty.py .                                                    [ 25%]
tests/test_food.py ...                                                   [100%]
============================== 4 passed in 0.03s ===============================

Sandbox passed on the latest main, so sandbox checks will be enabled for this issue.


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/eranheres/cli_snake_game_self/blob/0fac7569dc3ad528899399a96d2c625224d66201/cli_snake_game/snake.py#L1-L32 https://github.com/eranheres/cli_snake_game_self/blob/0fac7569dc3ad528899399a96d2c625224d66201/README.md#L1-L1

Step 2: ⌨️ Coding

trunk fmt tests/test_snake.py || return 0 1/15 ✓
 ✔ Formatted tests/test_snake.py
Re-checking autofixed files...

 ✔ Formatted tests/test_snake.py
Re-checking autofixed files...

Checked 1 file
✔ No issues
trunk check --fix --print-failures tests/test_snake.py 2/15 ✓
Checked 1 file
✔ No issues
pytest 3/15 ❌ (`1`)
============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-7.4.3, pluggy-1.3.0
rootdir: /repo
collected 10 items
tests/test_empty.py .                                                    [ 10%]
tests/test_food.py ...                                                   [ 40%]
tests/test_snake.py ..F...                                               [100%]
=================================== FAILURES ===================================
_____________________________ TestSnake.test_init ______________________________
self = 
    def test_init(self):
        snake = Snake()
>       self.assertEqual(snake.body, [(40, 40), (30, 40), (20, 40)])
E       AssertionError: Lists differ: [(40, 40), (30, 40), (20, 40), (20, 40)] != [(40, 40), (30, 40), (20, 40)]
E       
E       First list contains 1 additional elements.
E       First extra element 3:
E       (20, 40)
E       
E       - [(40, 40), (30, 40), (20, 40), (20, 40)]
E       ?                           ----------
E       
E       + [(40, 40), (30, 40), (20, 40)]
tests/test_snake.py:9: AssertionError
=========================== short test summary info ============================
FAILED tests/test_snake.py::TestSnake::test_init - AssertionError: Lists diff...
========================= 1 failed, 9 passed in 0.11s ==========================
trunk fmt tests/test_snake.py || return 0 4/15 ✓
 ✔ Formatted tests/test_snake.py
Re-checking autofixed files...

 ✔ Formatted tests/test_snake.py
Re-checking autofixed files...

Checked 1 file
✔ No issues
trunk check --fix --print-failures tests/test_snake.py 5/15 ✓
Checked 1 file
✔ No issues
pytest 6/15 ❌ (`1`)
============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-7.4.3, pluggy-1.3.0
rootdir: /repo
collected 10 items
tests/test_empty.py .                                                    [ 10%]
tests/test_food.py ...                                                   [ 40%]
tests/test_snake.py ..F...                                               [100%]
=================================== FAILURES ===================================
_____________________________ TestSnake.test_init ______________________________
self = 
    def test_init(self):
        snake = Snake()
>       self.assertEqual(snake.body, [(40, 40), (30, 40), (20, 40)])
E       AssertionError: Lists differ: [(40, 40), (30, 40), (20, 40), (20, 40)] != [(40, 40), (30, 40), (20, 40)]
E       
E       First list contains 1 additional elements.
E       First extra element 3:
E       (20, 40)
E       
E       - [(40, 40), (30, 40), (20, 40), (20, 40)]
E       ?                           ----------
E       
E       + [(40, 40), (30, 40), (20, 40)]
tests/test_snake.py:9: AssertionError
=========================== short test summary info ============================
FAILED tests/test_snake.py::TestSnake::test_init - AssertionError: Lists diff...
========================= 1 failed, 9 passed in 0.10s ==========================
trunk fmt tests/test_snake.py || return 0 7/15 ✓
 ✔ Formatted tests/test_snake.py
Re-checking autofixed files...

 ✔ Formatted tests/test_snake.py
Re-checking autofixed files...

Checked 1 file
✔ No issues
trunk check --fix --print-failures tests/test_snake.py 8/15 ✓
Checked 1 file
✔ No issues
pytest 9/15 ❌ (`1`)
============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-7.4.3, pluggy-1.3.0
rootdir: /repo
collected 10 items
tests/test_empty.py .                                                    [ 10%]
tests/test_food.py ...                                                   [ 40%]
tests/test_snake.py ..F...                                               [100%]
=================================== FAILURES ===================================
_____________________________ TestSnake.test_init ______________________________
self = 
    def test_init(self):
        snake = Snake()
>       self.assertEqual(snake.body, [(40, 40), (30, 40), (20, 40)])
E       AssertionError: Lists differ: [(40, 40), (30, 40), (20, 40), (20, 40)] != [(40, 40), (30, 40), (20, 40)]
E       
E       First list contains 1 additional elements.
E       First extra element 3:
E       (20, 40)
E       
E       - [(40, 40), (30, 40), (20, 40), (20, 40)]
E       ?                           ----------
E       
E       + [(40, 40), (30, 40), (20, 40)]
tests/test_snake.py:9: AssertionError
=========================== short test summary info ============================
FAILED tests/test_snake.py::TestSnake::test_init - AssertionError: Lists diff...
========================= 1 failed, 9 passed in 0.07s ==========================
trunk fmt tests/test_snake.py || return 0 10/15 ✓
 ✔ Formatted tests/test_snake.py
Re-checking autofixed files...

 ✔ Formatted tests/test_snake.py
Re-checking autofixed files...

Checked 1 file
✔ No issues
trunk check --fix --print-failures tests/test_snake.py 11/15 ✓
Checked 1 file
✔ No issues
pytest 12/15 ❌ (`1`)
============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-7.4.3, pluggy-1.3.0
rootdir: /repo
collected 10 items
tests/test_empty.py .                                                    [ 10%]
tests/test_food.py ...                                                   [ 40%]
tests/test_snake.py ..F...                                               [100%]
=================================== FAILURES ===================================
_____________________________ TestSnake.test_init ______________________________
self = 
    def test_init(self):
        snake = Snake()
>       self.assertEqual(snake.body, [(40, 40), (30, 40), (20, 40)])
E       AssertionError: Lists differ: [(40, 40), (30, 40), (20, 40), (20, 40)] != [(40, 40), (30, 40), (20, 40)]
E       
E       First list contains 1 additional elements.
E       First extra element 3:
E       (20, 40)
E       
E       - [(40, 40), (30, 40), (20, 40), (20, 40)]
E       ?                           ----------
E       
E       + [(40, 40), (30, 40), (20, 40)]
tests/test_snake.py:9: AssertionError
=========================== short test summary info ============================
FAILED tests/test_snake.py::TestSnake::test_init - AssertionError: Lists diff...
========================= 1 failed, 9 passed in 0.07s ==========================
trunk fmt tests/test_snake.py || return 0 13/15 ✓
 ✔ Formatted tests/test_snake.py
Re-checking autofixed files...

 ✔ Formatted tests/test_snake.py
Re-checking autofixed files...

Checked 1 file
✔ No issues
trunk check --fix --print-failures tests/test_snake.py 14/15 ✓
Checked 1 file
✔ No issues
pytest 15/15 ❌ (`1`)
============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-7.4.3, pluggy-1.3.0
rootdir: /repo
collected 10 items
tests/test_empty.py .                                                    [ 10%]
tests/test_food.py ...                                                   [ 40%]
tests/test_snake.py ..F...                                               [100%]
=================================== FAILURES ===================================
_____________________________ TestSnake.test_init ______________________________
self = 
    def test_init(self):
        snake = Snake()
>       self.assertEqual(snake.body, [(40, 40), (30, 40), (20, 40)])
E       AssertionError: Lists differ: [(40, 40), (30, 40), (20, 40), (20, 40)] != [(40, 40), (30, 40), (20, 40)]
E       
E       First list contains 1 additional elements.
E       First extra element 3:
E       (20, 40)
E       
E       - [(40, 40), (30, 40), (20, 40), (20, 40)]
E       ?                           ----------
E       
E       + [(40, 40), (30, 40), (20, 40)]
tests/test_snake.py:9: AssertionError
=========================== short test summary info ============================
FAILED tests/test_snake.py::TestSnake::test_init - AssertionError: Lists diff...
========================= 1 failed, 9 passed in 0.07s ==========================

trunk fmt tests/test_snake.py || return 0 1/3 ✓
 ✔ Formatted tests/test_snake.py
Re-checking autofixed files...

 ✔ Formatted tests/test_snake.py
Re-checking autofixed files...

Checked 1 file
✔ No issues
trunk check --fix --print-failures tests/test_snake.py 2/3 ✓
Checked 1 file
✔ No issues
pytest 3/3 ✓
============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-7.4.3, pluggy-1.3.0
rootdir: /repo
collected 10 items
tests/test_empty.py .                                                    [ 10%]
tests/test_food.py ...                                                   [ 40%]
tests/test_snake.py ......                                               [100%]
============================== 10 passed in 0.06s ==============================

trunk fmt tests/test_snake.py || return 0 1/3 ✓
Checked 1 file
✔ No issues
trunk check --fix --print-failures tests/test_snake.py 2/3 ✓
Checked 1 file
✔ No issues
pytest 3/3 ✓
============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-7.4.3, pluggy-1.3.0
rootdir: /repo
collected 10 items
tests/test_empty.py .                                                    [ 10%]
tests/test_food.py ...                                                   [ 40%]
tests/test_snake.py ......                                               [100%]
============================== 10 passed in 0.07s ==============================


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/add-unit-tests-snake.


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord