Merge pull request #107 from hugovk/master

Fix comparison with None; fix tests; use Docker; badges
This commit is contained in:
Hugo 2014-12-26 17:07:42 +02:00
commit f74451a9af
5 changed files with 81 additions and 19 deletions

View file

@ -1,15 +1,22 @@
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "pypy"
sudo: false
install:
- pip install -r test_requirements.txt
- pip install coveralls
script: coverage run --source=pylast ./test_pylast.py
after_success:
coveralls
after_script:
- coverage report
- ./check.sh
@ -17,6 +24,7 @@ after_script:
- clonedigger pylast.py
- grep "Clones detected" output.html
- grep "lines are duplicates" output.html
env:
global:
- secure: ivg6II471E9HV8xyqnawLIuP/sZ0J63Y+BC0BQcRVKtLn/K3zmD1ozM3TFL9S549Nxd0FqDKHXJvXsgaTGIDpK8sxE2AMKV5IojyM0iAVuN7YjPK9vwSlRw1u0EysPMFqxOZVQnoDyHrSGIUrP/VMdnhBu6dbUX0FyEkvZshXhY=
@ -28,3 +36,4 @@ matrix:
allow_failures:
- python: "3.4"
- python: "pypy"
fast_finish: true

View file

@ -1,7 +1,7 @@
pyLast
======
[![Build Status](https://travis-ci.org/pylast/pylast.png?branch=master)](https://travis-ci.org/pylast/pylast) [![PyPI version](https://pypip.in/version/pylast/badge.svg)](https://pypi.python.org/pypi/pylast/) [![PyPI downloads](https://pypip.in/download/pylast/badge.svg)](https://pypi.python.org/pypi/pylast/) [![Coverage Status](https://coveralls.io/repos/pylast/pylast/badge.png?branch=master)](https://coveralls.io/r/pylast/pylast?branch=master)
[![Build Status](https://travis-ci.org/pylast/pylast.png?branch=master)](https://travis-ci.org/pylast/pylast) [![PyPI version](https://pypip.in/version/pylast/badge.svg)](https://pypi.python.org/pypi/pylast/) [![PyPI downloads](https://pypip.in/download/pylast/badge.svg)](https://pypi.python.org/pypi/pylast/) [![Coverage Status](https://coveralls.io/repos/pylast/pylast/badge.png?branch=master)](https://coveralls.io/r/pylast/pylast?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/hugovk/pylast/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/hugovk/pylast/?branch=master) [![Code Health](https://landscape.io/github/hugovk/pylast/master/landscape.svg)](https://landscape.io/github/hugovk/pylast/master)
A Python interface to [Last.fm](http://www.last.fm/) and other api-compatible websites such as [Libre.fm](http://libre.fm/).

View file

@ -4,6 +4,7 @@
# A Python interface to Last.fm (and other API compatible social networks)
#
# Copyright 2008-2010 Amr Hassan
# Copyright 2013-2014 hugovk
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -20,8 +21,8 @@
# http://code.google.com/p/pylast/
__version__ = '1.0.0'
__author__ = 'Amr Hassan'
__copyright__ = "Copyright (C) 2008-2010 Amr Hassan"
__author__ = 'Amr Hassan, hugovk'
__copyright__ = "Copyright (C) 2008-2010 Amr Hassan, 2013-2014 hugovk"
__license__ = "apache2"
__email__ = 'amr.hassan@gmail.com'
@ -1759,13 +1760,7 @@ class _Opus(_BaseObject, _Taggable):
return (a == b) and (c == d)
def __ne__(self, other):
if type(self) != type(other):
return True
a = self.get_title().lower()
b = other.get_title().lower()
c = self.get_artist().get_name().lower()
d = other.get_artist().get_name().lower()
return (a != b) or (c != d)
return not self.__eq__(other)
def _get_params(self):
return {
@ -1919,10 +1914,13 @@ class Artist(_BaseObject, _Taggable):
return self.get_name()
def __eq__(self, other):
return self.get_name().lower() == other.get_name().lower()
if type(self) is type(other):
return self.get_name().lower() == other.get_name().lower()
else:
return False
def __ne__(self, other):
return self.get_name().lower() != other.get_name().lower()
return not self.__eq__(other)
def _get_params(self):
return {self.ws_prefix: self.get_name()}
@ -2137,10 +2135,13 @@ class Event(_BaseObject):
return "Event #" + str(self.get_id())
def __eq__(self, other):
return self.get_id() == other.get_id()
if type(self) is type(other):
return self.get_id() == other.get_id()
else:
return False
def __ne__(self, other):
return self.get_id() != other.get_id()
return not self.__eq__(other)
def _get_params(self):
return {'event': self.get_id()}

View file

@ -27,7 +27,8 @@ setup(
name="pylast",
version="1.0." + get_build(),
author="Amr Hassan <amr.hassan@gmail.com>",
description="A Python interface to Last.fm (and other API compatible social networks)",
description=("A Python interface to Last.fm "
"(and other API compatible social networks)"),
author_email="amr.hassan@gmail.com",
url="https://github.com/pylast/pylast",
classifiers=[

View file

@ -377,7 +377,7 @@ class TestPyLast(unittest.TestCase):
def test_artist_is_hashable(self):
# Arrange
test_artist = self.network.get_artist("Test Artist")
artist = test_artist.get_similar(limit=1)[0].item
artist = test_artist.get_similar(limit=2)[0].item
self.assertIsInstance(artist, pylast.Artist)
# Act/Assert
@ -863,7 +863,8 @@ class TestPyLast(unittest.TestCase):
self.assertEqual(len(events), 1)
event = events[0]
self.assertIsInstance(event, pylast.Event)
self.assertEqual(event.get_venue().location['city'], "London")
self.assertIn(event.get_venue().location['city'],
["London", "Camden"])
def test_geo_get_events_in_latlong(self):
# Arrange
@ -1213,7 +1214,7 @@ class TestPyLast(unittest.TestCase):
self.helper_dates_valid(dates)
# Act/Assert
self.helper_get_assert_charts(tag, dates[-1])
self.helper_get_assert_charts(tag, dates[-2])
def test_user_charts(self):
# Arrange
@ -1222,7 +1223,7 @@ class TestPyLast(unittest.TestCase):
self.helper_dates_valid(dates)
# Act/Assert
self.helper_get_assert_charts(lastfm_user, dates[-1])
self.helper_get_assert_charts(lastfm_user, dates[1])
def test_track_top_fans(self):
# Arrange
@ -1818,6 +1819,56 @@ class TestPyLast(unittest.TestCase):
# Act / Assert
self.assertTrue(track1 != track2)
def test_artist_eq_none_is_false(self):
# Arrange
artist1 = None
artist2 = pylast.Artist("Test Artist", self.network)
# Act / Assert
self.assertFalse(artist1 == artist2)
def test_artist_ne_none_is_true(self):
# Arrange
artist1 = None
artist2 = pylast.Artist("Test Artist", self.network)
# Act / Assert
self.assertTrue(artist1 != artist2)
def test_album_eq_none_is_false(self):
# Arrange
album1 = None
album2 = pylast.Album("Test Artist", "Test Album", self.network)
# Act / Assert
self.assertFalse(album1 == album2)
def test_album_ne_none_is_true(self):
# Arrange
album1 = None
album2 = pylast.Album("Test Artist", "Test Album", self.network)
# Act / Assert
self.assertTrue(album1 != album2)
def test_event_eq_none_is_false(self):
# Arrange
event1 = None
event_id = 3478520 # Glasto 2014
event2 = pylast.Event(event_id, self.network)
# Act / Assert
self.assertFalse(event1 == event2)
def test_event_ne_none_is_true(self):
# Arrange
event1 = None
event_id = 3478520 # Glasto 2014
event2 = pylast.Event(event_id, self.network)
# Act / Assert
self.assertTrue(event1 != event2)
def test_band_members(self):
# Arrange
artist = pylast.Artist("The Beatles", self.network)