Skip to content

Commit fdf476b

Browse files
committed
Improve tests for history
1 parent e515c91 commit fdf476b

7 files changed

Lines changed: 78 additions & 61 deletions

File tree

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v6
13+
with:
14+
persist-credentials: false
1315
- uses: actions/setup-python@v6
1416
with:
1517
python-version: "3.11"

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ jobs:
1818
CI: "true"
1919
steps:
2020
- uses: actions/checkout@v6
21+
with:
22+
persist-credentials: false
2123
- uses: astral-sh/setup-uv@v8.0.0
2224
- run: uv run --python ${{ matrix.python-version }} --with pytest python -m pytest

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Coverage Status](https://coveralls.io/repos/github/captn3m0/hackertray/badge.svg?branch=master)](https://coveralls.io/github/captn3m0/hackertray?branch=master)
55
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/captn3m0/hackertray/test.yml)
66

7-
HackerTray is a simple [Hacker News](https://news.ycombinator.com/) application
7+
HackerTray is a cross-platform [Hacker News](https://news.ycombinator.com/) application
88
that lets you view top HN stories in your System Tray. On Linux it uses appindicator where available
99
(with a Gtk StatusIcon fallback). On macOS it uses a native status bar menu via pyobjc.
1010

hackertray/history.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,18 @@ def _query_urls(db_path: Path, table: str, column: str, urls: list[str]) -> set[
281281
# ── Public API ────────────────────────────────────────────────────────
282282

283283

284-
def discover(home: Path | None = None) -> list[HistoryDB]:
284+
def discover(home: Path | None = None, platform: str | None = None) -> list[HistoryDB]:
285285
"""Discover all browser history databases on this system.
286286
287287
Returns a list of HistoryDB instances, one per database file found.
288288
"""
289289
if home is None:
290290
home = Path.home()
291291

292+
key = platform or _PLATFORM_KEY
292293
results: list[HistoryDB] = []
293294
for schema, label, platform_globs in _BROWSERS:
294-
patterns = platform_globs.get(_PLATFORM_KEY, []) if _PLATFORM_KEY else []
295+
patterns = platform_globs.get(key, []) if key else []
295296
for pattern in patterns:
296297
for db_path in sorted(home.glob(pattern)):
297298
if db_path.is_file():

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ exclude = ["test*"]
3636

3737
[dependency-groups]
3838
dev = [
39-
"pytest>=9.0.3",
39+
"pytest>=9.0.2",
4040
"pytest-cov>=7.1.0",
4141
]

test/history_test.py

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -154,74 +154,82 @@ def test_missing_db_raises(self):
154154

155155

156156
class TestDiscover(unittest.TestCase):
157-
def test_discover_finds_firefox(self):
157+
def _setup_and_discover(self, rel_path, fixture, platform):
158+
"""Create a fake browser profile and run discover."""
158159
with tempfile.TemporaryDirectory() as tmpdir:
159160
home = Path(tmpdir) / "home"
160-
profile_dir = (
161-
home
162-
/ "Library"
163-
/ "Application Support"
164-
/ "Firefox"
165-
/ "abc12345.default-release"
166-
)
167-
profile_dir.mkdir(parents=True)
168-
shutil.copy(FIXTURES / "places.sqlite", profile_dir / "places.sqlite")
169-
dbs = discover(home=home)
170-
firefox_dbs = [db for db in dbs if db.label == "Firefox"]
171-
self.assertTrue(len(firefox_dbs) >= 1)
172-
self.assertEqual(firefox_dbs[0].schema, HistorySchema.FIREFOX)
173-
174-
def test_discover_finds_chrome(self):
175-
with tempfile.TemporaryDirectory() as tmpdir:
176-
home = Path(tmpdir) / "home"
177-
chrome_dir = (
178-
home
179-
/ "Library"
180-
/ "Application Support"
181-
/ "Google"
182-
/ "Chrome"
183-
/ "Default"
184-
)
185-
chrome_dir.mkdir(parents=True)
186-
shutil.copy(FIXTURES / "History", chrome_dir / "History")
187-
dbs = discover(home=home)
188-
chrome_dbs = [db for db in dbs if db.label == "Chrome"]
189-
self.assertTrue(len(chrome_dbs) >= 1)
190-
self.assertEqual(chrome_dbs[0].schema, HistorySchema.CHROMIUM)
161+
dest = home / rel_path
162+
dest.parent.mkdir(parents=True, exist_ok=True)
163+
shutil.copy(FIXTURES / fixture, dest)
164+
return discover(home=home, platform=platform)
165+
166+
def test_discover_finds_firefox_macos(self):
167+
dbs = self._setup_and_discover(
168+
"Library/Application Support/Firefox/abc12345.default-release/places.sqlite",
169+
"places.sqlite", "macos")
170+
firefox_dbs = [db for db in dbs if db.label == "Firefox"]
171+
self.assertEqual(len(firefox_dbs), 1)
172+
self.assertEqual(firefox_dbs[0].schema, HistorySchema.FIREFOX)
173+
174+
def test_discover_finds_firefox_linux(self):
175+
dbs = self._setup_and_discover(
176+
".mozilla/firefox/abc12345.default-release/places.sqlite",
177+
"places.sqlite", "linux")
178+
firefox_dbs = [db for db in dbs if db.label == "Firefox"]
179+
self.assertEqual(len(firefox_dbs), 1)
180+
self.assertEqual(firefox_dbs[0].schema, HistorySchema.FIREFOX)
181+
182+
def test_discover_finds_chrome_macos(self):
183+
dbs = self._setup_and_discover(
184+
"Library/Application Support/Google/Chrome/Default/History",
185+
"History", "macos")
186+
chrome_dbs = [db for db in dbs if db.label == "Chrome"]
187+
self.assertEqual(len(chrome_dbs), 1)
188+
self.assertEqual(chrome_dbs[0].schema, HistorySchema.CHROMIUM)
189+
190+
def test_discover_finds_chrome_linux(self):
191+
dbs = self._setup_and_discover(
192+
".config/google-chrome/Default/History",
193+
"History", "linux")
194+
chrome_dbs = [db for db in dbs if db.label == "Chrome"]
195+
self.assertEqual(len(chrome_dbs), 1)
196+
self.assertEqual(chrome_dbs[0].schema, HistorySchema.CHROMIUM)
191197

192198
def test_discover_finds_safari(self):
193-
with tempfile.TemporaryDirectory() as tmpdir:
194-
home = Path(tmpdir) / "home"
195-
safari_dir = home / "Library" / "Safari"
196-
safari_dir.mkdir(parents=True)
197-
shutil.copy(FIXTURES / "safari" / "History.db", safari_dir / "History.db")
198-
dbs = discover(home=home)
199-
safari_dbs = [db for db in dbs if db.label == "Safari"]
200-
self.assertTrue(len(safari_dbs) >= 1)
201-
self.assertEqual(safari_dbs[0].schema, HistorySchema.SAFARI)
199+
dbs = self._setup_and_discover(
200+
"Library/Safari/History.db",
201+
"safari/History.db", "macos")
202+
safari_dbs = [db for db in dbs if db.label == "Safari"]
203+
self.assertEqual(len(safari_dbs), 1)
204+
self.assertEqual(safari_dbs[0].schema, HistorySchema.SAFARI)
202205

203206
def test_discover_empty_home(self):
204207
with tempfile.TemporaryDirectory() as tmpdir:
205208
home = Path(tmpdir) / "emptyhome"
206209
home.mkdir()
207-
dbs = discover(home=home)
208-
self.assertEqual(dbs, [])
210+
for platform in ("macos", "linux"):
211+
dbs = discover(home=home, platform=platform)
212+
self.assertEqual(dbs, [])
213+
214+
def test_discover_multiple_chrome_profiles_macos(self):
215+
with tempfile.TemporaryDirectory() as tmpdir:
216+
home = Path(tmpdir) / "home"
217+
for profile in ("Default", "Profile 1"):
218+
d = home / "Library" / "Application Support" / "Google" / "Chrome" / profile
219+
d.mkdir(parents=True)
220+
shutil.copy(FIXTURES / "History", d / "History")
221+
dbs = discover(home=home, platform="macos")
222+
chrome_dbs = [db for db in dbs if db.label == "Chrome"]
223+
self.assertEqual(len(chrome_dbs), 2)
209224

210-
def test_discover_multiple_chrome_profiles(self):
225+
def test_discover_multiple_chrome_profiles_linux(self):
211226
with tempfile.TemporaryDirectory() as tmpdir:
212227
home = Path(tmpdir) / "home"
213228
for profile in ("Default", "Profile 1"):
214-
d = (
215-
home
216-
/ "Library"
217-
/ "Application Support"
218-
/ "Google"
219-
/ "Chrome"
220-
/ profile
221-
)
229+
d = home / ".config" / "google-chrome" / profile
222230
d.mkdir(parents=True)
223231
shutil.copy(FIXTURES / "History", d / "History")
224-
dbs = discover(home=home)
232+
dbs = discover(home=home, platform="linux")
225233
chrome_dbs = [db for db in dbs if db.label == "Chrome"]
226234
self.assertEqual(len(chrome_dbs), 2)
227235

uv.lock

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)