From bf25d87a73641ad7d4e60c8ef3ce05c97ab83c19 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Fri, 23 Jun 2023 15:47:20 -0700 Subject: [PATCH 1/3] Implement date format intent that matches time format intent with updated tests --- __init__.py | 25 ++++++++++++ .../dialog/date_format_already_set.dialog | 1 + .../en-us/dialog/date_format_changed.dialog | 1 + locale/en-us/vocab/DMY.voc | 1 + locale/en-us/vocab/MDY.voc | 1 + locale/en-us/vocab/YMD.voc | 1 + locale/en-us/vocab/date.voc | 1 + test/test_resources.yaml | 6 +++ test/test_skill.py | 38 +++++++++++++++++++ 9 files changed, 75 insertions(+) create mode 100644 locale/en-us/dialog/date_format_already_set.dialog create mode 100644 locale/en-us/dialog/date_format_changed.dialog create mode 100644 locale/en-us/vocab/DMY.voc create mode 100644 locale/en-us/vocab/MDY.voc create mode 100644 locale/en-us/vocab/YMD.voc create mode 100644 locale/en-us/vocab/date.voc diff --git a/__init__.py b/__init__.py index 001e5c9..2111362 100644 --- a/__init__.py +++ b/__init__.py @@ -197,6 +197,31 @@ def handle_time_format_change(self, message: Message): self.speak_dialog("time_format_changed", {"scale": str(new_setting)}, private=True) + @intent_handler(IntentBuilder("ChangeDate").require("change") + .require("date").one_of("MDY", "DMY", "YMD").build()) + def handle_date_format_change(self, message: Message): + """ + Handle a request to set date format to DMY, MDY, or YMD format + :param message: Message associated with request + """ + new_setting = "YMD" if message.data.get("YMD") else \ + "MDY" if message.data.get("MDY") else \ + "DMY" if message.data.get("DMY") else None + if not new_setting: + raise RuntimeError("Missing required date format vocab") + + current_setting = get_user_prefs(message)["units"]["date"] + if new_setting == current_setting: + self.speak_dialog("date_format_already_set", + {"format": message.data.get(new_setting)}, + private=True) + else: + updated_prefs = {"units": {"date": new_setting}} + self.update_profile(updated_prefs, message) + self.speak_dialog("date_format_changed", + {"format": message.data.get(new_setting)}, + private=True) + @intent_handler(IntentBuilder("SetHesitation").one_of("permit", "deny") .require("hesitation").build()) def handle_speak_hesitation(self, message: Message): diff --git a/locale/en-us/dialog/date_format_already_set.dialog b/locale/en-us/dialog/date_format_already_set.dialog new file mode 100644 index 0000000..bdc10d3 --- /dev/null +++ b/locale/en-us/dialog/date_format_already_set.dialog @@ -0,0 +1 @@ +Date format is already set to {{format}}. \ No newline at end of file diff --git a/locale/en-us/dialog/date_format_changed.dialog b/locale/en-us/dialog/date_format_changed.dialog new file mode 100644 index 0000000..79b3d18 --- /dev/null +++ b/locale/en-us/dialog/date_format_changed.dialog @@ -0,0 +1 @@ +Date format changed to {{format}}. \ No newline at end of file diff --git a/locale/en-us/vocab/DMY.voc b/locale/en-us/vocab/DMY.voc new file mode 100644 index 0000000..af3759a --- /dev/null +++ b/locale/en-us/vocab/DMY.voc @@ -0,0 +1 @@ +day month year \ No newline at end of file diff --git a/locale/en-us/vocab/MDY.voc b/locale/en-us/vocab/MDY.voc new file mode 100644 index 0000000..cc0243d --- /dev/null +++ b/locale/en-us/vocab/MDY.voc @@ -0,0 +1 @@ +month day year \ No newline at end of file diff --git a/locale/en-us/vocab/YMD.voc b/locale/en-us/vocab/YMD.voc new file mode 100644 index 0000000..80c3681 --- /dev/null +++ b/locale/en-us/vocab/YMD.voc @@ -0,0 +1 @@ +year month day \ No newline at end of file diff --git a/locale/en-us/vocab/date.voc b/locale/en-us/vocab/date.voc new file mode 100644 index 0000000..81229b4 --- /dev/null +++ b/locale/en-us/vocab/date.voc @@ -0,0 +1 @@ +date \ No newline at end of file diff --git a/test/test_resources.yaml b/test/test_resources.yaml index a8ecbae..b01b11c 100644 --- a/test/test_resources.yaml +++ b/test/test_resources.yaml @@ -51,6 +51,10 @@ vocab: - 'timezone' - 'units' - 'username' + - 'date' + - 'DMY' + - 'MDY' + - 'YMD' # dialog is .dialog file basenames (case-sensitive) dialog: @@ -132,6 +136,8 @@ dialog: - 'word_dot' - 'word_at' - 'word_email_title' + - 'date_format_already_set' + - 'date_format_changed' # regex entities, not necessarily filenames regex: - 'rx_language' diff --git a/test/test_skill.py b/test/test_skill.py index 05cbf4d..b52e675 100644 --- a/test/test_skill.py +++ b/test/test_skill.py @@ -203,6 +203,44 @@ def test_handle_time_format_change(self): self.assertEqual( test_message.context["user_profiles"][0]["units"]["time"], 12) + def test_handle_date_format_change(self): + test_profile = self.user_config + test_profile["user"]["username"] = "test_user" + test_profile["units"]["date"] = "MDY" + test_message = Message("test", {"MDY": "month day year"}, + {"username": "test_user", + "user_profiles": [test_profile]}) + # MDY -> MDY + self.skill.handle_date_format_change(test_message) + self.skill.speak_dialog.assert_called_once_with( + "date_format_already_set", {"format": "month day year"}, + private=True) + self.assertEqual( + test_message.context["user_profiles"][0]["units"]["date"], "MDY") + # MDY -> YMD + test_message.data = {"YMD": "year month day"} + self.skill.handle_date_format_change(test_message) + self.skill.speak_dialog.assert_called_with("date_format_changed", + {"format": "year month day"}, + private=True) + self.assertEqual( + test_message.context["user_profiles"][0]["units"]["date"], "YMD") + # YMD -> YMD + self.skill.handle_date_format_change(test_message) + self.skill.speak_dialog.assert_called_with("date_format_already_set", + {"format": "year month day"}, + private=True) + self.assertEqual( + test_message.context["user_profiles"][0]["units"]["date"], "YMD") + # YMD -> DMY + test_message.data = {"DMY": "day month year"} + self.skill.handle_date_format_change(test_message) + self.skill.speak_dialog.assert_called_with("date_format_changed", + {"format": "day month year"}, + private=True) + self.assertEqual( + test_message.context["user_profiles"][0]["units"]["date"], "DMY") + def test_handle_speech_hesitation(self): test_profile = self.user_config test_profile["user"]["username"] = "test_user" From 7589c7fb17eb8a60b593bbdacaf79ed9a25a793c Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Fri, 23 Jun 2023 15:51:23 -0700 Subject: [PATCH 2/3] Add intent to resource tests --- test/test_resources.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_resources.yaml b/test/test_resources.yaml index b01b11c..74b28bf 100644 --- a/test/test_resources.yaml +++ b/test/test_resources.yaml @@ -159,6 +159,7 @@ intents: adapt: - ChangeUnits - ChangeTime + - ChangeDate - SetHesitation - Transcription - SpeakSpeed From 0f11a3b873b78aad962d56782db7c007f351b7d7 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Fri, 23 Jun 2023 16:00:03 -0700 Subject: [PATCH 3/3] Lowercase added vocab with test updates Add intent test cases --- __init__.py | 12 ++++++------ locale/en-us/vocab/{DMY.voc => dmy.voc} | 0 locale/en-us/vocab/{MDY.voc => mdy.voc} | 0 locale/en-us/vocab/{YMD.voc => ymd.voc} | 0 test/test_intents.yaml | 7 +++++++ test/test_resources.yaml | 6 +++--- test/test_skill.py | 6 +++--- 7 files changed, 19 insertions(+), 12 deletions(-) rename locale/en-us/vocab/{DMY.voc => dmy.voc} (100%) rename locale/en-us/vocab/{MDY.voc => mdy.voc} (100%) rename locale/en-us/vocab/{YMD.voc => ymd.voc} (100%) diff --git a/__init__.py b/__init__.py index 2111362..249ac11 100644 --- a/__init__.py +++ b/__init__.py @@ -198,28 +198,28 @@ def handle_time_format_change(self, message: Message): {"scale": str(new_setting)}, private=True) @intent_handler(IntentBuilder("ChangeDate").require("change") - .require("date").one_of("MDY", "DMY", "YMD").build()) + .require("date").one_of("mdy", "dmy", "ymd").build()) def handle_date_format_change(self, message: Message): """ Handle a request to set date format to DMY, MDY, or YMD format :param message: Message associated with request """ - new_setting = "YMD" if message.data.get("YMD") else \ - "MDY" if message.data.get("MDY") else \ - "DMY" if message.data.get("DMY") else None + new_setting = "YMD" if message.data.get("ymd") else \ + "MDY" if message.data.get("mdy") else \ + "DMY" if message.data.get("dmy") else None if not new_setting: raise RuntimeError("Missing required date format vocab") current_setting = get_user_prefs(message)["units"]["date"] if new_setting == current_setting: self.speak_dialog("date_format_already_set", - {"format": message.data.get(new_setting)}, + {"format": message.data.get(new_setting.lower())}, private=True) else: updated_prefs = {"units": {"date": new_setting}} self.update_profile(updated_prefs, message) self.speak_dialog("date_format_changed", - {"format": message.data.get(new_setting)}, + {"format": message.data.get(new_setting.lower())}, private=True) @intent_handler(IntentBuilder("SetHesitation").one_of("permit", "deny") diff --git a/locale/en-us/vocab/DMY.voc b/locale/en-us/vocab/dmy.voc similarity index 100% rename from locale/en-us/vocab/DMY.voc rename to locale/en-us/vocab/dmy.voc diff --git a/locale/en-us/vocab/MDY.voc b/locale/en-us/vocab/mdy.voc similarity index 100% rename from locale/en-us/vocab/MDY.voc rename to locale/en-us/vocab/mdy.voc diff --git a/locale/en-us/vocab/YMD.voc b/locale/en-us/vocab/ymd.voc similarity index 100% rename from locale/en-us/vocab/YMD.voc rename to locale/en-us/vocab/ymd.voc diff --git a/test/test_intents.yaml b/test/test_intents.yaml index abb4ceb..8efe834 100644 --- a/test/test_intents.yaml +++ b/test/test_intents.yaml @@ -44,6 +44,13 @@ en-us: - full - change to military time: - full + ChangeDate: + - use year month day date format: + - ymd + - change date format to month day year: + - mdy + - change to day month year date format: + - dmy SetHesitation: - enable hesitation: - permit diff --git a/test/test_resources.yaml b/test/test_resources.yaml index 74b28bf..bba2188 100644 --- a/test/test_resources.yaml +++ b/test/test_resources.yaml @@ -52,9 +52,9 @@ vocab: - 'units' - 'username' - 'date' - - 'DMY' - - 'MDY' - - 'YMD' + - 'dmy' + - 'mdy' + - 'ymd' # dialog is .dialog file basenames (case-sensitive) dialog: diff --git a/test/test_skill.py b/test/test_skill.py index b52e675..a671f68 100644 --- a/test/test_skill.py +++ b/test/test_skill.py @@ -207,7 +207,7 @@ def test_handle_date_format_change(self): test_profile = self.user_config test_profile["user"]["username"] = "test_user" test_profile["units"]["date"] = "MDY" - test_message = Message("test", {"MDY": "month day year"}, + test_message = Message("test", {"mdy": "month day year"}, {"username": "test_user", "user_profiles": [test_profile]}) # MDY -> MDY @@ -218,7 +218,7 @@ def test_handle_date_format_change(self): self.assertEqual( test_message.context["user_profiles"][0]["units"]["date"], "MDY") # MDY -> YMD - test_message.data = {"YMD": "year month day"} + test_message.data = {"ymd": "year month day"} self.skill.handle_date_format_change(test_message) self.skill.speak_dialog.assert_called_with("date_format_changed", {"format": "year month day"}, @@ -233,7 +233,7 @@ def test_handle_date_format_change(self): self.assertEqual( test_message.context["user_profiles"][0]["units"]["date"], "YMD") # YMD -> DMY - test_message.data = {"DMY": "day month year"} + test_message.data = {"dmy": "day month year"} self.skill.handle_date_format_change(test_message) self.skill.speak_dialog.assert_called_with("date_format_changed", {"format": "day month year"},