- commit
- 64602de6800b1b7a4adb9bf805dd0f2c6fdc488e
- parent
- b6fbaea2c971b91f258a36a78006e5a377c62f0c
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2026-03-27 09:07
add tests
Diffstat
| M | quickstream/base.py | 4 | +++- |
| M | quickstream/providers/bandcamp.py | 9 | ++++++++- |
| M | quickstream/providers/soundcloud.py | 9 | ++++++++- |
| A | tests.py | 14 | ++++++++++++++ |
4 files changed, 33 insertions, 3 deletions
diff --git a/quickstream/base.py b/quickstream/base.py
@@ -1,11 +1,13 @@ 1 1 import re 2 2 3 3 registry = [] -1 4 test_registry = {} 4 5 5 66 -1 def provider(pattern):-1 7 def provider(pattern, tests={}): 7 8 def decorator(fn): 8 9 registry.append((re.compile(pattern), fn)) -1 10 test_registry.update(tests) 9 11 return fn 10 12 11 13 return decorator
diff --git a/quickstream/providers/bandcamp.py b/quickstream/providers/bandcamp.py
@@ -8,7 +8,14 @@ def get_stream(trackinfo): 8 8 return url 9 9 10 1011 -1 @provider(r'https?://([^/]+)\.bandcamp\.com/track/([^/?#&]+)')-1 11 @provider(r'https?://([^/]+)\.bandcamp\.com/track/([^/?#&]+)', tests={ -1 12 'http://benprunty.bandcamp.com/track/lanius-battle': { -1 13 'id': 2650410135, -1 14 'url': 'https://benprunty.bandcamp.com/track/lanius-battle', -1 15 'title': 'Lanius (Battle)', -1 16 'duration': 260.877, -1 17 }, -1 18 }) 12 19 async def bandcamp_track(client, url, uploader, id): 13 20 soup = await client.fetch_html(url) 14 21 el = soup.select_one('[data-tralbum]')
diff --git a/quickstream/providers/soundcloud.py b/quickstream/providers/soundcloud.py
@@ -29,7 +29,14 @@ async def get_streams(client, trackinfo): 29 29 return streaminfo['url'] 30 30 31 3132 -1 @provider(r'https?://soundcloud.com/([^/]+)/([^/]+)')-1 32 @provider(r'https?://soundcloud.com/([^/]+)/([^/]+)', tests={ -1 33 'http://soundcloud.com/ethmusic/lostin-powers-she-so-heavy': { -1 34 'id': 62986583, -1 35 'url': 'https://soundcloud.com/ethmusic/lostin-powers-she-so-heavy', -1 36 'title': 'Lostin Powers - She so Heavy (SneakPreview) Adrian Ackers Blueprint 1', # noqa -1 37 'duration': 143.216, -1 38 }, -1 39 }) 33 40 async def soundcloud_track(client, url, uploader, id): 34 41 soup = await client.fetch_html(url) 35 42 trackinfo = get_trackinfo(soup)
diff --git a/tests.py b/tests.py
@@ -0,0 +1,14 @@
-1 1 import unittest
-1 2
-1 3 import quickstream
-1 4 from quickstream.base import test_registry
-1 5
-1 6
-1 7 class TestProviders(unittest.IsolatedAsyncioTestCase):
-1 8 async def test_providers(self):
-1 9 for url, expected in test_registry.items():
-1 10 with self.subTest(url=url):
-1 11 actual = await quickstream.extract(url)
-1 12 base = {k: v for k, v in actual.items() if k != 'stream'}
-1 13 self.assertEqual(base, expected)
-1 14 self.assertIsNotNone(actual['stream'])