This is CS50XPython - Working 9 to 5 (pset7) - Running the test in the IDE works correctly. Looking up exit code 2, it states the program was interrupted by the user (check50?)
I have verified all my tests work, the code works, the import statements are correct, but I cannot get check50 to get past this error.
The results of running "pytest test_working.py" are below. As shown by the 5 dots, all tests passed.
test_working.py .....
Check50's output is...
Results for cs50/problems/2022/python/working generated by check50 v3.3.7
:) working.py and test_working.py exist
:) working.py does not import libraries other than sys and re
:) working.py converts "9 AM to 5 PM" to "09:00 to 17:00"
:) working.py converts "9:00 AM to 5:00 PM" to "09:00 to 17:00"
:) working.py converts "8 PM to 8 AM" to "20:00 to 08:00"
:) working.py converts "8:00 PM to 8:00 AM" to "20:00 to 08:00"
:) working.py converts "12 AM to 12 PM" to "00:00 to 12:00"
:) working.py converts "12:00 AM to 12:00 PM" to "00:00 to 12:00"
:) working.py raises ValueError when given "8:60 AM to 4:60 PM"
:) working.py raises ValueError when given "9AM to 5PM"
:) working.py raises ValueError when given "09:00 to 17:00"
:) working.py raises ValueError when given "9 AM - 5 PM"
:) working.py raises ValueError when given "10:7 AM - 5:1 PM"
:( correct working.py passes all test_working checks
expected exit code 0, not 2
My test_working.py code is...
from working import convert, convert_minutes, convert_to_twenty_four_hour
import pytest
def test_invalid_format():
with pytest.raises(ValueError):
convert("9AM5PM")
with pytest.raises(ValueError):
convert("9AM 5PM")
with pytest.raises(ValueError):
convert("9 AM 5 PM")
with pytest.raises(ValueError):
convert("9 AM - 5 PM")
def test_invalid_hours():
with pytest.raises(ValueError):
convert("15 AM to 3 PM")
with pytest.raises(ValueError):
convert("9 AM to 5 pm")
with pytest.raises(ValueError):
convert("9 am to 5 pm")
with pytest.raises(ValueError):
convert("9 to 5")
with pytest.raises(ValueError):
convert("9 AM 5 PM")
def test_minutes():
assert convert_minutes(0) == 0
assert convert_minutes(3) == 3
assert convert_minutes(59) == 59
def test_invalid_minutes():
assert convert_minutes(None) == 0
with pytest.raises(ValueError):
convert_minutes(60)
with pytest.raises(ValueError):
convert_minutes(85)
with pytest.raises(ValueError):
convert_minutes(-1)
def test_twenty_four_hour():
assert convert_to_twenty_four_hour(5, "PM") == 17
assert convert_to_twenty_four_hour(12, "AM") == 0
assert convert_to_twenty_four_hour(12, "PM") != 15
def test_valid_times():
assert convert("10:30 PM to 8:50 AM") == "22:30 to 08:50"