diff --git a/borax/calendars/festivals2.py b/borax/calendars/festivals2.py index ce4fa17..e84de7f 100644 --- a/borax/calendars/festivals2.py +++ b/borax/calendars/festivals2.py @@ -65,17 +65,25 @@ class FestivalSchema(enum.IntEnum): class WrappedDate: """A date object with solar and lunar calendars.""" - __slots__ = ['solar', 'lunar', 'name', '_fl'] + __slots__ = ['_solar', '_lunar', 'name', '_fl'] def __init__(self, date_obj: MixedDate, name: str = ''): - self.solar = LCalendars.cast_date(date_obj, date) - self.lunar = LCalendars.cast_date(date_obj, LunarDate) + self._solar = LCalendars.cast_date(date_obj, date) + self._lunar = LCalendars.cast_date(date_obj, LunarDate) self.name = name if isinstance(date_obj, date): self._fl = 's' else: self._fl = 'l' + @property + def solar(self): + return self._solar + + @property + def lunar(self): + return self._lunar + def __iter__(self): yield self.solar yield self.lunar @@ -122,13 +130,6 @@ def __hash__(self): def __eq__(self, other): return isinstance(self, type(other)) and self.__key() == other.__key() - def __getstate__(self): - return self.__key() - - def __setstate__(self, state): - _year, _month, _day = state - self.solar = date(_year, _month, _day) - def full_str(self): return f'{self.solar}({self.lunar.cn_str()})' diff --git a/borax/capp/borax_calendar_app.py b/borax/capp/borax_calendar_app.py index de4e024..bc5e2fb 100644 --- a/borax/capp/borax_calendar_app.py +++ b/borax/capp/borax_calendar_app.py @@ -18,8 +18,6 @@ library = FestivalLibrary.load_builtin().sort_by_countdown() -__VERSION__ = '1.1.0' - PROJECT_URLS = { 'home': 'https://github.com/kinegratii/borax' } @@ -347,7 +345,7 @@ def start_festival_dlg(self): self._create_festival_dialog() def show_about_info(self): - showinfo('关于', f' 日历v{__VERSION__}\n\n Powered by Borax{borax_version}') + showinfo('关于', f' 日历v{borax_version}\n\n Powered by Borax{borax_version}') def start_calendar_app(): @@ -356,7 +354,7 @@ def start_calendar_app(): x, y = int(root.winfo_screenwidth() / 2 - rw / 2), int(root.winfo_screenheight() / 2 - rh / 2) root.geometry(f"{rw}x{rh}+{x}+{y}") root.resizable(False, False) - root.title(f'日历 - v{__VERSION__}') + root.title(f'日历 - v{borax_version}') global style style = ttk.Style(root) # style.theme_use('alt') diff --git a/docs/changelog.md b/docs/changelog.md index e7a7276..23d1e92 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -13,6 +13,7 @@ - 新增方法 `FestivalLibrary.load` - 新增 `borax.ui.widgets.MessageLabel` 类 - `Festival` 类新增 `code` 属性 + - `WrappedDate.solar` 和 `WrappedDate.lunar` 属性变更为只读属性,不可写入 - 项目构建 - 不再支持python3.7和python3.8 - 本地开发环境更新至 python3.11.7 diff --git a/mkdocs.yaml b/mkdocs.yaml index c17a294..b80922b 100644 --- a/mkdocs.yaml +++ b/mkdocs.yaml @@ -9,6 +9,10 @@ theme: - navigation.tabs - navigation.sections - navigation.footer +validation: + links: + absolute_links: ignore + unrecognized_links: ignore extra: social: - icon: fontawesome/brands/github diff --git a/tests/test_date_pickle.py b/tests/test_date_pickle.py index 1e0c29c..bb60b80 100644 --- a/tests/test_date_pickle.py +++ b/tests/test_date_pickle.py @@ -2,13 +2,24 @@ import pickle from io import BytesIO +from datetime import date + from borax.calendars.lunardate import LunarDate from borax.calendars.festivals2 import WrappedDate +class WrappedDateBasicTestCase(unittest.TestCase): + def test_wrapped_date(self): + ld = LunarDate.today() + wd = WrappedDate(ld) + self.assertEqual(ld, wd.lunar) + with self.assertRaises(AttributeError): + wd.lunar = LunarDate(2024, 1, 1) + + class DatePickleTestCase(unittest.TestCase): - def test_wd(self): + def test_lunardate_pickle(self): ld1 = LunarDate.today() fp = BytesIO() @@ -18,11 +29,13 @@ def test_wd(self): e_ld = pickle.load(fp) self.assertEqual(ld1, e_ld) - wd1 = WrappedDate(ld1) - fp2 = BytesIO() - - pickle.dump(wd1, fp2) - - fp2.seek(0) - wd2 = pickle.load(fp2) - self.assertEqual(wd2, wd1) + def test_wrapped_date_pickle(self): + wd_list = [WrappedDate(date.today()), WrappedDate(LunarDate.today())] + for wd in wd_list: + with self.subTest(wd=wd): + fp = BytesIO() + pickle.dump(wd, fp) + fp.seek(0) + new_wd = pickle.load(fp) + self.assertEqual(wd.solar, new_wd.solar) + self.assertEqual(wd.lunar, new_wd.lunar)