-
Notifications
You must be signed in to change notification settings - Fork 0
Multi fields #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi fields #38
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,17 @@ def lib(): | |
| lib.add(MockItem("song1", 2000, "artist1", "album1", 128, "lyrics1")) | ||
| lib.add(MockItem("song2", 2001, "artist2", "album2", 256, "lyrics2")) | ||
| lib.add(MockItem("song3", 2002, "artist3", "album3", 512, "lyrics3")) | ||
| lib.add( | ||
| MockItem( | ||
| "song4", | ||
| 2003, | ||
| "artist3; artist4", | ||
| "album4", | ||
| 700, | ||
| "so many lyrics in this song", | ||
| ) | ||
|
Comment on lines
+37
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Suggest adding more test cases for multi-field handling with edge cases. It would be beneficial to add tests for edge cases like empty strings, strings with only delimiters, and combinations of valid and invalid multi-field values. For example, consider cases like Suggested implementation: lib.add(MockItem("song1", 2000, "artist1", "album1", 128, "lyrics1"))
lib.add(MockItem("song2", 2001, "artist2", "album2", 256, "lyrics2"))
lib.add(MockItem("song3", 2002, "artist3", "album3", 512, "lyrics3"))
lib.add(
MockItem(
"song4",
2003,
"artist3; artist4",
"album4",
700,
"so many lyrics in this song",
)
)
# Edge cases for multi-field handling
lib.add(
MockItem(
"song5",
2004,
"artist1;;artist2", # Double delimiter
"album5",
800,
"lyrics5",
)
)
lib.add(
MockItem(
"song6",
2005,
";artist1;artist2;", # Leading/trailing delimiters
"album6",
900,
"lyrics6",
)
)
lib.add(
MockItem(
"song7",
2006,
" ", # Just whitespace
"album7",
1000,
"lyrics7",
)
)
lib.add(
MockItem(
"song8",
2007,
"", # Empty string
"album8",
1100,
"lyrics8",
)
)
lib.add(
MockItem(
"song9",
2008,
" artist1 ; artist2 ", # Whitespace around delimiters
"album9",
1200,
"lyrics9",
)
)
return libYou'll need to:
|
||
| ) | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Missing tests for other multifield_categories. The description mentions that multiple fields are now supported. The tests only cover the Suggested implementation: lib.add(
MockItem(
"song4",
2003,
"artist3; artist4",
"album4",
700,
"so many lyrics in this song",
)
)
# Add items with multiple albumartists
lib.add(
MockItem(
"song5",
2004,
"artist5",
"album5",
800,
"lyrics5",
albumartist="albumartist1; albumartist2"
)
)
# Add items with multiple genres
lib.add(
MockItem(
"song6",
2005,
"artist6",
"album6",
900,
"lyrics6",
genre="rock; pop"
)
)
return lib
assert "2000 |" in txtdef test_show_summary_artist(lib):
stats = "count"
txt = sm.show_summary(lib, "query", category="artist", stats=stats, reverse=False)
assert "artist1 | 1" in txt
assert "artist2 | 1" in txt
assert "artist3 | 2" in txt # in the multi-field
assert "artist4 | 1" in txt # in the multi-field
def test_show_summary_albumartist(lib):
stats = "count"
txt = sm.show_summary(lib, "query", category="albumartist", stats=stats, reverse=False)
assert "albumartist1 | 1" in txt # in the multi-field
assert "albumartist2 | 1" in txt # in the multi-field
def test_show_summary_genre(lib):
stats = "count"
txt = sm.show_summary(lib, "query", category="genre", stats=stats, reverse=False)
assert "rock | 1" in txt # in the multi-field
assert "pop | 1" in txt # in the multi-fieldNote: The MockItem class constructor might need to be updated to accept albumartist and genre parameters if they're not already supported. You may need to add these fields to the MockItem class definition if they don't exist. |
||
| return lib | ||
|
|
||
|
|
||
|
|
@@ -78,3 +89,13 @@ def test_show_summary(lib): | |
| assert "2000 |" in txt | ||
| assert "2001 |" in txt | ||
| assert "2002 |" in txt | ||
|
|
||
|
|
||
| def test_show_summary_artist(lib): | ||
| stats = "count" | ||
| txt = sm.show_summary(lib, "query", category="artist", stats=stats, reverse=False) | ||
|
|
||
| assert "artist1 | 1" in txt | ||
| assert "artist2 | 1" in txt | ||
| assert "artist3 | 2" in txt # in the multi-field | ||
| assert "artist4 | 1" in txt # in the multi-field | ||
|
Comment on lines
+100
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Consider using more precise assertions. Instead of checking if a substring exists in the output, it's better to parse the output and assert on the specific values. This makes the test less brittle and provides more informative error messages when it fails. For example, you could split the output by lines and then by '|' to check the counts for each artist. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider handling edge cases where 'cat' is None or an empty string
The current implementation might create groups with empty keys or raise exceptions for None values. Consider adding validation or explicit handling for these cases.