From bc7433990b1caf94e9c04beda9773dfec54611eb Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 11 Sep 2014 15:07:02 +0300 Subject: [PATCH 1/7] Fix comparison with None for artist, album and event, with test. For #97. --- pylast.py | 22 +++++++++++----------- test_pylast.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 12 deletions(-) diff --git a/pylast.py b/pylast.py index 49a2f1a..53ac356 100644 --- a/pylast.py +++ b/pylast.py @@ -1747,13 +1747,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 { @@ -1907,10 +1901,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()} @@ -2114,10 +2111,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()} diff --git a/test_pylast.py b/test_pylast.py index ed2bf9b..fd4b807 100755 --- a/test_pylast.py +++ b/test_pylast.py @@ -1803,7 +1803,6 @@ class TestPyLast(unittest.TestCase): self.assertTrue(country1 != country2) self.assertEqual(url, "http://www.last.fm/place/italy") - def test_track_eq_none_is_false(self): # Arrange track1 = None @@ -1820,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) + if __name__ == '__main__': parser = argparse.ArgumentParser( From 2fea3a1b46215012af9682a355246c70fee8749f Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 11 Sep 2014 15:17:47 +0300 Subject: [PATCH 2/7] Last.fm returns no results for artist.getsimilar with limit=1, but limit=2 returns 2 --- test_pylast.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_pylast.py b/test_pylast.py index fd4b807..0a1b8d9 100755 --- a/test_pylast.py +++ b/test_pylast.py @@ -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 From 56d1f2791f78045e111b542032df08428dfd1470 Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 11 Sep 2014 15:29:25 +0300 Subject: [PATCH 3/7] Fix chart tests that failed due to date ranges --- pylast.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pylast.py b/pylast.py index 53ac356..baeac57 100644 --- a/pylast.py +++ b/pylast.py @@ -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' From def9b2414a2286ad32d62f3c5ca2cf3844abaa18 Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 11 Sep 2014 15:37:17 +0300 Subject: [PATCH 4/7] Fix chart tests that failed due to date ranges (take 2) --- .travis.yml | 1 + test_pylast.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c853ea3..8987743 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,3 +28,4 @@ matrix: allow_failures: - python: "3.4" - python: "pypy" + fast_finish: true diff --git a/test_pylast.py b/test_pylast.py index 0a1b8d9..0bd0f0b 100755 --- a/test_pylast.py +++ b/test_pylast.py @@ -1213,7 +1213,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 +1222,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 From 8a53afd41b93b30e8855d09d3a5cbb8d5537e5c9 Mon Sep 17 00:00:00 2001 From: hugovk Date: Thu, 18 Dec 2014 21:09:22 +0200 Subject: [PATCH 5/7] Badges! [CI skip] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7366cb4..d089d68 100644 --- a/README.md +++ b/README.md @@ -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/). From 3941fd8ab59f37986808d63b2a543c29b7a251f5 Mon Sep 17 00:00:00 2001 From: hugovk Date: Thu, 18 Dec 2014 21:13:28 +0200 Subject: [PATCH 6/7] Make test more robust --- setup.py | 3 ++- test_pylast.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 94e11f1..c166df7 100755 --- a/setup.py +++ b/setup.py @@ -27,7 +27,8 @@ setup( name="pylast", version="1.0." + get_build(), author="Amr Hassan ", - 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=[ diff --git a/test_pylast.py b/test_pylast.py index 52244bf..81dcbbc 100755 --- a/test_pylast.py +++ b/test_pylast.py @@ -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 From 59769d31d64d91b01037e4fb5ce8a947031e8775 Mon Sep 17 00:00:00 2001 From: hugovk Date: Fri, 26 Dec 2014 15:28:25 +0200 Subject: [PATCH 7/7] Use Docker --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8987743..ceca581 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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=