12months/tests.py

44 lines
1.4 KiB
Python

# SPDX-License-Identifier: CC0-1.0
import unittest
from month_num_convert import MonthNumConvert
class TestMonthNumConvert(unittest.TestCase):
def test_convert_number(self):
"https://example.com/1 -> January"
self.assertEqual(MonthNumConvert().convert("8"), "August")
def test_convert_name_lower_shortened(self):
"https://example.com/jan -> 1"
self.assertEqual(MonthNumConvert().convert("jan"), 1)
def test_convert_name_lower(self):
"https://example.com/january -> 1"
self.assertEqual(MonthNumConvert().convert("march"), 3)
def test_convert_name(self):
"https://example.com/January -> 1"
self.assertEqual(MonthNumConvert().convert("April"), 4)
def test_convert_name_shortened(self):
"https://example.com/Jan -> 1"
self.assertEqual(MonthNumConvert().convert("Oct"), 10)
def test_out_of_bounds_num(self):
"https://example.com/13 -> (Error 404)"
self.assertEqual(MonthNumConvert().convert("13"), None)
def test_consistency(self):
self.assertEqual(
MonthNumConvert().convert("November"), MonthNumConvert().convert("nov")
)
def test_invalid_string(self):
"https://example.com/audwhb -> (Error 404)"
self.assertEqual(MonthNumConvert().convert("audwhb"), None)
if __name__ == "__main__":
unittest.main()