Skip to content
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

Python 3.12 unittest fixes. #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
strategy:
matrix:
python-version: ['2.7', '3.6', '3.8', '3.9', '3.10']
python-version: ['2.7', '3.6', '3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
Expand Down
182 changes: 91 additions & 91 deletions mygpoclient/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class Test_SubscriptionChanges(unittest.TestCase):

def test_initSetsCorrectAttributes(self):
changes = api.SubscriptionChanges(self.ADD, self.REMOVE, self.SINCE)
self.assertEquals(changes.add, self.ADD)
self.assertEquals(changes.remove, self.REMOVE)
self.assertEquals(changes.since, self.SINCE)
self.assertEqual(changes.add, self.ADD)
self.assertEqual(changes.remove, self.REMOVE)
self.assertEqual(changes.since, self.SINCE)


class Test_EpisodeActionChanges(unittest.TestCase):
Expand All @@ -63,19 +63,19 @@ class Test_EpisodeActionChanges(unittest.TestCase):

def test_initSetsCorrectAttributes(self):
changes = api.EpisodeActionChanges(self.ACTIONS, self.SINCE)
self.assertEquals(changes.actions, self.ACTIONS)
self.assertEquals(changes.since, self.SINCE)
self.assertEqual(changes.actions, self.ACTIONS)
self.assertEqual(changes.since, self.SINCE)


class Test_PodcastDevice(unittest.TestCase):
CAPTION = 'My Nice Device'

def test_initSetsCorrectAttributes(self):
device = api.PodcastDevice(DEVICE_ID_1, self.CAPTION, 'mobile', 42)
self.assertEquals(device.device_id, DEVICE_ID_1)
self.assertEquals(device.caption, self.CAPTION)
self.assertEquals(device.type, 'mobile')
self.assertEquals(device.subscriptions, 42)
self.assertEqual(device.device_id, DEVICE_ID_1)
self.assertEqual(device.caption, self.CAPTION)
self.assertEqual(device.type, 'mobile')
self.assertEqual(device.subscriptions, 42)

def test_invalidDeviceType_raisesValueError(self):
self.assertRaises(ValueError,
Expand All @@ -98,14 +98,14 @@ def test_initSetsCorrectAttributes(self):
action = api.EpisodeAction(FEED_URL_1, EPISODE_URL_1, 'play',
DEVICE_ID_1, self.XML_TIMESTAMP, self.VALID_STARTED,
self.VALID_POSITION, self.VALID_TOTAL)
self.assertEquals(action.podcast, FEED_URL_1)
self.assertEquals(action.episode, EPISODE_URL_1)
self.assertEquals(action.action, 'play')
self.assertEquals(action.device, DEVICE_ID_1)
self.assertEquals(action.timestamp, self.XML_TIMESTAMP)
self.assertEquals(action.started, self.VALID_STARTED)
self.assertEquals(action.position, self.VALID_POSITION)
self.assertEquals(action.total, self.VALID_TOTAL)
self.assertEqual(action.podcast, FEED_URL_1)
self.assertEqual(action.episode, EPISODE_URL_1)
self.assertEqual(action.action, 'play')
self.assertEqual(action.device, DEVICE_ID_1)
self.assertEqual(action.timestamp, self.XML_TIMESTAMP)
self.assertEqual(action.started, self.VALID_STARTED)
self.assertEqual(action.position, self.VALID_POSITION)
self.assertEqual(action.total, self.VALID_TOTAL)

def test_invalidAction_raisesValueError(self):
self.assertRaises(ValueError,
Expand Down Expand Up @@ -155,36 +155,36 @@ def test_invalidTotalFormat_raisesValueError(self):
def test_toDictionary_containsMandatoryAttributes(self):
action = api.EpisodeAction(FEED_URL_1, EPISODE_URL_1, 'play')
dictionary = action.to_dictionary()
self.assertEquals(len(list(dictionary.keys())), 3)
self.assert_('podcast' in dictionary)
self.assert_('episode' in dictionary)
self.assert_('action' in dictionary)
self.assertEquals(dictionary['podcast'], FEED_URL_1)
self.assertEquals(dictionary['episode'], EPISODE_URL_1)
self.assertEquals(dictionary['action'], 'play')
self.assertEqual(len(list(dictionary.keys())), 3)
self.assertTrue('podcast' in dictionary)
self.assertTrue('episode' in dictionary)
self.assertTrue('action' in dictionary)
self.assertEqual(dictionary['podcast'], FEED_URL_1)
self.assertEqual(dictionary['episode'], EPISODE_URL_1)
self.assertEqual(dictionary['action'], 'play')

def test_toDictionary_containsAllAttributes(self):
action = api.EpisodeAction(FEED_URL_3, EPISODE_URL_4, 'play',
DEVICE_ID_1, self.XML_TIMESTAMP, self.VALID_STARTED,
self.VALID_POSITION, self.VALID_TOTAL)
dictionary = action.to_dictionary()
self.assertEquals(len(list(dictionary.keys())), 8)
self.assert_('podcast' in dictionary)
self.assert_('episode' in dictionary)
self.assert_('action' in dictionary)
self.assert_('device' in dictionary)
self.assert_('timestamp' in dictionary)
self.assert_('started' in dictionary)
self.assert_('position' in dictionary)
self.assert_('total' in dictionary)
self.assertEquals(dictionary['podcast'], FEED_URL_3)
self.assertEquals(dictionary['episode'], EPISODE_URL_4)
self.assertEquals(dictionary['action'], 'play')
self.assertEquals(dictionary['device'], DEVICE_ID_1)
self.assertEquals(dictionary['timestamp'], self.XML_TIMESTAMP)
self.assertEquals(dictionary['started'], self.VALID_STARTED)
self.assertEquals(dictionary['position'], self.VALID_POSITION)
self.assertEquals(dictionary['total'], self.VALID_TOTAL)
self.assertEqual(len(list(dictionary.keys())), 8)
self.assertTrue('podcast' in dictionary)
self.assertTrue('episode' in dictionary)
self.assertTrue('action' in dictionary)
self.assertTrue('device' in dictionary)
self.assertTrue('timestamp' in dictionary)
self.assertTrue('started' in dictionary)
self.assertTrue('position' in dictionary)
self.assertTrue('total' in dictionary)
self.assertEqual(dictionary['podcast'], FEED_URL_3)
self.assertEqual(dictionary['episode'], EPISODE_URL_4)
self.assertEqual(dictionary['action'], 'play')
self.assertEqual(dictionary['device'], DEVICE_ID_1)
self.assertEqual(dictionary['timestamp'], self.XML_TIMESTAMP)
self.assertEqual(dictionary['started'], self.VALID_STARTED)
self.assertEqual(dictionary['position'], self.VALID_POSITION)
self.assertEqual(dictionary['total'], self.VALID_TOTAL)


class Test_MygPodderClient(unittest.TestCase):
Expand Down Expand Up @@ -223,13 +223,13 @@ def set_http_response_value(self, value):
self.fake_client.response_value = value

def assert_http_request_count(self, count):
self.assertEquals(len(self.fake_client.requests), count)
self.assertEqual(len(self.fake_client.requests), count)

def has_put_json_data(self, data, required_method='PUT'):
"""Returns True if the FakeJsonClient has received the given data"""
for method, uri, sent in self.fake_client.requests:
if method == required_method:
self.assertEquals(sent, data)
self.assertEqual(sent, data)
return True

return False
Expand All @@ -241,17 +241,17 @@ def has_posted_json_data(self, data):
def test_getSubscriptions_withPodcastDevice(self):
self.set_http_response_value(b'[]')
device = api.PodcastDevice('manatee', 'My Device', 'mobile', 20)
self.assertEquals(self.client.get_subscriptions(device), [])
self.assertEqual(self.client.get_subscriptions(device), [])
self.assert_http_request_count(1)

def test_putSubscriptions_withPodcastDevice(self):
self.set_http_response_value(b'')
device = api.PodcastDevice('manatee', 'My Device', 'mobile', 20)
self.assertEquals(
self.assertEqual(
self.client.put_subscriptions(
device, self.ADD), True)
self.assert_http_request_count(1)
self.assert_(self.has_put_json_data(self.ADD))
self.assertTrue(self.has_put_json_data(self.ADD))

def test_updateSubscriptions_raisesValueError_onInvalidAddList(self):
self.assertRaises(ValueError,
Expand Down Expand Up @@ -334,12 +334,12 @@ def test_updateSubscriptions_returnsUpdateResult(self):
result = self.client.update_subscriptions(DEVICE_ID_1,
self.ADD, self.REMOVE)
# result is a UpdateResult object
self.assert_(hasattr(result, 'since'))
self.assert_(hasattr(result, 'update_urls'))
self.assertEquals(result.since, self.SINCE)
self.assertEquals(result.update_urls, update_urls_expected)
self.assertTrue(hasattr(result, 'since'))
self.assertTrue(hasattr(result, 'update_urls'))
self.assertEqual(result.since, self.SINCE)
self.assertEqual(result.update_urls, update_urls_expected)
self.assert_http_request_count(1)
self.assert_(self.has_posted_json_data(self.ADD_REMOVE_AS_JSON_UPLOAD))
self.assertTrue(self.has_posted_json_data(self.ADD_REMOVE_AS_JSON_UPLOAD))

def test_pullSubscriptions_raisesInvalidResponse_onEmptyResponse(self):
self.set_http_response_value(b'')
Expand Down Expand Up @@ -442,9 +442,9 @@ def test_pullSubscriptions_returnsChangesListAndTimestamp(self):
"timestamp": 1262103016}
""")
changes = self.client.pull_subscriptions(DEVICE_ID_2)
self.assertEquals(changes.add, [FEED_URL_1, FEED_URL_2])
self.assertEquals(changes.remove, [FEED_URL_3, FEED_URL_4])
self.assertEquals(changes.since, self.SINCE)
self.assertEqual(changes.add, [FEED_URL_1, FEED_URL_2])
self.assertEqual(changes.remove, [FEED_URL_3, FEED_URL_4])
self.assertEqual(changes.since, self.SINCE)
self.assert_http_request_count(1)

def test_uploadEpisodeActions_raisesInvalidResponse_onEmptyResponse(self):
Expand All @@ -471,9 +471,9 @@ def test_uploadEpisodeActions_returnsTimestamp(self):
{"timestamp": 1262103016}
""")
result = self.client.upload_episode_actions(self.ACTIONS)
self.assertEquals(result, self.SINCE)
self.assertEqual(result, self.SINCE)
self.assert_http_request_count(1)
self.assert_(self.has_posted_json_data(self.ACTIONS_AS_JSON_UPLOAD))
self.assertTrue(self.has_posted_json_data(self.ACTIONS_AS_JSON_UPLOAD))

def test_downloadEpisodeActions_raisesInvalidResponse_onEmptyResponse(
self):
Expand Down Expand Up @@ -535,47 +535,47 @@ def test_downloadEpisodeActions_returnsActionList(self):
], "timestamp": 1262103016}
""")
changes = self.client.download_episode_actions()
self.assertEquals(len(changes.actions), 2)
self.assertEqual(len(changes.actions), 2)
action1, action2 = changes.actions
self.assertEquals(action1.podcast, 'a')
self.assertEquals(action1.episode, 'b')
self.assertEquals(action1.action, 'download')
self.assertEquals(action2.podcast, 'x')
self.assertEquals(action2.episode, 'y')
self.assertEquals(action2.action, 'play')
self.assertEquals(changes.since, self.SINCE)
self.assertEqual(action1.podcast, 'a')
self.assertEqual(action1.episode, 'b')
self.assertEqual(action1.action, 'download')
self.assertEqual(action2.podcast, 'x')
self.assertEqual(action2.episode, 'y')
self.assertEqual(action2.action, 'play')
self.assertEqual(changes.since, self.SINCE)
self.assert_http_request_count(1)

def test_updateDeviceSettings_withNothing(self):
self.set_http_response_value(b'')
result = self.client.update_device_settings(DEVICE_ID_1)
self.assertEquals(result, True)
self.assertEqual(result, True)
self.assert_http_request_count(1)
self.assert_(self.has_posted_json_data({}))
self.assertTrue(self.has_posted_json_data({}))

def test_updateDeviceSettings_withCaption(self):
self.set_http_response_value(b'')
result = self.client.update_device_settings(DEVICE_ID_1,
caption='Poodonkis')
self.assertEquals(result, True)
self.assertEqual(result, True)
self.assert_http_request_count(1)
self.assert_(self.has_posted_json_data({'caption': 'Poodonkis'}))
self.assertTrue(self.has_posted_json_data({'caption': 'Poodonkis'}))

def test_updateDeviceSettings_withType(self):
self.set_http_response_value(b'')
result = self.client.update_device_settings(DEVICE_ID_1,
type='desktop')
self.assertEquals(result, True)
self.assertEqual(result, True)
self.assert_http_request_count(1)
self.assert_(self.has_posted_json_data({'type': 'desktop'}))
self.assertTrue(self.has_posted_json_data({'type': 'desktop'}))

def test_updateDeviceSettings_withCaptionAndType(self):
self.set_http_response_value(b'')
result = self.client.update_device_settings(DEVICE_ID_1,
'My Unit Testing Device', 'desktop')
self.assertEquals(result, True)
self.assertEqual(result, True)
self.assert_http_request_count(1)
self.assert_(self.has_posted_json_data({
self.assertTrue(self.has_posted_json_data({
'caption': 'My Unit Testing Device',
'type': 'desktop'}))

Expand Down Expand Up @@ -610,16 +610,16 @@ def test_getDevices_returnsDeviceList(self):
]
""")
devices = self.client.get_devices()
self.assertEquals(len(devices), 2)
self.assertEqual(len(devices), 2)
device1, device2 = devices
self.assertEquals(device1.device_id, DEVICE_ID_1)
self.assertEquals(device1.caption, 'Phone')
self.assertEquals(device1.type, 'mobile')
self.assertEquals(device1.subscriptions, 42)
self.assertEquals(device2.device_id, DEVICE_ID_2)
self.assertEquals(device2.caption, 'The Lappy')
self.assertEquals(device2.type, 'laptop')
self.assertEquals(device2.subscriptions, 4711)
self.assertEqual(device1.device_id, DEVICE_ID_1)
self.assertEqual(device1.caption, 'Phone')
self.assertEqual(device1.type, 'mobile')
self.assertEqual(device1.subscriptions, 42)
self.assertEqual(device2.device_id, DEVICE_ID_2)
self.assertEqual(device2.caption, 'The Lappy')
self.assertEqual(device2.type, 'laptop')
self.assertEqual(device2.subscriptions, 4711)
self.assert_http_request_count(1)

def test_getFavoriteEpisodes_returnsEpisodeList(self):
Expand All @@ -644,24 +644,24 @@ def test_getFavoriteEpisodes_returnsEpisodeList(self):
]
""")
favorites = self.client.get_favorite_episodes()
self.assertEquals(len(favorites), 2)
self.assertEqual(len(favorites), 2)
episode1, episode2 = favorites
self.assertEquals(episode1.title, 'TWiT 245: No Hitler For You')
self.assertEquals(
self.assertEqual(episode1.title, 'TWiT 245: No Hitler For You')
self.assertEqual(
episode1.url,
'http://www.podtrac.com/pts/redirect.mp3/aolradio.podcast.aol.com/twit/twit0245.mp3')
self.assertEquals(
self.assertEqual(
episode1.podcast_title,
'this WEEK in TECH - MP3 Edition')
self.assertEquals(episode1.podcast_url, 'http://leo.am/podcasts/twit')
self.assertEquals(episode1.description, '[...]')
self.assertEquals(
self.assertEqual(episode1.podcast_url, 'http://leo.am/podcasts/twit')
self.assertEqual(episode1.description, '[...]')
self.assertEqual(
episode1.website,
'http://www.podtrac.com/pts/redirect.mp3/aolradio.podcast.aol.com/twit/twit0245.mp3')
self.assertEquals(episode1.released, '2010-12-25T00:30:00')
self.assertEquals(
self.assertEqual(episode1.released, '2010-12-25T00:30:00')
self.assertEqual(
episode1.mygpo_link,
'http://gpodder.net/episode/1046492')
self.assertEquals(
self.assertEqual(
episode2.website,
'http://feedproxy.google.com/~r/coverville/~3/5UK8-PZmmMQ/')
12 changes: 6 additions & 6 deletions mygpoclient/http_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ def test_BadRequest(self):
def test_GET(self):
client = HttpClient()
path = self.URI_BASE + '/noauth'
self.assertEquals(client.GET(path), self.RESPONSE)
self.assertEqual(client.GET(path), self.RESPONSE)

def test_authenticated_GET(self):
client = HttpClient(self.USERNAME, self.PASSWORD)
path = self.URI_BASE + '/auth'
self.assertEquals(client.GET(path), self.RESPONSE)
self.assertEqual(client.GET(path), self.RESPONSE)

def test_unauthenticated_GET(self):
client = HttpClient()
Expand All @@ -186,15 +186,15 @@ def test_unauthenticated_GET(self):
def test_POST(self):
client = HttpClient()
path = self.URI_BASE + '/noauth'
self.assertEquals(
self.assertEqual(
client.POST(
path, self.DUMMYDATA), codecs.encode(
self.DUMMYDATA.decode('utf-8'), 'rot-13').encode('utf-8'))

def test_authenticated_POST(self):
client = HttpClient(self.USERNAME, self.PASSWORD)
path = self.URI_BASE + '/auth'
self.assertEquals(
self.assertEqual(
client.POST(
path, self.DUMMYDATA), codecs.encode(
self.DUMMYDATA.decode('utf-8'), 'rot-13').encode('utf-8'))
Expand All @@ -207,14 +207,14 @@ def test_unauthenticated_POST(self):
def test_PUT(self):
client = HttpClient()
path = self.URI_BASE + '/noauth'
self.assertEquals(client.PUT(path, self.DUMMYDATA), b'PUT OK')
self.assertEqual(client.PUT(path, self.DUMMYDATA), b'PUT OK')

def test_GET_after_PUT(self):
client = HttpClient()
for i in range(10):
path = self.URI_BASE + '/file.%(i)d.txt' % locals()
client.PUT(path, self.RESPONSE + str(i).encode('utf-8'))
self.assertEquals(
self.assertEqual(
client.GET(path),
self.RESPONSE +
str(i).encode('utf-8'))
Loading