def add_local_properties(self): client_context = self.create_client_context("console") client_context.brain.properties.add_property("name", "ProgramY") client_context.brain.properties.add_property("app_version", "1.0.0") client_context.brain.properties.add_property("grammar_version", "1.0.0") date_formatter = DateFormatter() client_context.brain.properties.add_property("birthdate", date_formatter.locate_appropriate_date_time())
def test_decimal_weekday(self): df = DateFormatter() self.assertIsNotNone(df) result = df.decimal_weekday() self.assertIsNotNone(result) self.assertRegex(result, r"\d{1}|\d{2}")
def test_hour_12_hour_clock(self): df = DateFormatter() self.assertIsNotNone(df) result = df.hour_12_hour_clock() self.assertIsNotNone(result) self.assertRegex(result, r"\d{1}|\d{2}")
def test_full_month(self): df = DateFormatter() self.assertIsNotNone(df) result = df.full_month() self.assertIsNotNone(result) self.assertRegex(result, r"[January|February|March|April|May|June|July|August|September|October|November|December]")
def test_full_weekday(self): df = DateFormatter() self.assertIsNotNone(df) result = df.full_weekday() self.assertIsNotNone(result) self.assertRegex(result, r"[Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday]")
def setUp(self): client = DateTimeAIMLTestClient() self._client_context = client.create_client_context("testid") self.date = DateFormatter()
def test_year_month_day_now(self): result = DateFormatter.year_month_day_now() self.assertIsNotNone(result) now = datetime.datetime.now() self.assertEqual(datetime.datetime(now.year, now.month, now.day, 0, 0), result)
def get_value(self, bot, clientid, value=None): formatter = DateFormatter() return formatter.time_representation()
def test_abbreviated_weekday(self): df = DateFormatter() self.assertIsNotNone(df) result = df.abbreviated_weekday() self.assertIsNotNone(result) self.assertRegex(result, r"[Mon|Tue|Wed|Thu|Fri|Sat|Sun]")
def test_tomorrow(self): response = DateTimeAIMLTests.test_client.bot.ask_question( "test", "TOMORROW") self.assertIsNotNone(response) self.date = DateFormatter(days=1) self.assertEqual(response, self.date.full_weekday())
def setUp(self): DateTimeAIMLTests.test_client = BasicTestClient() self.date = DateFormatter()
def test_decimal_minute(self): df = DateFormatter() self.assertIsNotNone(df) result = df.decimal_minute() self.assertIsNotNone(result) self.assertRegex(result, "\d{1}|\d{2}")
def test_time_representation(self): df = DateFormatter() self.assertIsNotNone(df) result = df.time_representation() self.assertIsNotNone(result) self.assertRegex(result, r"\d{2}:\d{2}:\d{2}")
def test_abbreviated_month(self): df = DateFormatter() self.assertIsNotNone(df) result = df.abbreviated_month() self.assertIsNotNone(result) self.assertRegex(result, r"[Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec]")
def test_timezone_name(self): df = DateFormatter() self.assertIsNotNone(df) result = df.timezone_name() self.assertIsNotNone(result) self.assertEqual("", result)
def test_tomorrow(self): response = DateTimeAIMLTests.test_client.bot.ask_question("test", "TOMORROW") self.assertIsNotNone(response) self.date = DateFormatter(days=1) self.assertEqual(response, self.date.full_weekday().upper())
def test_locate_appropriate_date_time(self): df = DateFormatter() self.assertIsNotNone(df) result = df.locate_appropriate_date_time() self.assertIsNotNone(result) self.assertRegex(result, TextUtilsTests.DEFAULT_DATETIME_REGEX)
def setUp(self): client = DateTimeAIMLTestClient() self._client_context = client.create_client_context("testid") self._client_context.brain.dynamics.add_dynamic_set('number', "programy.dynamic.sets.numeric.IsNumeric", None) self.date = DateFormatter()
def test_year_month_day(self): result = DateFormatter.year_month_day(2017, 7, 7) self.assertIsNotNone(result) self.assertEqual(datetime.datetime(2017, 7, 7, 0, 0), result)
def test_hour_12_hour_clock(self): df = DateFormatter() self.assertIsNotNone(df) result = df.hour_12_hour_clock() self.assertIsNotNone(result) self.assertRegex(result, "\d{1}|\d{2}")
def test_decimal_second(self): df = DateFormatter() self.assertIsNotNone(df) result = df.decimal_second() self.assertIsNotNone(result) self.assertRegex(result, r"\d{1}|\d{2}")
def test_decimal_week_number_monday_as_first(self): df = DateFormatter() self.assertIsNotNone(df) result = df.decimal_week_number_monday_as_first() self.assertIsNotNone(result) self.assertRegex(result, r"\d{1}|\d{2}")
def test_decimal_week_number_monday_as_first(self): df = DateFormatter() self.assertIsNotNone(df) result = df.decimal_week_number_monday_as_first() self.assertIsNotNone(result) self.assertRegex(result, "\d{1}|\d{2}")
def test_am_or_pm(self): df = DateFormatter() self.assertIsNotNone(df) result = df.am_or_pm() self.assertIsNotNone(result) self.assertRegex(r"[AM|PM]", result)
def test_decimal_weekday(self): df = DateFormatter() self.assertIsNotNone(df) result = df.decimal_weekday() self.assertIsNotNone(result) self.assertRegex(result, "\d{1}|\d{2}")
def test_year_4_digit(self): df = DateFormatter() self.assertIsNotNone(df) result = df.year_4_digit() self.assertIsNotNone(result) self.assertRegex(result, r"\d{4}")
def get_value(self, client_context, value=None): formatter = DateFormatter() return formatter.time_representation()
class DateTimeAIMLTests(unittest.TestCase): DEFAULT_DATETIME_REGEX = "^.*.{3}\s*.{3}\s*\d{1,}\s\d{2}:\d{2}:\d{2}\s\d{4}" def setUp(self): client = DateTimeAIMLTestClient() self._client_context = client.create_client_context("testid") self._client_context.brain.dynamics.add_dynamic_set('number', "programy.dynamic.sets.numeric.IsNumeric", None) self.date = DateFormatter() def test_season(self): response = self._client_context.bot.ask_question(self._client_context, "SEASON") self.assertIsNotNone(response) self.assertRegex(response, "[Winter|Spring|Summer|Autumn|Fall]") def test_day(self): response = self._client_context.bot.ask_question(self._client_context, "DAY") self.assertIsNotNone(response) self.assertEqual(response, "Today is %s"%(self.date.full_weekday())) def test_tomorrow(self): response = self._client_context.bot.ask_question(self._client_context, "TOMORROW") self.assertIsNotNone(response) self.date = DateFormatter(days=1) self.assertEqual(response, self.date.full_weekday()) def test_year(self): response = self._client_context.bot.ask_question(self._client_context, "YEAR") self.assertIsNotNone(response) self.assertEqual(response, "This is %s"%(self.date.year_4_digit())) response = self._client_context.bot.ask_question(self._client_context, "YEAR NEXT") self.assertIsNotNone(response) self.assertEqual(response, "This is %s"%(self.date.year_4_digit())) def test_next_year(self): next_year = (int(self.date.year_4_digit()))+1 response = self._client_context.bot.ask_question(self._client_context, "NEXT YEAR") self.assertIsNotNone(response) self.assertEqual(response, "%d"%(next_year)) response = self._client_context.bot.ask_question(self._client_context, "NEXT YEAR NEXT") self.assertIsNotNone(response) self.assertEqual(response, "%d"%(next_year)) def test_last_year(self): last_year = (int(self.date.year_4_digit()))-1 response = self._client_context.bot.ask_question(self._client_context, "LAST YEAR") self.assertIsNotNone(response) self.assertEqual(response, "%d"%(last_year)) response = self._client_context.bot.ask_question(self._client_context, "LAST YEAR AGO") self.assertIsNotNone(response) self.assertEqual(response, "%d"%(last_year)) def test_month(self): response = self._client_context.bot.ask_question(self._client_context, "MONTH") self.assertIsNotNone(response) self.assertEqual(response, "This is %s"%(self.date.full_month())) def test_time(self): response = self._client_context.bot.ask_question(self._client_context, "TIME") self.assertIsNotNone(response) hour = self.date.hour_12_hour_clock() min = self.date.decimal_minute() ampm = self.date.am_or_pm() self.assertRegex(response, "The time is %s:%s %s"%(hour, min, ampm)) def test_day_phase(self): response = self._client_context.bot.ask_question(self._client_context, "DAY PHASE") self.assertIsNotNone(response) self.assertRegex(response, "[Noon|Afternoon|Night]") def test_days_until_day(self): response = self._client_context.bot.ask_question(self._client_context, "DAYS UNTIL THURSDAY") self.assertIsNotNone(response) self.assertRegex(response, "\d{1}|\d{2}") def test_days_until_christmas(self): response = self._client_context.bot.ask_question(self._client_context, "DAYS UNTIL CHRISTMAS") self.assertIsNotNone(response) self.assertRegex(response, "\d{1}|\d{2}") def test_days_until_day_month_year(self): response = self._client_context.bot.ask_question(self._client_context, "DAYS UNTIL APRIL 01 2017") self.assertIsNotNone(response) self.assertRegex(response, "\d{1}|\d{2}") def test_days_until_month_year(self): response = self._client_context.bot.ask_question(self._client_context, "DAYS UNTIL APRIL 01") self.assertIsNotNone(response) self.assertRegex(response, "\d{1}|\d{2}") def test_date(self): response = self._client_context.bot.ask_question(self._client_context, "DATE") self.assertIsNotNone(response) self.assertRegex(response, "Today is .* \\d{2}, \\d{4}") def test_date_tomorrow(self): response = self._client_context.bot.ask_question(self._client_context, "DATE TOMORROW") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") def test_date_and_time(self): response = self._client_context.bot.ask_question(self._client_context, "DATE AND TIME") self.assertIsNotNone(response) self.assertRegex(response, "The date and time is .{3} .{3}\s*\\d{1}|\\d{2} \\d{2}:\\d{2}:\\d{2} \\d{4}") def test_tomorrowdate_month_day_year(self): response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE APRIL 01 2017") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") def test_tomorrowdate_month_end_carry_over(self): response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE JANUARY 31 2017") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE FEBRUARY 28 2012") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE FEBRUARY 28 2016") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE FEBRUARY 28 2020") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE FEBRUARY 28 2024") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE FEBRUARY 28 2028") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE FEBRUARY 28 2019") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE FEBRUARY 29 2020") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE MATCH 30 2020") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE APRIL 31 2020") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE MAY 31 2020") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE JUNE 30 2020") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE JULY 31 2020") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE AUGUST 31 2020") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE SEPTEMBER 30 2020") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE OCTOBER 31 2020") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE NOVEBER 30 2020") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") response = self._client_context.bot.ask_question(self._client_context, "TOMORROWDATE DECEMBER 31 2020") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") def test_date_in_one_days(self): response = self._client_context.bot.ask_question(self._client_context, "DATE IN 1 DAYS") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") def test_date_in_two_days(self): response = self._client_context.bot.ask_question(self._client_context, "DATE IN 2 DAYS") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") def test_date_in_ten_days(self): response = self._client_context.bot.ask_question(self._client_context, "DATE IN 10 DAYS") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") def test_day_after_tomorrow_date(self): response = self._client_context.bot.ask_question(self._client_context, "DAYAFTERTOMORROWDATE") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") def test_day_after_tomorrow_date_specific(self): response = self._client_context.bot.ask_question(self._client_context, "DAYAFTERTOMORROWDATE APRIL 01 2017") self.assertIsNotNone(response) self.assertRegex(response, ".* \\d{1}|\\d{2} \\d{4}") def test_day_after_tomorrow(self): response = self._client_context.bot.ask_question(self._client_context, "DAY AFTER TOMORROW") self.assertIsNotNone(response) self.assertRegex(response, ".*") def test_days_until_weekday(self): response = self._client_context.bot.ask_question(self._client_context, "DAYS UNTIL THURSDAY") self.assertIsNotNone(response) self.assertRegex(response, ".*") def test_date_on(self): response = self._client_context.bot.ask_question(self._client_context, "DATE ON THURSDAY") self.assertIsNotNone(response) self.assertRegex(response, ".*") def test_date_weekend(self): response = self._client_context.bot.ask_question(self._client_context, "DATE ON WEEKEND") self.assertIsNotNone(response) self.assertRegex(response, ".*") def test_weekday_in_five_days(self): response = self._client_context.bot.ask_question(self._client_context, "WEEKDAY IN 5 DAYS") self.assertIsNotNone(response) self.assertRegex(response, ".*") def test_date_a_week_from(self): response = self._client_context.bot.ask_question(self._client_context, "DATE A WEEK FROM THURSDAY") self.assertIsNotNone(response) self.assertRegex(response, ".*")
def test_tomorrow(self): response = self._client_context.bot.ask_question(self._client_context, "TOMORROW") self.assertIsNotNone(response) self.date = DateFormatter(days=1) self.assertEqual(response, self.date.full_weekday())
def setUp(self): DateTimeAIMLTests.test_client = BasicTestClient() DateTimeAIMLTests.test_client.bot.brain.dynamics.add_dynamic_set( 'number', "programy.dynamic.sets.numeric.IsNumeric", None) self.date = DateFormatter()