Queer European MD passionate about IT

test_working.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import pytest
  2. from working import convert
  3. def main():
  4. test_missing_to()
  5. test_out_of_range_times()
  6. test_exception()
  7. test_hours_off_by_one()
  8. def test_missing_to():
  9. try:
  10. convert('09:00 AM - 05:00 PM')
  11. except ValueError:
  12. pass
  13. else:
  14. raise ValueError("Missing to")
  15. try:
  16. convert('09:00 AM 05:00 PM')
  17. except Exception as e:
  18. assert isinstance(e, ValueError)
  19. def test_out_of_range_times():
  20. try:
  21. convert('09:00 AM to 05:61 PM')
  22. except Exception as e:
  23. assert isinstance(e, ValueError)
  24. try:
  25. convert('31:00 AM to 05:00 PM')
  26. except Exception as e:
  27. assert isinstance(e, ValueError)
  28. try:
  29. convert('13:00 PM to 8:00 AM')
  30. except Exception as e:
  31. assert isinstance(e, ValueError)
  32. try:
  33. convert('13:00PM to 8:00 AM')
  34. except Exception as e:
  35. assert isinstance(e, ValueError)
  36. try:
  37. convert('13:00 to 8:00')
  38. except Exception as e:
  39. assert isinstance(e, ValueError)
  40. try:
  41. convert("09:00 AM - 17:00 PM")
  42. except Exception as e:
  43. assert isinstance(e, ValueError)
  44. try:
  45. convert("9:00 AM 5:00 PM")
  46. except Exception as e:
  47. assert isinstance(e, ValueError)
  48. try:
  49. convert("9:60 AM to 5:60 PM")
  50. except Exception as e:
  51. assert isinstance(e, ValueError)
  52. try:
  53. convert("9 AM - 5 PM")
  54. except Exception as e:
  55. assert isinstance(e, ValueError)
  56. try:
  57. convert("9 AM5 PM")
  58. except Exception as e:
  59. assert isinstance(e, ValueError)
  60. try:
  61. convert("9 AM 5 PM")
  62. except Exception as e:
  63. assert isinstance(e, ValueError)
  64. with pytest.raises(ValueError):
  65. convert("9:72 to 6:30")
  66. def test_exception():
  67. with pytest.raises(ValueError):
  68. convert("09:00 AM - 17:00 PM")
  69. with pytest.raises(ValueError):
  70. convert("9:00 AM 5:00 PM")
  71. with pytest.raises(ValueError):
  72. convert("9:60 AM to 5:60 PM")
  73. with pytest.raises(ValueError):
  74. convert("9 AM - 5 PM")
  75. with pytest.raises(ValueError):
  76. convert("9 AM5 PM")
  77. with pytest.raises(ValueError):
  78. convert("9 AM 5 PM")
  79. with pytest.raises(ValueError):
  80. convert("9:72 to 6:30")
  81. def test_hours_off_by_one():
  82. assert convert('12:00 AM to 12:00 PM') == "00:00 to 12:00"
  83. assert convert("9 AM to 5 PM") == "09:00 to 17:00"
  84. assert convert("8 PM to 8 AM") == "20:00 to 08:00"
  85. assert convert("8:00 PM to 8:00 AM") == "20:00 to 08:00"
  86. assert convert("12 AM to 12 PM") == "00:00 to 12:00"
  87. assert convert("12:00 AM to 12:00 PM") == "00:00 to 12:00"
  88. if __name__ == '__main__':
  89. main()