Код: Выделить всё
:) 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
:( test_working.py catches working.py printing incorrect hours
expected exit code 1, not 2
:( test_working.py catches working.py printing incorrect minutes
expected exit code 1, not 2
:( test_working.py catches working.py not raising ValueError when user omits " to "
expected exit code 1, not 2
:( test_working.py catches working.py not raising ValueError for out-of-range times
expected exit code 1, not 2
:( test_working.py catches working.py not raising ValueError for invalid time format
expected exit code 1, not 2
Код: Выделить всё
from working import convert
import pytest
def test_wrong_hour():
with pytest.raises(ValueError):
convert("13 AM to 5 PM")
def test_wrong_minute():
with pytest.raises(ValueError):
convert("12:60 AM to 5 PM")
def test_time():
assert convert("9 AM to 5 PM") == "09:00 to 17:00"
assert convert("9:30 AM to 5:45 PM") == "09:30 to 17:45"
def test_to():
with pytest.raises(ValueError):
convert("9 AM 5 PM")
def test_format():
with pytest.raises(ValueError):
convert("9 to 5")
with pytest.raises(ValueError):
convert("17:00 to 9 PM")
test_wrong_hour()
test_wrong_minute()
test_time()
test_to()
test_format()
Подробнее здесь: https://stackoverflow.com/questions/732 ... is-correct
Мобильная версия