test_audio.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from . import audio
  2. import pytest
  3. import re
  4. @pytest.mark.parametrize('input,expected', [
  5. ('http://foo.bar https://bar.foo',
  6. ('http://foo.bar', 'https://bar.foo', None)),
  7. ('http://test.foo',
  8. ('http://test.foo', None, None)),
  9. ('https://test.foo',
  10. ('https://test.foo', None, None)),
  11. ('http://foo.foo https://bar.bar http://zonk.zonk',
  12. ('http://foo.foo', 'https://bar.bar', 'http://zonk.zonk'))
  13. ])
  14. def test_regex(input, expected):
  15. assert re.match(audio.AUDIO, input).groups() == expected
  16. @pytest.mark.parametrize('input,expected', [
  17. ('http://foo.foo/foo.mp3',
  18. ('<audio controls>'
  19. '<source src="http://foo.foo/foo.mp3" type="audio/mpeg">'
  20. 'Your browser does not support the audio element.</audio>')),
  21. ('https://foo.foo/foo.ogg http://bar.bar/bar.opus',
  22. ('<audio controls>'
  23. '<source src="https://foo.foo/foo.ogg" type="audio/ogg">'
  24. '<source src="http://bar.bar/bar.opus" type="audio/ogg">'
  25. 'Your browser does not support the audio element.</audio>')),
  26. ('http://1.de/1.wav http://2.de/2.mp4 http://3.de/3.ogg',
  27. ('<audio controls>'
  28. '<source src="http://1.de/1.wav" type="audio/wav">'
  29. '<source src="http://2.de/2.mp4" type="audio/mp4">'
  30. '<source src="http://3.de/3.ogg" type="audio/ogg">'
  31. 'Your browser does not support the audio element.</audio>'))
  32. ])
  33. def test_create_html(input, expected):
  34. assert audio.create_html(input) == expected