-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathtest_report.py
More file actions
143 lines (119 loc) · 3.82 KB
/
test_report.py
File metadata and controls
143 lines (119 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import pytest
from beets.library import Item
from beetsplug.report import ReportPlugin
# --- Fixtures ---
@pytest.fixture
def library(tmp_path):
"""Create a temporary empty Beets library."""
from beets.library import Library
lib_path = tmp_path / "beets.db"
lib = Library(str(lib_path))
return lib
def add_item(
lib,
title="Test",
artist="Artist",
album="Album",
genre="Genre",
year=2000,
length=180,
bitrate=320,
):
"""Add a single Item to the test library."""
item = Item(
path=f"/tmp/{title}.mp3",
title=title,
artist=artist,
album=album,
genre=genre,
year=year,
length=length,
bitrate=bitrate,
)
lib.add(item)
# --- Tests ---
def test_empty_library(capsys, library):
"""Test empty library: should output message without crashing."""
plugin = ReportPlugin()
plugin._run_report(library, None, [])
captured = capsys.readouterr()
assert "Your Beets library is empty." in captured.out
def test_single_item(capsys, library):
"""Test library with a single track."""
add_item(
library,
title="Single Track",
artist="Solo Artist",
genre="Indie",
year=2019,
)
plugin = ReportPlugin()
plugin._run_report(library, None, [])
captured = capsys.readouterr()
# --- Basic statistics ---
assert "Tracks:" in captured.out
assert "Albums:" in captured.out
assert "Artists:" in captured.out
assert "Genres:" in captured.out
# --- Wrapped-style insights ---
assert "Top artist:" in captured.out
assert "Solo Artist" in captured.out
assert "Top genre:" in captured.out
assert "Indie" in captured.out
assert "Top decade:" in captured.out
assert "10s" in captured.out
assert "Top year:" in captured.out
assert "2019" in captured.out
def test_multiple_items(capsys, library):
"""Test library with multiple tracks from different decades and genres."""
add_item(library, "Track1", "Artist A", "Album X", "Rock", 1995)
add_item(library, "Track2", "Artist A", "Album X", "Rock", 1995)
add_item(library, "Track3", "Artist B", "Album Y", "Pop", 2002)
add_item(library, "Track4", "Artist C", "Album Z", "Electronic", 2018)
plugin = ReportPlugin()
plugin._run_report(library, None, [])
captured = capsys.readouterr()
# --- Basic stats ---
assert "Tracks:" in captured.out and "4" in captured.out
assert "Albums:" in captured.out and "3" in captured.out
assert "Artists:" in captured.out and "3" in captured.out
assert "Genres:" in captured.out and "3" in captured.out
# --- Wrapped-style insights ---
assert "Top artist:" in captured.out and "Artist A" in captured.out
assert "Top genre:" in captured.out and "Rock" in captured.out
assert "Top decade:" in captured.out and "90s" in captured.out
assert "Top year:" in captured.out and "1995" in captured.out
# --- Decade distribution ---
assert "90s" in captured.out
assert "00s" in captured.out
assert "10s" in captured.out
def test_missing_metadata(capsys, library):
"""Test library with missing tags, length, and bitrate."""
add_item(
library,
"Track1",
"Artist",
"Album",
None,
2000,
length=200,
bitrate=256,
)
add_item(
library,
"Track2",
"Artist",
"Album",
"Rock",
None,
length=180,
bitrate=None,
)
plugin = ReportPlugin()
plugin._run_report(library, None, [])
captured = capsys.readouterr()
# --- Check missing metadata counts ---
assert "Missing genre" in captured.out
assert "1" in captured.out # At least one missing genre
assert "Missing year" in captured.out
assert "1" in captured.out # At least one missing year