diff --git a/sleap/gui/web.py b/sleap/gui/web.py index a6fe79d1f..fa10242dd 100644 --- a/sleap/gui/web.py +++ b/sleap/gui/web.py @@ -6,6 +6,7 @@ from typing import List, Dict, Any, Optional, Tuple import json import os +from datetime import datetime REPO_ID = "talmolab/sleap" @@ -164,7 +165,7 @@ def previous_announcement_date(self): _previous_announcement_date = self.state["announcement last seen date"] return _previous_announcement_date - def _read_bulletin_data(self): + def _read_bulletin_data(self) -> Optional[Dict]: """Reads the bulletin data from the JSON file.""" try: with open(self.bulletin_json_path, "r") as jsf: @@ -176,14 +177,17 @@ def _read_bulletin_data(self): @property def new_announcement_available(self): self._read_bulletin_data() + latest_date = datetime.strptime(self._latest_data["date"], "%m/%d/%Y") + previous_date = datetime.strptime(self.previous_announcement_date, "%m/%d/%Y") if ( - self._latest_data and self.previous_announcement_date - and self._latest_data["date"] != self.previous_announcement_date + self._latest_data + and self.previous_announcement_date + and latest_date > previous_date ): return True return False - def get_latest_announcement(self) -> Optional[Tuple[str, str]]: + def get_latest_announcement(self) -> Optional[Tuple[str, str, str]]: """Return latest announcements on the releases page not seen by user.""" if self.new_announcement_available: return ( diff --git a/tests/data/announcement_checker_bulletin/test_bulletin.json b/tests/data/announcement_checker_bulletin/test_bulletin.json index 4c9ef56b7..a4b2e60c8 100644 --- a/tests/data/announcement_checker_bulletin/test_bulletin.json +++ b/tests/data/announcement_checker_bulletin/test_bulletin.json @@ -1 +1 @@ -[{"title": "title1", "date": "10/12/2023", "content": "# Bulletin\n\n\n\nSLEAP 1.3.2 adds some nice usability features thanks to both the community ideas and new contributors! See [1.3.0](https://github.com/talmolab/sleap/releases/tag/v1.3.0) and [1.3.1](https://github.com/talmolab/sleap/releases/tag/v1.3.1) for previous notable changes. As a reminder:\n\n> The 1.3.1 dependency update requires [Mamba](https://mamba.readthedocs.io/en/latest/index.html) for faster dependency resolution. If you already have anaconda installed, then you _can_ set the solver to libmamba in the base environment:\n>```\n>conda update -n base conda\n>conda install -n base conda-libmamba-solver\n>conda config --set solver libmamba\n>```\n>Any subsequent `mamba` commands in the docs will need to be replaced with `conda` if you choose to use your existing Anaconda installation. \n>\n>Otherwise, follow the [recommended installation instruction for Mamba](https://mamba.readthedocs.io/en/latest/installation.html).\n\n**`mamba` (Windows/Linux/GPU)**:\n```\nmamba create -y -n sleap -c conda-forge -c nvidia -c sleap -c anaconda sleap=1.3.2\n```\n\n**`mamba` (Mac)**:\n```\nmamba create -y -n sleap -c conda-forge -c anaconda -c sleap sleap=1.3.2\n```\n\n**`pip` (any OS except Apple Silicon)**:\n```\npip install sleap[pypi]==1.3.2\n```\n\n* Limit max tracks via track-local queues by @shrivaths16 and @talmo in https://github.com/talmolab/sleap/pull/1447\n* Add option to remove videos in batch by @gitttt-1234 in https://github.com/talmolab/sleap/pull/1382 and https://github.com/talmolab/sleap/pull/1406\n* Add shortcut to export analysis for current video by @KevinZ0217 in https://github.com/talmolab/sleap/pull/1414 and https://github.com/talmolab/sleap/pull/1444\n* Add video path and frame indices to metrics by @roomrys in https://github.com/talmolab/sleap/pull/1396\n* Add a button for copying model config to clipboard by @KevinZ0217 in https://github.com/talmolab/sleap/pull/1433\n* Add Option to Export CSV by @gitttt-1234 in https://github.com/talmolab/sleap/pull/1438\n\n\n* Add option to remove videos in batch by @gitttt-1234 in https://github.com/talmolab/sleap/pull/1382 and https://github.com/talmolab/sleap/pull/1406\n* Add `Track` when add `Instance` by @roomrys in https://github.com/talmolab/sleap/pull/1408\n* Add `Video` to cache when adding `Track` by @roomrys in https://github.com/talmolab/sleap/pull/1407\n* Add shortcut to export analysis for current video by @KevinZ0217 in https://github.com/talmolab/sleap/pull/1414 and https://github.com/talmolab/sleap/pull/1444\n* Add video path and frame indices to metrics by @roomrys in https://github.com/talmolab/sleap/pull/1396\n* Improve error message for detecting video backend by @roomrys in https://github.com/talmolab/sleap/pull/1441\n* Add a button for copying model config to clipboard by @KevinZ0217 in https://github.com/talmolab/sleap/pull/1433\n* Add Option to Export CSV by @gitttt-1234 in https://github.com/talmolab/sleap/pull/1438\n* Limit max tracks via track-local queues by @shrivaths16 and @talmo in https://github.com/talmolab/sleap/pull/1447\n\n* Minor fix in computation of OKS by @shrivaths16 in https://github.com/talmolab/sleap/pull/1383 and https://github.com/talmolab/sleap/pull/1399\n* Fix `Filedialog` to work across (mac)OS by @roomrys in https://github.com/talmolab/sleap/pull/1393\n* Fix panning bounding box by @gitttt-1234 in https://github.com/talmolab/sleap/pull/1398\n* Fix skeleton templates by @roomrys in https://github.com/talmolab/sleap/pull/1404\n* Fix labels export for json by @roomrys in https://github.com/talmolab/sleap/pull/1410\n* Correct GUI state emulation by @roomrys in https://github.com/talmolab/sleap/pull/1422\n* Update status message on status bar by @shrivaths16 in https://github.com/talmolab/sleap/pull/1411\n* Fix error thrown when last video is deleted by @shrivaths16 in https://github.com/talmolab/sleap/pull/1421\n* Add model folder to the unzip path by @roomrys in https://github.com/talmolab/sleap/pull/1445\n* Fix drag and drop by @talmo in https://github.com/talmolab/sleap/pull/1449\n\n* Pin micromamba version by @roomrys in https://github.com/talmolab/sleap/pull/1376\n* Add pip extras by @roomrys in https://github.com/talmolab/sleap/pull/1481\n\n* @shrivaths16 made their first contribution in https://github.com/talmolab/sleap/pull/1383\n* @gitttt-1234 made their first contribution in https://github.com/talmolab/sleap/pull/1382\n* @KevinZ0217 made their first contribution in https://github.com/talmolab/sleap/pull/1414\n\n**Full Changelog**: https://github.com/talmolab/sleap/compare/v1.3.1...v1.3.2\n"}, {"title": "title2", "date": "10/07/2023", "content": "Old Announcment"}] \ No newline at end of file +[{"title": "title1", "date": "10/09/2023", "content": "New announcement"}, {"title": "title2", "date": "10/07/2023", "content": "Old Announcment"}] \ No newline at end of file diff --git a/tests/gui/test_web.py b/tests/gui/test_web.py index 942d4e84f..bd0d7d26e 100644 --- a/tests/gui/test_web.py +++ b/tests/gui/test_web.py @@ -107,10 +107,23 @@ def test_announcementchecker(bulletin_json_path): announcement = checker.get_latest_announcement() assert announcement == ("title1", "10/12/2023", "New announcement") + # Check if announcement is updated checker.update_announcement() assert context.state["announcement last seen date"] == "10/12/2023" assert context.state["announcement"] == "New announcement" + # Create dummy JSON file + bulletin_data = [ + {"title": "title1", "date": "10/09/2023", "content": "New announcement"}, + {"title": "title2", "date": "10/07/2023", "content": "Old Announcment"}, + ] + with open(bulletin_json_path, "w") as test_file: + json.dump(bulletin_data, test_file) + + # Check to ensure no new announcement is created + announcement = checker.get_latest_announcement() + assert announcement == None + def test_get_analytics_data(): analytics_data = get_analytics_data()