Fix UnicodeDecodeError from #114. Replace definitions of _unicode and
_string. Add six as a dependeny. Fix clonedigger script.
This commit is contained in:
parent
1f9ebb530a
commit
df75cf2aa2
1
.dir-locals.el
Normal file
1
.dir-locals.el
Normal file
|
@ -0,0 +1 @@
|
||||||
|
((nil . ((pytest-global-name . "source secrets.sh && tox -e py34 --"))))
|
3
clonedigger.sh
Executable file
3
clonedigger.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
clonedigger pylast
|
||||||
|
! grep -E "Clones detected\|lines are duplicates" output.html
|
|
@ -37,6 +37,8 @@ import collections
|
||||||
import warnings
|
import warnings
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
|
|
||||||
def _deprecation_warning(message):
|
def _deprecation_warning(message):
|
||||||
warnings.warn(message, DeprecationWarning)
|
warnings.warn(message, DeprecationWarning)
|
||||||
|
@ -1910,9 +1912,12 @@ class Artist(_BaseObject, _Taggable):
|
||||||
return "pylast.Artist(%s, %s)" % (
|
return "pylast.Artist(%s, %s)" % (
|
||||||
repr(self.get_name()), repr(self.network))
|
repr(self.get_name()), repr(self.network))
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return six.text_type(self.get_name())
|
||||||
|
|
||||||
@_string_output
|
@_string_output
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.get_name()
|
return self.__unicode__()
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if type(self) is type(other):
|
if type(self) is type(other):
|
||||||
|
@ -3966,40 +3971,22 @@ def md5(text):
|
||||||
|
|
||||||
|
|
||||||
def _unicode(text):
|
def _unicode(text):
|
||||||
if sys.version_info[0] == 3:
|
if isinstance(text, six.binary_type):
|
||||||
if type(text) in (bytes, bytearray):
|
return six.text_type(text, "utf-8")
|
||||||
return str(text, "utf-8")
|
elif isinstance(text, six.text_type):
|
||||||
elif type(text) == str:
|
return text
|
||||||
return text
|
else:
|
||||||
else:
|
return six.text_type(text)
|
||||||
return str(text)
|
|
||||||
|
|
||||||
elif sys.version_info[0] == 2:
|
|
||||||
if type(text) in (str,):
|
|
||||||
return unicode(text, "utf-8")
|
|
||||||
elif type(text) == unicode:
|
|
||||||
return text
|
|
||||||
else:
|
|
||||||
return unicode(text)
|
|
||||||
|
|
||||||
|
|
||||||
def _string(text):
|
def _string(string):
|
||||||
"""For Python2 routines that can only process str type."""
|
"""For Python2 routines that can only process str type."""
|
||||||
|
if isinstance(string, str):
|
||||||
if sys.version_info[0] == 3:
|
return string
|
||||||
if type(text) != str:
|
casted = six.text_type(string)
|
||||||
return str(text)
|
if sys.version_info[0] == 2:
|
||||||
else:
|
casted = casted.encode("utf-8")
|
||||||
return text
|
return casted
|
||||||
|
|
||||||
elif sys.version_info[0] == 2:
|
|
||||||
if type(text) == str:
|
|
||||||
return text
|
|
||||||
|
|
||||||
if type(text) == int:
|
|
||||||
return str(text)
|
|
||||||
|
|
||||||
return text.encode("utf-8")
|
|
||||||
|
|
||||||
|
|
||||||
def _collect_nodes(limit, sender, method_name, cacheable, params=None):
|
def _collect_nodes(limit, sender, method_name, cacheable, params=None):
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -8,6 +8,7 @@ setup(
|
||||||
name="pylast",
|
name="pylast",
|
||||||
version="1.0.0",
|
version="1.0.0",
|
||||||
author="Amr Hassan <amr.hassan@gmail.com>",
|
author="Amr Hassan <amr.hassan@gmail.com>",
|
||||||
|
install_requires=['six'],
|
||||||
tests_require=['mock', 'pytest', 'coverage', 'pep8', 'pyyaml', 'pyflakes'],
|
tests_require=['mock', 'pytest', 'coverage', 'pep8', 'pyyaml', 'pyflakes'],
|
||||||
description=("A Python interface to Last.fm "
|
description=("A Python interface to Last.fm "
|
||||||
"(and other API compatible social networks)"),
|
"(and other API compatible social networks)"),
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import mock
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
import pylast
|
|
||||||
|
|
||||||
|
|
||||||
def mock_network():
|
|
||||||
return mock.Mock(
|
|
||||||
_get_ws_auth=mock.Mock(return_value=("", "", ""))
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('unicode_artist', [u'\xe9lafdasfdsafdsa', u'ééééééé'])
|
|
||||||
def test_get_cache_key(unicode_artist):
|
|
||||||
request = pylast._Request(mock_network(), 'some_method',
|
|
||||||
params={'artist': unicode_artist})
|
|
||||||
request._get_cache_key()
|
|
28
tests/unicode_test.py
Normal file
28
tests/unicode_test.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import mock
|
||||||
|
import pytest
|
||||||
|
import six
|
||||||
|
|
||||||
|
import pylast
|
||||||
|
|
||||||
|
|
||||||
|
def mock_network():
|
||||||
|
return mock.Mock(
|
||||||
|
_get_ws_auth=mock.Mock(return_value=("", "", ""))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('artist', [
|
||||||
|
u'\xe9lafdasfdsafdsa', u'ééééééé',
|
||||||
|
pylast.Artist(u'B\xe9l', mock_network()),
|
||||||
|
'fdasfdsafsaf not unicode',
|
||||||
|
])
|
||||||
|
def test_get_cache_key(artist):
|
||||||
|
request = pylast._Request(mock_network(), 'some_method',
|
||||||
|
params={'artist': artist})
|
||||||
|
request._get_cache_key()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('obj', [pylast.Artist(u'B\xe9l', mock_network())])
|
||||||
|
def test_cast(obj):
|
||||||
|
assert type(six.text_type(obj)) is six.text_type
|
3
tox.ini
3
tox.ini
|
@ -8,6 +8,7 @@ deps =
|
||||||
pyyaml
|
pyyaml
|
||||||
pytest
|
pytest
|
||||||
mock
|
mock
|
||||||
|
ipdb
|
||||||
pytest-cov
|
pytest-cov
|
||||||
commands = py.test -v --cov pylast --cov-report term-missing {posargs}
|
commands = py.test -v --cov pylast --cov-report term-missing {posargs}
|
||||||
|
|
||||||
|
@ -27,4 +28,4 @@ commands =
|
||||||
pyflakes tests
|
pyflakes tests
|
||||||
pep8 pylast
|
pep8 pylast
|
||||||
pep8 tests
|
pep8 tests
|
||||||
clonedigger pylast -o /dev/stdout | grep -E "Clones detected\|lines are duplicates"
|
./clonedigger.sh
|
Loading…
Reference in a new issue