mopidy/tests/core/test_history.py
Bjørnar Snoksrud 1eb41aca7d tests: fix test breakage due to promotion from int to long
This fixes #1240.

In internals/path.py. there is a snippet of code that multiples mtime
for a file with 1000, and then casting it to `int`, to return the number
of milliseconds since epoch (or whatever). This will, however, not
ensure that the result is an `int`.

>>> type(int(2**32))
<type 'long'>

Instead, fix the tests to look for (int, long), and clarify the
implementation.

This bug found on a 32-bit VM :)
2015-08-05 22:38:21 +02:00

48 lines
1.5 KiB
Python

from __future__ import absolute_import, unicode_literals
import unittest
from mopidy.core import HistoryController
from mopidy.models import Artist, Track
class PlaybackHistoryTest(unittest.TestCase):
def setUp(self): # noqa: N802
self.tracks = [
Track(uri='dummy1:a', name='foo',
artists=[Artist(name='foober'), Artist(name='barber')]),
Track(uri='dummy2:a', name='foo'),
Track(uri='dummy3:a', name='bar')
]
self.history = HistoryController()
def test_add_track(self):
self.history._add_track(self.tracks[0])
self.assertEqual(self.history.get_length(), 1)
self.history._add_track(self.tracks[1])
self.assertEqual(self.history.get_length(), 2)
self.history._add_track(self.tracks[2])
self.assertEqual(self.history.get_length(), 3)
def test_non_tracks_are_rejected(self):
with self.assertRaises(TypeError):
self.history._add_track(object())
self.assertEqual(self.history.get_length(), 0)
def test_history_entry_contents(self):
track = self.tracks[0]
self.history._add_track(track)
result = self.history.get_history()
(timestamp, ref) = result[0]
self.assertIsInstance(timestamp, (int, long))
self.assertEqual(track.uri, ref.uri)
self.assertIn(track.name, ref.name)
for artist in track.artists:
self.assertIn(artist.name, ref.name)