Merge pull request #129 from hugovk/develop

Network.get_top_tags: don't compare to limit if limit is None
This commit is contained in:
Hugo 2015-04-26 23:46:06 +03:00
commit a0256faa4e
3 changed files with 29 additions and 8 deletions

13
.editorconfig Normal file
View file

@ -0,0 +1,13 @@
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
# 4 space indentation
[*.py]
indent_size = 4
indent_style = space

View file

@ -4,7 +4,7 @@
# A Python interface to Last.fm (and other API compatible social networks) # A Python interface to Last.fm (and other API compatible social networks)
# #
# Copyright 2008-2010 Amr Hassan # Copyright 2008-2010 Amr Hassan
# Copyright 2013-2014 hugovk # Copyright 2013-2015 hugovk
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@ -34,7 +34,7 @@ import six
__version__ = '1.1.0' __version__ = '1.1.0'
__author__ = 'Amr Hassan, hugovk' __author__ = 'Amr Hassan, hugovk'
__copyright__ = "Copyright (C) 2008-2010 Amr Hassan, 2013-2014 hugovk" __copyright__ = "Copyright (C) 2008-2010 Amr Hassan, 2013-2015 hugovk"
__license__ = "apache2" __license__ = "apache2"
__email__ = 'amr.hassan@gmail.com' __email__ = 'amr.hassan@gmail.com'
@ -396,7 +396,7 @@ class _Network(object):
seq = [] seq = []
for node in doc.getElementsByTagName("tag"): for node in doc.getElementsByTagName("tag"):
if len(seq) >= limit: if limit and len(seq) >= limit:
break break
tag = Tag(_extract(node, "name"), self) tag = Tag(_extract(node, "name"), self)
weight = _number(_extract(node, "count")) weight = _number(_extract(node, "count"))
@ -4038,7 +4038,7 @@ def _extract(node, name, index=0):
return None return None
def _extract_element_tree(node, index=0): def _extract_element_tree(node):
"""Extract an element tree into a multi-level dictionary """Extract an element tree into a multi-level dictionary
NB: If any elements have text nodes as well as nested NB: If any elements have text nodes as well as nested
@ -4197,13 +4197,13 @@ class BadSessionError(ScrobblingError):
class _ScrobblerRequest(object): class _ScrobblerRequest(object):
def __init__(self, url, params, network, type="POST"): def __init__(self, url, params, network, request_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 = request_type
(self.hostname, self.subdir) = url_split_host(url[len("http:"):]) (self.hostname, self.subdir) = url_split_host(url[len("http:"):])
self.network = network self.network = network

View file

@ -31,7 +31,7 @@ def load_secrets():
return doc return doc
@flaky @flaky(max_runs=5, min_passes=1)
class TestPyLast(unittest.TestCase): class TestPyLast(unittest.TestCase):
secrets = None secrets = None
@ -1101,6 +1101,14 @@ class TestPyLast(unittest.TestCase):
# Assert # Assert
self.helper_only_one_thing_in_top_list(tags, pylast.Tag) self.helper_only_one_thing_in_top_list(tags, pylast.Tag)
def test_network_get_top_tags_with_no_limit(self):
# Arrange
# Act
tags = self.network.get_top_tags()
# Assert
self.helper_at_least_one_thing_in_top_list(tags, pylast.Tag)
def test_network_get_top_tracks_with_limit(self): def test_network_get_top_tracks_with_limit(self):
# Arrange # Arrange
# Act # Act
@ -1228,7 +1236,7 @@ class TestPyLast(unittest.TestCase):
self.helper_dates_valid(dates) self.helper_dates_valid(dates)
# Act/Assert # Act/Assert
self.helper_get_assert_charts(lastfm_user, dates[1]) self.helper_get_assert_charts(lastfm_user, dates[0])
def test_track_top_fans(self): def test_track_top_fans(self):
# Arrange # Arrange