import pytest from working import convert def main(): test_missing_to() test_out_of_range_times() test_exception() test_hours_off_by_one() def test_missing_to(): try: convert('09:00 AM - 05:00 PM') except ValueError: pass else: raise ValueError("Missing to") try: convert('09:00 AM 05:00 PM') except Exception as e: assert isinstance(e, ValueError) def test_out_of_range_times(): try: convert('09:00 AM to 05:61 PM') except Exception as e: assert isinstance(e, ValueError) try: convert('31:00 AM to 05:00 PM') except Exception as e: assert isinstance(e, ValueError) try: convert('13:00 PM to 8:00 AM') except Exception as e: assert isinstance(e, ValueError) try: convert('13:00PM to 8:00 AM') except Exception as e: assert isinstance(e, ValueError) try: convert('13:00 to 8:00') except Exception as e: assert isinstance(e, ValueError) try: convert("09:00 AM - 17:00 PM") except Exception as e: assert isinstance(e, ValueError) try: convert("9:00 AM 5:00 PM") except Exception as e: assert isinstance(e, ValueError) try: convert("9:60 AM to 5:60 PM") except Exception as e: assert isinstance(e, ValueError) try: convert("9 AM - 5 PM") except Exception as e: assert isinstance(e, ValueError) try: convert("9 AM5 PM") except Exception as e: assert isinstance(e, ValueError) try: convert("9 AM 5 PM") except Exception as e: assert isinstance(e, ValueError) with pytest.raises(ValueError): convert("9:72 to 6:30") def test_exception(): with pytest.raises(ValueError): convert("09:00 AM - 17:00 PM") with pytest.raises(ValueError): convert("9:00 AM 5:00 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("9 AM5 PM") with pytest.raises(ValueError): convert("9 AM 5 PM") with pytest.raises(ValueError): convert("9:72 to 6:30") def test_hours_off_by_one(): assert convert('12:00 AM to 12:00 PM') == "00:00 to 12:00" assert convert("9 AM to 5 PM") == "09:00 to 17:00" assert convert("8 PM to 8 AM") == "20:00 to 08:00" assert convert("8:00 PM to 8:00 AM") == "20:00 to 08:00" assert convert("12 AM to 12 PM") == "00:00 to 12:00" assert convert("12:00 AM to 12:00 PM") == "00:00 to 12:00" if __name__ == '__main__': main()