diff --git a/README.md b/README.md index 9e47136..9e5c942 100644 --- a/README.md +++ b/README.md @@ -87,12 +87,22 @@ export PYLAST_API_KEY=TODO_ENTER_YOURS_HERE export PYLAST_API_SECRET=TODO_ENTER_YOURS_HERE ``` -Then: +To run all: ``` pip install pyyaml ./test_pylast.py ``` +Or run just one: +``` +./test_pylast.py -1 test_scrobble +``` + +Or all those tests matching a term: +``` +./test_pylast.py -m geo +``` + To run with coverage: ``` pip install coverage diff --git a/pylast.py b/pylast.py index 6fd8fbd..2fc2efc 100644 --- a/pylast.py +++ b/pylast.py @@ -1449,10 +1449,31 @@ class _BaseObject(object): self._request(self.ws_prefix + '.share', False, params) - def get_wiki(self, section): + def get_wiki_published_date(self): """ Returns the summary of the wiki. Only for Album/Track. + """ + return self.get_wiki("published") + + def get_wiki_summary(self): + """ + Returns the summary of the wiki. + Only for Album/Track. + """ + return self.get_wiki("summary") + + def get_wiki_content(self): + """ + Returns the summary of the wiki. + Only for Album/Track. + """ + return self.get_wiki("content") + + def get_wiki(self, section): + """ + Returns a section of the wiki. + Only for Album/Track. section can be "content", "summary" or "published" (for published date) """ diff --git a/test_pylast.py b/test_pylast.py index 765b9cd..d93b2f3 100755 --- a/test_pylast.py +++ b/test_pylast.py @@ -2,6 +2,7 @@ """ Integration (not unit) tests for pylast.py """ +import argparse import os from random import choice import time @@ -682,18 +683,18 @@ class TestPyLast(unittest.TestCase): album = pylast.Album("Test Artist", "Test Album", self.network) # Act - wiki = album.get_wiki("content") + wiki = album.get_wiki_content() # Assert self.assertIsNotNone(wiki) self.assertGreaterEqual(len(wiki), 1) - def test_album_wiki_published(self): + def test_album_wiki_published_date(self): # Arrange album = pylast.Album("Test Artist", "Test Album", self.network) # Act - wiki = album.get_wiki("published") + wiki = album.get_wiki_published_date() # Assert self.assertIsNotNone(wiki) @@ -704,7 +705,7 @@ class TestPyLast(unittest.TestCase): album = pylast.Album("Test Artist", "Test Album", self.network) # Act - wiki = album.get_wiki("summary") + wiki = album.get_wiki_summary() # Assert self.assertIsNotNone(wiki) @@ -715,7 +716,7 @@ class TestPyLast(unittest.TestCase): track = pylast.Track("Test Artist", "Test Title", self.network) # Act - wiki = track.get_wiki("content") + wiki = track.get_wiki_content() # Assert self.assertIsNotNone(wiki) @@ -726,7 +727,7 @@ class TestPyLast(unittest.TestCase): track = pylast.Track("Test Artist", "Test Title", self.network) # Act - wiki = track.get_wiki("summary") + wiki = track.get_wiki_summary() # Assert self.assertIsNotNone(wiki) @@ -1333,15 +1334,35 @@ class TestPyLast(unittest.TestCase): if __name__ == '__main__': + parser = argparse.ArgumentParser( + description = "Integration (not unit) tests for pylast.py", + formatter_class = argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument('-1', '--single', + help="Run a single test") + parser.add_argument('-m', '--matching', + help="Run tests with this in the name") + args = parser.parse_args() - # For quick testing of a single case (eg. test = "test_scrobble") - test = "" - - if test is not None and len(test): + if args.single: suite = unittest.TestSuite() - suite.addTest(TestPyLast(test)) + suite.addTest(TestPyLast(args.single)) unittest.TextTestRunner().run(suite) + + elif args.matching: + suite = unittest.TestSuite() + + import inspect + methods = inspect.getmembers(TestPyLast, predicate=inspect.ismethod) + + tests = [] + for method, _ in methods: + if method.startswith("test_") and args.matching in method: + print method + suite.addTest(TestPyLast(method)) + + unittest.TextTestRunner().run(suite) + else: unittest.main()