-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_working.py
31 lines (31 loc) · 2.01 KB
/
test_working.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from working import convert
import pytest
#from working import convert: This line imports a function named convert from a module named working. We don't have the code for the convert function, but we can assume it's defined in a separate file named working.py.
#import pytest: Imports the pytest library, which is used for writing and running tests.
#def main():: Defines a main function that calls two other functions, test1 and test2.
def main():
test1()
test2()
#def test1():: Defines a test function named test1.
#assert convert("9 AM to 5 PM") == "09:00 to 17:00": This line asserts that the convert function, when given the input "9 AM to 5 PM", returns the string "09:00 to 17:00". If the returned value is different, a test failure occurs.
#The following three lines perform similar assertions for different input-output pairs.
def test1():
assert convert("9 AM to 5 PM") == "09:00 to 17:00"
assert convert("9:00 AM to 5:00 PM") == "09:00 to 17:00"
assert convert("10 PM to 8 AM") == "22:00 to 08:00"
assert convert("10:30 PM to 8:50 AM") == "22:30 to 08:50"
#def test2():: Defines a test function named test2.
#with pytest.raises(ValueError):: This line starts a context where a ValueError is expected to be raised.
#convert("9:60 AM to 5:60 PM"): Calls the convert function with an invalid input.
#If the convert function raises a ValueError, the test passes. Otherwise, it fails.
#The following three lines perform similar assertions for different invalid inputs.
def test2():
with pytest.raises(ValueError):
convert("9:60 AM to 5:60 PM")
with pytest.raises(ValueError):
convert("9:60 AM to 5:60 PM")
with pytest.raises(ValueError):
convert("9 AM - 5 PM")
with pytest.raises(ValueError):
convert("09:00 AM - 17:00 PM")
#The code defines two test functions to verify the behavior of the convert function. test1 checks if the function correctly converts 12-hour time formats to 24-hour formats. test2 ensures that the function raises a ValueError for invalid input formats.