mopidy/tests/__init__.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

38 lines
805 B
Python

from __future__ import absolute_import, unicode_literals
import os
from mopidy import compat
def path_to_data_dir(name):
if not isinstance(name, bytes):
name = name.encode('utf-8')
path = os.path.dirname(__file__)
path = os.path.join(path, b'data')
path = os.path.abspath(path)
return os.path.join(path, name)
class IsA(object):
def __init__(self, klass):
self.klass = klass
def __eq__(self, rhs):
try:
return isinstance(rhs, self.klass)
except TypeError:
return type(rhs) == type(self.klass) # flake8: noqa
def __ne__(self, rhs):
return not self.__eq__(rhs)
def __repr__(self):
return str(self.klass)
any_int = IsA((int, long))
any_str = IsA(str)
any_unicode = IsA(compat.text_type)