Skip to content

Commit

Permalink
tests for case-insensitive am, pm, time and dmy
Browse files Browse the repository at this point in the history
  • Loading branch information
manoelrui authored and gunthercox committed May 13, 2018
1 parent dbcda9a commit 64762ba
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ def test_captured_pattern_is_next_three_weeks(self):
)
self.assertEqual(len(parser), 1)

def test_captured_pattern_is_next_x_weeks_case_insensitive(self):
input_text = 'next 2 Weeks'
parser = parsing.datetime_parsing(input_text)
self.assertIn(input_text, parser[0])
self.assertEqual(
parser[0][1].strftime('%d-%m-%Y'),
(datetime.today() + timedelta(weeks=2)).strftime('%d-%m-%Y')
)
self.assertEqual(len(parser), 1)

def test_captured_pattern_is_next_eight_days(self):
input_text = 'Next 8 days'
parser = parsing.datetime_parsing(input_text)
Expand All @@ -199,6 +209,16 @@ def test_captured_pattern_is_next_eight_days(self):
)
self.assertEqual(len(parser), 1)

def test_captured_pattern_is_next_x_days_case_insensitive(self):
input_text = 'next 14 Days'
parser = parsing.datetime_parsing(input_text)
self.assertIn(input_text, parser[0])
self.assertEqual(
parser[0][1].strftime('%d-%m-%Y'),
(datetime.today() + timedelta(days=14)).strftime('%d-%m-%Y')
)
self.assertEqual(len(parser), 1)

def test_captured_pattern_is_next_ten_years(self):
input_text = 'Next 10 years'
parser = parsing.datetime_parsing(input_text)
Expand All @@ -209,6 +229,16 @@ def test_captured_pattern_is_next_ten_years(self):
)
self.assertEqual(len(parser), 1)

def test_captured_pattern_is_next_x_years_case_insensitive(self):
input_text = 'next 43 Years'
parser = parsing.datetime_parsing(input_text)
self.assertIn('next 43 Year', parser[0])
self.assertEqual(
parser[0][1].strftime('%d-%m-%Y'),
(datetime.today() + timedelta(43 * 365)).strftime('%d-%m-%Y')
)
self.assertEqual(len(parser), 1)

def test_captured_pattern_is_next_eleven_months(self):
import calendar
input_text = 'Next 11 months'
Expand All @@ -224,6 +254,21 @@ def test_captured_pattern_is_next_eleven_months(self):
)
self.assertEqual(len(parser), 1)

def test_captured_pattern_is_next_x_months_case_insensitive(self):
import calendar
input_text = 'next 55 Months'
parser = parsing.datetime_parsing(input_text)
relative_date = datetime.today()
month = relative_date.month - 1 + 55
year = relative_date.year + month // 12
month = month % 12 + 1
day = min(relative_date.day, calendar.monthrange(year, month)[1])
self.assertIn('next 55 Month', parser[0])
self.assertEqual(
parser[0][1].strftime('%d-%m-%Y'), datetime(year, month, day).strftime('%d-%m-%Y')
)
self.assertEqual(len(parser), 1)

def test_captured_pattern_is_on_day(self):
input_text = 'My birthday is on January 2nd.'
parser = parsing.datetime_parsing(input_text)
Expand Down Expand Up @@ -254,6 +299,30 @@ def test_captured_pattern_has_am(self):
self.assertEqual(parser[0][1].strftime('%H'), '05')
self.assertEqual(len(parser), 1)

def test_captured_pattern_has_am_case_insensitive_1(self):
input_text = '7 AM'
parser = parsing.datetime_parsing(input_text)
self.assertIn('7 AM', parser[0])
self.assertEqual(parser[0][1].strftime('%d'), datetime.today().strftime('%d'))
self.assertEqual(parser[0][1].strftime('%H'), '07')
self.assertEqual(len(parser), 1)

def test_captured_pattern_has_am_case_insensitive_2(self):
input_text = '1 Am'
parser = parsing.datetime_parsing(input_text)
self.assertIn('1 Am', parser[0])
self.assertEqual(parser[0][1].strftime('%d'), datetime.today().strftime('%d'))
self.assertEqual(parser[0][1].strftime('%H'), '01')
self.assertEqual(len(parser), 1)

def test_captured_pattern_has_am_case_insensitive_3(self):
input_text = '9aM'
parser = parsing.datetime_parsing(input_text)
self.assertIn('9aM', parser[0])
self.assertEqual(parser[0][1].strftime('%d'), datetime.today().strftime('%d'))
self.assertEqual(parser[0][1].strftime('%H'), '09')
self.assertEqual(len(parser), 1)

def test_captured_pattern_has_pm(self):
input_text = 'Your dental appointment at 4 pm in the evening.'
parser = parsing.datetime_parsing(input_text)
Expand All @@ -262,6 +331,30 @@ def test_captured_pattern_has_pm(self):
self.assertEqual(parser[0][1].strftime('%H'), '16')
self.assertEqual(len(parser), 1)

def test_captured_pattern_has_pm_case_insensitive_1(self):
input_text = '8 PM'
parser = parsing.datetime_parsing(input_text)
self.assertIn('8 PM', parser[0])
self.assertEqual(parser[0][1].strftime('%d'), datetime.today().strftime('%d'))
self.assertEqual(parser[0][1].strftime('%H'), '20')
self.assertEqual(len(parser), 1)

def test_captured_pattern_has_pm_case_insensitive_2(self):
input_text = '11 pM'
parser = parsing.datetime_parsing(input_text)
self.assertIn('11 pM', parser[0])
self.assertEqual(parser[0][1].strftime('%d'), datetime.today().strftime('%d'))
self.assertEqual(parser[0][1].strftime('%H'), '23')
self.assertEqual(len(parser), 1)

def test_captured_pattern_has_pm_case_insensitive_3(self):
input_text = '3Pm'
parser = parsing.datetime_parsing(input_text)
self.assertIn('3Pm', parser[0])
self.assertEqual(parser[0][1].strftime('%d'), datetime.today().strftime('%d'))
self.assertEqual(parser[0][1].strftime('%H'), '15')
self.assertEqual(len(parser), 1)


class DateTimeParsingTestCases(TestCase):
"""
Expand Down

0 comments on commit 64762ba

Please sign in to comment.