bejw 0.3.2__tar.gz → 0.3.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bejw
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: A capped reading list for links that shimmer
5
5
  Author: menisadi
6
6
  License: MIT License
@@ -51,7 +51,7 @@ def add(url: str, title: str, file_path: str = DEFAULT_FILE_PATH) -> None:
51
51
  )
52
52
  raise typer.Exit(code=1)
53
53
  save(reading_list, file_path)
54
- ordered = reading_list.ordered_links()
54
+ ordered = reading_list.unread_links()
55
55
  number = next(
56
56
  (index for index, item in enumerate(ordered, start=1) if item.id == link.id),
57
57
  len(ordered),
@@ -74,12 +74,12 @@ def remove(number: int, file_path: str = DEFAULT_FILE_PATH) -> None:
74
74
  def read(number: int, file_path: str = DEFAULT_FILE_PATH) -> None:
75
75
  """Open a link from the reading list by number."""
76
76
  reading_list = load(file_path)
77
- ordered = reading_list.ordered_links()
78
- if number < 1 or number > len(ordered):
77
+ unread = reading_list.unread_links()
78
+ if number < 1 or number > len(unread):
79
79
  typer.echo("No link found with that number.")
80
80
  raise typer.Exit(code=1)
81
81
 
82
- url = ordered[number - 1].url
82
+ url = unread[number - 1].url
83
83
  webbrowser.open(url)
84
84
  typer.echo(f"Opened #{number}: {url}")
85
85
 
@@ -63,11 +63,11 @@ class ReadingList:
63
63
  self.links = [link for link in self.links if link.id != link_id]
64
64
  return len(self.links) < before
65
65
 
66
- def remove_by_number(self, number: int) -> bool:
67
- ordered = self.ordered_links()
68
- if number < 1 or number > len(ordered):
66
+ def remove_by_number(self, number: int, include_read: bool = False) -> bool:
67
+ visible_links = self.ordered_links() if include_read else self.unread_links()
68
+ if number < 1 or number > len(visible_links):
69
69
  return False
70
- target_id = ordered[number - 1].id
70
+ target_id = visible_links[number - 1].id
71
71
  return self.remove_link(target_id)
72
72
 
73
73
  def clear_links(self) -> None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bejw
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: A capped reading list for links that shimmer
5
5
  Author: menisadi
6
6
  License: MIT License
@@ -14,6 +14,7 @@ bejw.egg-info/requires.txt
14
14
  bejw.egg-info/top_level.txt
15
15
  tests/test_cli_list_formats.py
16
16
  tests/test_cli_mark_read.py
17
+ tests/test_cli_numbering_consistency.py
17
18
  tests/test_cli_read.py
18
19
  tests/test_models.py
19
20
  tests/test_storage.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "bejw"
7
- version = "0.3.2"
7
+ version = "0.3.3"
8
8
  description = "A capped reading list for links that shimmer"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.13"
@@ -0,0 +1,82 @@
1
+ from pathlib import Path
2
+
3
+ from typer.testing import CliRunner
4
+
5
+ from bejw.main import app
6
+ from bejw.models import Link, ReadingList
7
+ from bejw.storage import load, save
8
+
9
+
10
+ runner = CliRunner()
11
+
12
+
13
+ def test_remove_uses_unread_numbering_by_default(tmp_path: Path) -> None:
14
+ file_path = tmp_path / "links.json"
15
+ reading_list = ReadingList(
16
+ capacity=10,
17
+ links=[
18
+ Link(
19
+ id="id-read",
20
+ title="Read First",
21
+ url="https://example.com/read",
22
+ created_at="2024-01-01T00:00:00+00:00",
23
+ read_at="2024-01-10T00:00:00+00:00",
24
+ ),
25
+ Link(
26
+ id="id-unread-1",
27
+ title="Unread One",
28
+ url="https://example.com/unread-1",
29
+ created_at="2024-01-02T00:00:00+00:00",
30
+ ),
31
+ Link(
32
+ id="id-unread-2",
33
+ title="Unread Two",
34
+ url="https://example.com/unread-2",
35
+ created_at="2024-01-03T00:00:00+00:00",
36
+ ),
37
+ ],
38
+ )
39
+ save(reading_list, str(file_path))
40
+
41
+ result = runner.invoke(app, ["remove", "1", "--file-path", str(file_path)])
42
+
43
+ assert result.exit_code == 0
44
+ updated = load(str(file_path))
45
+ assert [link.id for link in updated.ordered_links()] == ["id-read", "id-unread-2"]
46
+
47
+
48
+ def test_add_confirmation_number_uses_unread_numbering(tmp_path: Path) -> None:
49
+ file_path = tmp_path / "links.json"
50
+ reading_list = ReadingList(
51
+ capacity=10,
52
+ links=[
53
+ Link(
54
+ id="id-read",
55
+ title="Read First",
56
+ url="https://example.com/read",
57
+ created_at="2024-01-01T00:00:00+00:00",
58
+ read_at="2024-01-10T00:00:00+00:00",
59
+ ),
60
+ Link(
61
+ id="id-unread-1",
62
+ title="Unread One",
63
+ url="https://example.com/unread-1",
64
+ created_at="2024-01-02T00:00:00+00:00",
65
+ ),
66
+ ],
67
+ )
68
+ save(reading_list, str(file_path))
69
+
70
+ result = runner.invoke(
71
+ app,
72
+ [
73
+ "add",
74
+ "https://example.com/new",
75
+ "New Link",
76
+ "--file-path",
77
+ str(file_path),
78
+ ],
79
+ )
80
+
81
+ assert result.exit_code == 0
82
+ assert result.stdout == "Added #2\n"
@@ -70,3 +70,39 @@ def test_read_returns_error_for_empty_list(tmp_path: Path) -> None:
70
70
 
71
71
  assert result.exit_code == 1
72
72
  assert result.stdout == "No link found with that number.\n"
73
+
74
+
75
+ def test_read_uses_unread_numbering_by_default(tmp_path: Path, monkeypatch) -> None:
76
+ file_path = tmp_path / "links.json"
77
+ reading_list = ReadingList(
78
+ capacity=10,
79
+ links=[
80
+ Link(
81
+ id="id-1",
82
+ title="Read Example",
83
+ url="https://example.com/read",
84
+ created_at="2024-01-01T00:00:00+00:00",
85
+ read_at="2024-01-03T00:00:00+00:00",
86
+ ),
87
+ Link(
88
+ id="id-2",
89
+ title="Unread Example",
90
+ url="https://example.com/unread",
91
+ created_at="2024-01-02T00:00:00+00:00",
92
+ ),
93
+ ],
94
+ )
95
+ save(reading_list, str(file_path))
96
+ opened: list[str] = []
97
+
98
+ def _fake_open(url: str, *_args, **_kwargs) -> bool:
99
+ opened.append(url)
100
+ return True
101
+
102
+ monkeypatch.setattr(webbrowser, "open", _fake_open)
103
+
104
+ result = runner.invoke(app, ["read", "1", "--file-path", str(file_path)])
105
+
106
+ assert result.exit_code == 0
107
+ assert opened == ["https://example.com/unread"]
108
+ assert result.stdout == "Opened #1: https://example.com/unread\n"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes