Replace unittest with pytest
This commit is contained in:
parent
1160ee1513
commit
aae4bb3693
10 changed files with 253 additions and 305 deletions
|
@ -2,8 +2,6 @@
|
|||
"""
|
||||
Integration (not unit) tests for pylast.py
|
||||
"""
|
||||
import unittest
|
||||
|
||||
import pylast
|
||||
import pytest
|
||||
|
||||
|
@ -19,13 +17,13 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
representation = repr(artist)
|
||||
|
||||
# Assert
|
||||
self.assertTrue(representation.startswith("pylast.Artist('Test Artist',"))
|
||||
assert representation.startswith("pylast.Artist('Test Artist',")
|
||||
|
||||
def test_artist_is_hashable(self):
|
||||
# Arrange
|
||||
test_artist = self.network.get_artist("Test Artist")
|
||||
artist = test_artist.get_similar(limit=2)[0].item
|
||||
self.assertIsInstance(artist, pylast.Artist)
|
||||
assert isinstance(artist, pylast.Artist)
|
||||
|
||||
# Act/Assert
|
||||
self.helper_is_thing_hashable(artist)
|
||||
|
@ -38,8 +36,8 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
bio = artist.get_bio_published_date()
|
||||
|
||||
# Assert
|
||||
self.assertIsNotNone(bio)
|
||||
self.assertGreaterEqual(len(bio), 1)
|
||||
assert bio is not None
|
||||
assert len(bio) >= 1
|
||||
|
||||
def test_bio_content(self):
|
||||
# Arrange
|
||||
|
@ -49,8 +47,8 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
bio = artist.get_bio_content(language="en")
|
||||
|
||||
# Assert
|
||||
self.assertIsNotNone(bio)
|
||||
self.assertGreaterEqual(len(bio), 1)
|
||||
assert bio is not None
|
||||
assert len(bio) >= 1
|
||||
|
||||
def test_bio_content_none(self):
|
||||
# Arrange
|
||||
|
@ -61,7 +59,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
bio = artist.get_bio_content()
|
||||
|
||||
# Assert
|
||||
self.assertIsNone(bio)
|
||||
assert bio is None
|
||||
|
||||
def test_bio_summary(self):
|
||||
# Arrange
|
||||
|
@ -71,8 +69,8 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
bio = artist.get_bio_summary(language="en")
|
||||
|
||||
# Assert
|
||||
self.assertIsNotNone(bio)
|
||||
self.assertGreaterEqual(len(bio), 1)
|
||||
assert bio is not None
|
||||
assert len(bio) >= 1
|
||||
|
||||
def test_artist_top_tracks(self):
|
||||
# Arrange
|
||||
|
@ -106,7 +104,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
things = artist.get_top_albums(limit=limit)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(len(things), 1)
|
||||
assert len(things) == 1
|
||||
|
||||
def test_artist_top_albums_limit_50(self):
|
||||
# Arrange
|
||||
|
@ -118,7 +116,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
things = artist.get_top_albums(limit=limit)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(len(things), 50)
|
||||
assert len(things) == 50
|
||||
|
||||
def test_artist_top_albums_limit_100(self):
|
||||
# Arrange
|
||||
|
@ -130,7 +128,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
things = artist.get_top_albums(limit=limit)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(len(things), 100)
|
||||
assert len(things) == 100
|
||||
|
||||
def test_artist_listener_count(self):
|
||||
# Arrange
|
||||
|
@ -140,8 +138,8 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
count = artist.get_listener_count()
|
||||
|
||||
# Assert
|
||||
self.assertIsInstance(count, int)
|
||||
self.assertGreater(count, 0)
|
||||
assert isinstance(count, int)
|
||||
assert count > 0
|
||||
|
||||
def test_tag_artist(self):
|
||||
# Arrange
|
||||
|
@ -153,13 +151,13 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
|
||||
# Assert
|
||||
tags = artist.get_tags()
|
||||
self.assertGreater(len(tags), 0)
|
||||
assert len(tags) > 0
|
||||
found = False
|
||||
for tag in tags:
|
||||
if tag.name == "testing":
|
||||
found = True
|
||||
break
|
||||
self.assertTrue(found)
|
||||
assert found
|
||||
|
||||
def test_remove_tag_of_type_text(self):
|
||||
# Arrange
|
||||
|
@ -177,7 +175,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
if tag.name == "testing":
|
||||
found = True
|
||||
break
|
||||
self.assertFalse(found)
|
||||
assert not found
|
||||
|
||||
def test_remove_tag_of_type_tag(self):
|
||||
# Arrange
|
||||
|
@ -195,7 +193,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
if tag.name == "testing":
|
||||
found = True
|
||||
break
|
||||
self.assertFalse(found)
|
||||
assert not found
|
||||
|
||||
def test_remove_tags(self):
|
||||
# Arrange
|
||||
|
@ -210,15 +208,15 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
|
||||
# Assert
|
||||
tags_after = artist.get_tags()
|
||||
self.assertEqual(len(tags_after), len(tags_before) - 2)
|
||||
assert len(tags_after) == len(tags_before) - 2
|
||||
found1, found2 = False, False
|
||||
for tag in tags_after:
|
||||
if tag.name == "removetag1":
|
||||
found1 = True
|
||||
elif tag.name == "removetag2":
|
||||
found2 = True
|
||||
self.assertFalse(found1)
|
||||
self.assertFalse(found2)
|
||||
assert not found1
|
||||
assert not found2
|
||||
|
||||
def test_set_tags(self):
|
||||
# Arrange
|
||||
|
@ -233,16 +231,16 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
|
||||
# Assert
|
||||
tags_after = artist.get_tags()
|
||||
self.assertNotEqual(tags_before, tags_after)
|
||||
self.assertEqual(len(tags_after), 2)
|
||||
assert tags_before != tags_after
|
||||
assert len(tags_after) == 2
|
||||
found1, found2 = False, False
|
||||
for tag in tags_after:
|
||||
if tag.name == "settag1":
|
||||
found1 = True
|
||||
elif tag.name == "settag2":
|
||||
found2 = True
|
||||
self.assertTrue(found1)
|
||||
self.assertTrue(found2)
|
||||
assert found1
|
||||
assert found2
|
||||
|
||||
def test_artists(self):
|
||||
# Arrange
|
||||
|
@ -259,13 +257,13 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
name_cap = artist1.get_name(properly_capitalized=True)
|
||||
|
||||
# Assert
|
||||
self.assertIn("https", image)
|
||||
self.assertGreater(playcount, 1)
|
||||
self.assertNotEqual(artist1, artist2)
|
||||
self.assertEqual(name.lower(), name_cap.lower())
|
||||
self.assertEqual(url, "https://www.last.fm/music/radiohead")
|
||||
self.assertEqual(mbid, "a74b1b7f-71a5-4011-9441-d0b5e4122711")
|
||||
self.assertIsInstance(streamable, bool)
|
||||
assert "https" in image
|
||||
assert playcount > 1
|
||||
assert artist1 != artist2
|
||||
assert name.lower() == name_cap.lower()
|
||||
assert url == "https://www.last.fm/music/radiohead"
|
||||
assert mbid == "a74b1b7f-71a5-4011-9441-d0b5e4122711"
|
||||
assert isinstance(streamable, bool)
|
||||
|
||||
def test_artist_eq_none_is_false(self):
|
||||
# Arrange
|
||||
|
@ -273,7 +271,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
artist2 = pylast.Artist("Test Artist", self.network)
|
||||
|
||||
# Act / Assert
|
||||
self.assertNotEqual(artist1, artist2)
|
||||
assert artist1 != artist2
|
||||
|
||||
def test_artist_ne_none_is_true(self):
|
||||
# Arrange
|
||||
|
@ -281,7 +279,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
artist2 = pylast.Artist("Test Artist", self.network)
|
||||
|
||||
# Act / Assert
|
||||
self.assertNotEqual(artist1, artist2)
|
||||
assert artist1 != artist2
|
||||
|
||||
def test_artist_get_correction(self):
|
||||
# Arrange
|
||||
|
@ -291,7 +289,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
corrected_artist_name = artist.get_correction()
|
||||
|
||||
# Assert
|
||||
self.assertEqual(corrected_artist_name, "Guns N' Roses")
|
||||
assert corrected_artist_name == "Guns N' Roses"
|
||||
|
||||
@pytest.mark.xfail
|
||||
def test_get_userplaycount(self):
|
||||
|
@ -302,8 +300,4 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
playcount = artist.get_userplaycount()
|
||||
|
||||
# Assert
|
||||
self.assertGreaterEqual(playcount, 0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(failfast=True)
|
||||
assert playcount >= 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue