Merge pull request #111 from hugovk/master

PyPy3 / Scrutinizer / Landscape.io / tests
This commit is contained in:
Hugo 2015-01-06 11:59:18 +02:00
commit 123951517a
7 changed files with 44 additions and 52 deletions

1
.build
View file

@ -1 +0,0 @@
0

9
.scrutinizer.yml Normal file
View file

@ -0,0 +1,9 @@
checks:
python:
code_rating: true
duplicate_code: true
filter:
excluded_paths:
- '*/test/*'
tools:
external_code_coverage: true

View file

@ -5,17 +5,20 @@ python:
- "3.3" - "3.3"
- "3.4" - "3.4"
- "pypy" - "pypy"
- "pypy3"
sudo: false sudo: false
install: install:
- pip install -r test_requirements.txt - travis_retry pip install -r test_requirements.txt
- pip install coveralls - travis_retry pip install coveralls
script: coverage run --source=pylast ./test_pylast.py script: coverage run --source=pylast ./test_pylast.py
after_success: after_success:
coveralls - coveralls
- travis_retry pip install scrutinizer-ocular
- ocular
after_script: after_script:
- coverage report - coverage report
@ -36,4 +39,5 @@ matrix:
allow_failures: allow_failures:
- python: "3.4" - python: "3.4"
- python: "pypy" - python: "pypy"
- python: "pypy3"
fast_finish: true fast_finish: true

View file

@ -3,4 +3,3 @@ include setup.py
include README include README
include COPYING include COPYING
include INSTALL include INSTALL
include .build

View file

@ -312,9 +312,9 @@ class _Network(object):
if domain_language in self.domain_names: if domain_language in self.domain_names:
return self.domain_names[domain_language] return self.domain_names[domain_language]
def _get_url(self, domain, type): def _get_url(self, domain, url_type):
return "http://%s/%s" % ( return "http://%s/%s" % (
self._get_language_domain(domain), self.urls[type]) self._get_language_domain(domain), self.urls[url_type])
def _get_ws_auth(self): def _get_ws_auth(self):
""" """
@ -404,14 +404,14 @@ class _Network(object):
return seq return seq
def get_geo_events( def get_geo_events(
self, long=None, lat=None, location=None, distance=None, self, longitude=None, latitude=None, location=None, distance=None,
tag=None, festivalsonly=None, limit=None, cacheable=True): tag=None, festivalsonly=None, limit=None, cacheable=True):
""" """
Returns all events in a specific location by country or city name. Returns all events in a specific location by country or city name.
Parameters: Parameters:
long (Optional) : Specifies a longitude value to retrieve events for longitude (Optional) : Specifies a longitude value to retrieve events
(service returns nearby events by default) for (service returns nearby events by default)
lat (Optional) : Specifies a latitude value to retrieve events for latitude (Optional) : Specifies a latitude value to retrieve events for
(service returns nearby events by default) (service returns nearby events by default)
location (Optional) : Specifies a location to retrieve events for location (Optional) : Specifies a location to retrieve events for
(service returns nearby events by default) (service returns nearby events by default)
@ -426,10 +426,10 @@ class _Network(object):
params = {} params = {}
if long: if longitude:
params["long"] = long params["long"] = longitude
if lat: if latitude:
params["lat"] = lat params["lat"] = latitude
if location: if location:
params["location"] = location params["location"] = location
if limit: if limit:
@ -768,17 +768,17 @@ class _Network(object):
if remaining_tracks: if remaining_tracks:
self.scrobble_many(remaining_tracks) self.scrobble_many(remaining_tracks)
def get_play_links(self, type, things, cacheable=True): def get_play_links(self, link_type, things, cacheable=True):
method = type + ".getPlaylinks" method = link_type + ".getPlaylinks"
params = {} params = {}
for i, thing in enumerate(things): for i, thing in enumerate(things):
if type == "artist": if link_type == "artist":
params['artist[' + str(i) + ']'] = thing params['artist[' + str(i) + ']'] = thing
elif type == "album": elif link_type == "album":
params['artist[' + str(i) + ']'] = thing.artist params['artist[' + str(i) + ']'] = thing.artist
params['album[' + str(i) + ']'] = thing.title params['album[' + str(i) + ']'] = thing.title
elif type == "track": elif link_type == "track":
params['artist[' + str(i) + ']'] = thing.artist params['artist[' + str(i) + ']'] = thing.artist
params['track[' + str(i) + ']'] = thing.title params['track[' + str(i) + ']'] = thing.title
@ -793,13 +793,13 @@ class _Network(object):
return seq return seq
def get_artist_play_links(self, artists, cacheable=True): def get_artist_play_links(self, artists, cacheable=True):
return self.get_play_links("artist", artists) return self.get_play_links("artist", artists, cacheable)
def get_album_play_links(self, albums, cacheable=True): def get_album_play_links(self, albums, cacheable=True):
return self.get_play_links("album", albums) return self.get_play_links("album", albums, cacheable)
def get_track_play_links(self, tracks, cacheable=True): def get_track_play_links(self, tracks, cacheable=True):
return self.get_play_links("track", tracks) return self.get_play_links("track", tracks, cacheable)
class LastFMNetwork(_Network): class LastFMNetwork(_Network):
@ -1110,7 +1110,8 @@ class _Request(object):
if self.network.is_proxy_enabled(): if self.network.is_proxy_enabled():
conn = HTTPConnection( conn = HTTPConnection(
host=self.network._get_proxy()[0], port=self.network._get_proxy()[1]) host=self.network._get_proxy()[0],
port=self.network._get_proxy()[1])
try: try:
conn.request( conn.request(
@ -2717,7 +2718,7 @@ class Playlist(_BaseObject):
__hash__ = _BaseObject.__hash__ __hash__ = _BaseObject.__hash__
def __init__(self, user, id, network): def __init__(self, user, playlist_id, network):
_BaseObject.__init__(self, network, "playlist") _BaseObject.__init__(self, network, "playlist")
if isinstance(user, User): if isinstance(user, User):
@ -2725,7 +2726,7 @@ class Playlist(_BaseObject):
else: else:
self.user = User(user, self.network) self.user = User(user, self.network)
self.id = id self.id = playlist_id
@_string_output @_string_output
def __str__(self): def __str__(self):
@ -3897,10 +3898,10 @@ class Venue(_BaseObject):
__hash__ = _BaseObject.__hash__ __hash__ = _BaseObject.__hash__
def __init__(self, id, network, venue_element=None): def __init__(self, netword_id, network, venue_element=None):
_BaseObject.__init__(self, network, "venue") _BaseObject.__init__(self, network, "venue")
self.id = _number(id) self.id = _number(netword_id)
if venue_element is not None: if venue_element is not None:
self.info = _extract_element_tree(venue_element) self.info = _extract_element_tree(venue_element)
self.name = self.info.get('name') self.name = self.info.get('name')
@ -4213,7 +4214,7 @@ class _ScrobblerRequest(object):
def __init__(self, url, params, network, type="POST"): def __init__(self, url, params, network, type="POST"):
for key in params: for key in params:
params[key] = str(params[key]) params[key] = str(params[key])
self.params = params self.params = params
self.type = type self.type = type

View file

@ -2,30 +2,10 @@
from distutils.core import setup from distutils.core import setup
import os
def get_build():
path = "./.build"
if os.path.exists(path):
fp = open(path, "r")
build = eval(fp.read())
if os.path.exists("./.increase_build"):
build += 1
fp.close()
else:
build = 1
fp = open(path, "w")
fp.write(str(build))
fp.close()
return str(build)
setup( setup(
name="pylast", name="pylast",
version="1.0." + get_build(), version="1.0.0",
author="Amr Hassan <amr.hassan@gmail.com>", author="Amr Hassan <amr.hassan@gmail.com>",
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)"),

View file

@ -422,7 +422,7 @@ class TestPyLast(unittest.TestCase):
def test_playlist_is_hashable(self): def test_playlist_is_hashable(self):
# Arrange # Arrange
playlist = pylast.Playlist( playlist = pylast.Playlist(
user="RJ", id="1k1qp_doglist", network=self.network) user="RJ", playlist_id="1k1qp_doglist", network=self.network)
# Act/Assert # Act/Assert
self.helper_is_thing_hashable(playlist) self.helper_is_thing_hashable(playlist)
@ -870,7 +870,7 @@ class TestPyLast(unittest.TestCase):
# Arrange # Arrange
# Act # Act
events = self.network.get_geo_events( events = self.network.get_geo_events(
lat=53.466667, long=-2.233333, distance=5, limit=1) latitude=53.466667, longitude=-2.233333, distance=5, limit=1)
# Assert # Assert
self.assertEqual(len(events), 1) self.assertEqual(len(events), 1)