mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-13 00:15:05 +00:00
Fix linting and formatting issues
Co-authored-by: MischaPanch <35432522+MischaPanch@users.noreply.github.com>
This commit is contained in:
1 parent
61891370e4
commit
8c6fdda646
2 files changed
+10
-12
No files matched your search
@@ -2,7 +2,7 @@ import os
|
||||
import socket
|
||||
import threading
|
||||
from collections.abc import Callable
|
||||
from datetime import datetime
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, Self
|
||||
|
||||
@@ -148,23 +148,23 @@ class SerenaDashboardAPI:
|
||||
"""
|
||||
Get the installation date ID (YYYYMMDD format) based on the creation time
|
||||
of the SERENA_HOME directory.
|
||||
|
||||
|
||||
:return: Installation date as an integer in YYYYMMDD format
|
||||
"""
|
||||
serena_home = SerenaPaths().serena_user_home_dir
|
||||
|
||||
|
||||
# If SERENA_HOME doesn't exist yet, return today's date
|
||||
if not os.path.exists(serena_home):
|
||||
today = datetime.now()
|
||||
today = datetime.now(tz=UTC)
|
||||
return int(today.strftime("%Y%m%d"))
|
||||
|
||||
|
||||
# Get the creation/modification time of the SERENA_HOME directory
|
||||
stat_info = os.stat(serena_home)
|
||||
# Use st_ctime on Unix-like systems (change time, closest to creation time)
|
||||
# or st_mtime if ctime is not reliable
|
||||
creation_timestamp = stat_info.st_ctime
|
||||
creation_date = datetime.fromtimestamp(creation_timestamp)
|
||||
|
||||
creation_date = datetime.fromtimestamp(creation_timestamp, tz=UTC)
|
||||
|
||||
# Return as YYYYMMDD integer
|
||||
return int(creation_date.strftime("%Y%m%d"))
|
||||
|
||||
@@ -350,12 +350,12 @@ class SerenaDashboardAPI:
|
||||
def _get_unread_news_ids() -> list[int]:
|
||||
all_news_files = (Path(SERENA_DASHBOARD_DIR) / "news").glob("*.html")
|
||||
all_news_ids = [int(f.stem) for f in all_news_files]
|
||||
|
||||
|
||||
# Filter news items by installation date
|
||||
installation_date_id = self._get_installation_date_id()
|
||||
# Only include news items published on or after the installation date
|
||||
all_news_ids = [news_id for news_id in all_news_ids if news_id >= installation_date_id]
|
||||
|
||||
|
||||
news_snippet_id_file = SerenaPaths().news_snippet_id_file
|
||||
if not os.path.exists(news_snippet_id_file):
|
||||
return all_news_ids
|
||||
|
||||
@@ -8,8 +8,6 @@ from datetime import datetime
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from serena.dashboard import SerenaDashboardAPI
|
||||
|
||||
|
||||
@@ -30,7 +28,7 @@ class TestNewsDisplayLogic:
|
||||
# Should return a valid YYYYMMDD format integer
|
||||
assert isinstance(result, int)
|
||||
assert 20000101 <= result <= 99991231 # Valid date range
|
||||
|
||||
|
||||
# Should match today's or recent date (since we just created the directory)
|
||||
result_str = str(result)
|
||||
assert len(result_str) == 8
|
||||
|
||||
Reference in new issue
Block a user