GatorEducator / execexam

:rocket: ExecExam runs executable examinations that assess Python programming skills
https://pypi.org/project/execexam/
2 stars 3 forks source link

feat: Add Error Handling for Missing Internet Connection #21

Closed hemanialaparthi closed 1 month ago

hemanialaparthi commented 1 month ago
  1. Pull Request: Add Error Handling for Missing Internet Connection and ensure CodingMentor doesn't crash and give a long stacktrace.

  2. List the names of those who contributed to the project. @hemanialaparthi

  3. Link the issue the pull request is meant to fix/resolve. Closes #15

  4. Add all labels that apply. (e.g., documentation, ready-for-review) bug, enhancement

  5. Describe the contents and goal of the pull request. This PR adds a feature that improves how the program handles situations where there is no internet connection. Previously, the program would crash if the Litellm dependency couldn't connect to the internet. Now, the program checks for an internet connection before running. If no connection is found, the user receives a message asking them to check their network, preventing the program from crashing and making it more reliable in offline situations.

  6. Will coverage be maintained/increased? Yes, coverage will be increased for the advice module, as I have implemented new tests to ensure the new feature is fully tested.

  7. What operating systems has this been tested on? How were these tests conducted? The tests have been conducted on a Mac. It would be great if I could have a Linux and Windows user test it out.

  8. Include a code block and/or screenshots displaying the functionality of your feature, if applicable/possible.

When the coding mentor is run without internet this should be included in the output:

Error: Unable to connect to the API server.
Please check your network connection and ensure the API server is reachable.

If internet connection is present, the program will continue and no additional output is produced.

boulais01 commented 1 month ago

@hemanialaparthi I recommend soliciting tests from your peers via Discord! I do know at least that @PCain02 and @hannahb09 have been active in PRs and have the necessary OSes for testing, if they are available.

hemanialaparthi commented 1 month ago

@PCain02 the command to run the tests is pytest tests/test_advise.py.

PCain02 commented 1 month ago

@PCain02 the command to run the tests is pytest tests/test_advise.py.

Awesome! Which directory do I run it in ? image

hemanialaparthi commented 1 month ago

Hi @PCain02 ! I ran the command in the root directory of execexam

execexam-py3.12hemanialaparthi@Hemanis-MacBook-Air execexam % ls
README.md       config.yml      coverage.json   execexam        poetry.lock     pyproject.toml  pytest.ini      shell.nix       tests

This should be the output:

execexam-py3.12hemanialaparthi@Hemanis-MacBook-Air execexam % pytest tests/test_advise.py         
============================================================================ test session starts =============================================================================
platform darwin -- Python 3.12.5, pytest-8.3.3, pluggy-1.5.0
Using --randomly-seed=3550217582
rootdir: /Users/hemanialaparthi/Desktop/cmpsc203/enchancement/execexam
configfile: pytest.ini
plugins: json-report-1.5.0, metadata-3.1.1, randomly-3.15.0, anyio-4.6.0, cov-4.1.0, clarity-1.0.1, hypothesis-6.112.1
collected 3 items                                                                                                                                                            

tests/test_advise.py ...                                                                                                                                               [100%]

============================================================================= 3 passed in 0.35s ==============================================================================

NOTE: I'd also check if you're in the handle_internet_connection branch as the test cases are there!

hannahb09 commented 1 month ago

when I run the pytest test_advice.py I get this error Screenshot from 2024-09-25 22-43-15

hemanialaparthi commented 1 month ago

when I run the pytest test_advice.py I get this error Screenshot from 2024-09-25 22-43-15

This could happen because you haven’t poetry update. Could you try that please? Also try poetry run pytest tests/test_advise.py

PCain02 commented 1 month ago

Hi @PCain02 ! I ran the command in the root directory of execexam

execexam-py3.12hemanialaparthi@Hemanis-MacBook-Air execexam % ls
README.md       config.yml      coverage.json   execexam        poetry.lock     pyproject.toml  pytest.ini      shell.nix       tests

This should be the output:

execexam-py3.12hemanialaparthi@Hemanis-MacBook-Air execexam % pytest tests/test_advise.py         
============================================================================ test session starts =============================================================================
platform darwin -- Python 3.12.5, pytest-8.3.3, pluggy-1.5.0
Using --randomly-seed=3550217582
rootdir: /Users/hemanialaparthi/Desktop/cmpsc203/enchancement/execexam
configfile: pytest.ini
plugins: json-report-1.5.0, metadata-3.1.1, randomly-3.15.0, anyio-4.6.0, cov-4.1.0, clarity-1.0.1, hypothesis-6.112.1
collected 3 items                                                                                                                                                            

tests/test_advise.py ...                                                                                                                                               [100%]

============================================================================= 3 passed in 0.35s ==============================================================================

NOTE: I'd also check if you're in the handle_internet_connection branch as the test cases are there!

Okay thank you for the clarification. It still does not work with the commands provided and I double checked the branch and the directory.

Your branch is up to date with 'origin/handle_internet_connection'.
PS C:\Users\Palla\Documents\GitHub\execexam> ls

    Directory: C:\Users\Palla\Documents\GitHub\execexam

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----         9/20/2024  10:18 AM                .ruff_cache
d-----         9/18/2024   9:02 PM                dist
d-----         9/25/2024  11:22 AM                execexam
d-----         9/25/2024  10:45 PM                tests
-a----          9/5/2024   3:41 PM           4573 .gitignore
-a----          9/5/2024   3:41 PM            416 config.yml
-a----         9/17/2024   3:38 PM         304576 poetry.lock
-a----         9/20/2024  10:21 AM           3890 pyproject.toml
-a----          9/5/2024   3:41 PM            134 pytest.ini
-a----         9/25/2024  11:17 AM           2655 README.md
-a----          9/5/2024   3:41 PM            178 shell.nix

PS C:\Users\Palla\Documents\GitHub\execexam> pytest tests/test_advise.py
Fatal error in launcher: Expected to find a command ending in '.exe' in shebang line: python
PCain02 commented 1 month ago

Update I got a successful run on Windows with poetry run pytest tests/test_advise.py so I would add that to the documentation. But otherwise it works well ! I approve of this PR.

PS C:\Users\Palla\Documents\GitHub\execexam> poetry run pytest tests/test_advise.py
============================================================================================================ test session starts ============================================================================================================
platform win32 -- Python 3.12.1, pytest-8.3.2, pluggy-1.5.0
Using --randomly-seed=2760958284
rootdir: C:\Users\Palla\Documents\GitHub\execexam
configfile: pytest.ini
plugins: anyio-4.4.0, hypothesis-6.112.0, clarity-1.0.1, cov-4.1.0, json-report-1.5.0, metadata-3.1.1, randomly-3.15.0
collected 3 items

tests\test_advise.py ...                                                                                                                                                                                                               [100%] 

============================================================================================================= 3 passed in 4.81s =============================================================================================================
hannahb09 commented 1 month ago

The poetry run for pytest worked. I ran without wifi for the code and I get this Screenshot from 2024-09-25 23-23-32 no mention of please connect to the wifi

That's just the parameter information. What is the final output you are getting at the very end?

hannahb09 commented 1 month ago

I got it to work and this is what I got. I am running this on linux Screenshot from 2024-09-26 14-08-48

gkapfham commented 1 month ago

LGTM! Note: Windows has to run poetry run pytest tests/test_advise.py for the tests to work.

@PCain02 why do you have to run the test suite in this fashion on Windows? We should be able to run the standard poetry run task test command across all of the operating systems that we support. If that is not possible, please document why that is the case, okay?

rebekahrudd commented 1 month ago

I have run this code and it works on Linux

hemanialaparthi commented 1 month ago

LGTM! Note: Windows has to run poetry run pytest tests/test_advise.py for the tests to work.

@PCain02 why do you have to run the test suite in this fashion on Windows? We should be able to run the standard poetry run task test command across all of the operating systems that we support. If that is not possible, please document why that is the case, okay?

We tested the poetry run task test and poetry run pytest tests/test_advise.py on all Mac, Linux and Windows and it works.