Replace unittest with pytest
This commit is contained in:
parent
1160ee1513
commit
aae4bb3693
10 changed files with 253 additions and 305 deletions
|
@ -5,7 +5,6 @@ Integration (not unit) tests for pylast.py
|
|||
import os
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
|
||||
import pylast
|
||||
import pytest
|
||||
|
@ -33,12 +32,12 @@ def load_secrets():
|
|||
return doc
|
||||
|
||||
|
||||
class PyLastTestCase(unittest.TestCase):
|
||||
class PyLastTestCase:
|
||||
def assert_startswith(self, str, prefix, start=None, end=None):
|
||||
self.assertTrue(str.startswith(prefix, start, end))
|
||||
assert str.startswith(prefix, start, end)
|
||||
|
||||
def assert_endswith(self, str, suffix, start=None, end=None):
|
||||
self.assertTrue(str.endswith(suffix, start, end))
|
||||
assert str.endswith(suffix, start, end)
|
||||
|
||||
|
||||
@flaky(max_runs=3, min_passes=1)
|
||||
|
@ -49,20 +48,21 @@ class TestPyLastWithLastFm(PyLastTestCase):
|
|||
def unix_timestamp(self):
|
||||
return int(time.time())
|
||||
|
||||
def setUp(self):
|
||||
if self.__class__.secrets is None:
|
||||
self.__class__.secrets = load_secrets()
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
if cls.secrets is None:
|
||||
cls.secrets = load_secrets()
|
||||
|
||||
self.username = self.__class__.secrets["username"]
|
||||
password_hash = self.__class__.secrets["password_hash"]
|
||||
cls.username = cls.secrets["username"]
|
||||
password_hash = cls.secrets["password_hash"]
|
||||
|
||||
api_key = self.__class__.secrets["api_key"]
|
||||
api_secret = self.__class__.secrets["api_secret"]
|
||||
api_key = cls.secrets["api_key"]
|
||||
api_secret = cls.secrets["api_secret"]
|
||||
|
||||
self.network = pylast.LastFMNetwork(
|
||||
cls.network = pylast.LastFMNetwork(
|
||||
api_key=api_key,
|
||||
api_secret=api_secret,
|
||||
username=self.username,
|
||||
username=cls.username,
|
||||
password_hash=password_hash,
|
||||
)
|
||||
|
||||
|
@ -74,19 +74,19 @@ class TestPyLastWithLastFm(PyLastTestCase):
|
|||
things.add(thing)
|
||||
|
||||
# Assert
|
||||
self.assertIsNotNone(thing)
|
||||
self.assertEqual(len(things), 1)
|
||||
assert thing is not None
|
||||
assert len(things) == 1
|
||||
|
||||
def helper_validate_results(self, a, b, c):
|
||||
# Assert
|
||||
self.assertIsNotNone(a)
|
||||
self.assertIsNotNone(b)
|
||||
self.assertIsNotNone(c)
|
||||
self.assertGreaterEqual(len(a), 0)
|
||||
self.assertGreaterEqual(len(b), 0)
|
||||
self.assertGreaterEqual(len(c), 0)
|
||||
self.assertEqual(a, b)
|
||||
self.assertEqual(b, c)
|
||||
assert a is not None
|
||||
assert b is not None
|
||||
assert c is not None
|
||||
assert len(a) >= 0
|
||||
assert len(b) >= 0
|
||||
assert len(c) >= 0
|
||||
assert a == b
|
||||
assert b == c
|
||||
|
||||
def helper_validate_cacheable(self, thing, function_name):
|
||||
# Arrange
|
||||
|
@ -103,35 +103,31 @@ class TestPyLastWithLastFm(PyLastTestCase):
|
|||
|
||||
def helper_at_least_one_thing_in_top_list(self, things, expected_type):
|
||||
# Assert
|
||||
self.assertGreater(len(things), 1)
|
||||
self.assertIsInstance(things, list)
|
||||
self.assertIsInstance(things[0], pylast.TopItem)
|
||||
self.assertIsInstance(things[0].item, expected_type)
|
||||
assert len(things) > 1
|
||||
assert isinstance(things, list)
|
||||
assert isinstance(things[0], pylast.TopItem)
|
||||
assert isinstance(things[0].item, expected_type)
|
||||
|
||||
def helper_only_one_thing_in_top_list(self, things, expected_type):
|
||||
# Assert
|
||||
self.assertEqual(len(things), 1)
|
||||
self.assertIsInstance(things, list)
|
||||
self.assertIsInstance(things[0], pylast.TopItem)
|
||||
self.assertIsInstance(things[0].item, expected_type)
|
||||
assert len(things) == 1
|
||||
assert isinstance(things, list)
|
||||
assert isinstance(things[0], pylast.TopItem)
|
||||
assert isinstance(things[0].item, expected_type)
|
||||
|
||||
def helper_only_one_thing_in_list(self, things, expected_type):
|
||||
# Assert
|
||||
self.assertEqual(len(things), 1)
|
||||
self.assertIsInstance(things, list)
|
||||
self.assertIsInstance(things[0], expected_type)
|
||||
assert len(things) == 1
|
||||
assert isinstance(things, list)
|
||||
assert isinstance(things[0], expected_type)
|
||||
|
||||
def helper_two_different_things_in_top_list(self, things, expected_type):
|
||||
# Assert
|
||||
self.assertEqual(len(things), 2)
|
||||
assert len(things) == 2
|
||||
thing1 = things[0]
|
||||
thing2 = things[1]
|
||||
self.assertIsInstance(thing1, pylast.TopItem)
|
||||
self.assertIsInstance(thing2, pylast.TopItem)
|
||||
self.assertIsInstance(thing1.item, expected_type)
|
||||
self.assertIsInstance(thing2.item, expected_type)
|
||||
self.assertNotEqual(thing1, thing2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(failfast=True)
|
||||
assert isinstance(thing1, pylast.TopItem)
|
||||
assert isinstance(thing2, pylast.TopItem)
|
||||
assert isinstance(thing1.item, expected_type)
|
||||
assert isinstance(thing2.item, expected_type)
|
||||
assert thing1 != thing2
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue