Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_key_attribute_on_none():
obj = m3u8.M3U8(playlists.SIMPLE_PLAYLIST)
mock_parser_data(obj, {})
assert len(obj.keys) == 0
def test_m3u8_should_propagate_base_uri_to_session_key():
with open(playlists.RELATIVE_PLAYLIST_FILENAME) as f:
content = f.read()
obj = m3u8.M3U8(content, base_uri='/any/path')
assert '../key.bin' == obj.session_keys[0].uri
assert '/any/key.bin' == obj.session_keys[0].absolute_uri
obj.base_uri = '/any/where/'
assert '../key.bin' == obj.session_keys[0].uri
assert '/any/key.bin' == obj.session_keys[0].absolute_uri
def test_iframe_playlists_base_path_update():
obj = m3u8.M3U8(playlists.VARIANT_PLAYLIST_WITH_IFRAME_PLAYLISTS)
assert obj.iframe_playlists[0].uri == 'video-800k-iframes.m3u8'
assert obj.iframe_playlists[0].base_uri == None
obj.base_path = 'http://localhost/base_path'
obj.base_uri = 'http://localhost/base_uri'
assert obj.iframe_playlists[0].uri == 'http://localhost/base_path/video-800k-iframes.m3u8'
assert obj.iframe_playlists[0].base_uri == 'http://localhost/base_uri'
def test_partial_segment_base_path_update():
obj = m3u8.M3U8(playlists.LOW_LATENCY_DELTA_UPDATE_PLAYLIST)
obj.base_path = 'http://localhost/base_path'
obj.base_uri = 'http://localhost/base_uri'
assert obj.segments[2].parts[0].uri == 'http://localhost/base_path/filePart271.0.ts'
assert obj.segments[2].parts[0].base_uri == 'http://localhost/base_uri'
def test_dump_should_work_for_variant_streams():
obj = m3u8.M3U8(playlists.VARIANT_PLAYLIST)
expected = playlists.VARIANT_PLAYLIST.replace(', BANDWIDTH', ',BANDWIDTH').strip()
assert expected == obj.dumps().strip()
def test_should_dump_frame_rate():
obj = m3u8.M3U8(playlists.VARIANT_PLAYLIST_WITH_FRAME_RATE)
expected = playlists.VARIANT_PLAYLIST_WITH_FRAME_RATE.strip()
assert expected == obj.dumps().strip()
def test_independent_segments_should_be_false():
obj = m3u8.M3U8(playlists.SIMPLE_PLAYLIST_WITH_EVENT_PLAYLIST_TYPE)
assert not obj.is_independent_segments
def test_iframe_playlists_attribute():
obj = m3u8.M3U8(playlists.SIMPLE_PLAYLIST)
data = {
'iframe_playlists': [{'uri': '/url/1.m3u8',
'iframe_stream_info': {'program_id': 1,
'bandwidth': 320000,
'resolution': '320x180',
'codecs': 'avc1.4d001f'}},
{'uri': '/url/2.m3u8',
'iframe_stream_info': {'bandwidth': '120000',
'codecs': 'avc1.4d400d'}}]
}
mock_parser_data(obj, data)
assert 2 == len(obj.iframe_playlists)
assert '/url/1.m3u8' == obj.iframe_playlists[0].uri
assert 1 == obj.iframe_playlists[0].iframe_stream_info.program_id
def test_date_range_in_parts():
data = m3u8.parse(playlists.DATERANGE_IN_PART_PLAYLIST)
assert data['segments'][0]['parts'][2]['dateranges'][0]['id'] == 'test_id'
assert data['segments'][0]['parts'][2]['dateranges'][0]['start_date'] == '2020-03-10T07:48:02Z'
assert data['segments'][0]['parts'][2]['dateranges'][0]['class'] == 'test_class'
assert data['segments'][0]['parts'][2]['dateranges'][0]['end_on_next'] == 'YES'
def test_should_parse_ALLOW_CACHE():
data = m3u8.parse(playlists.PLAYLIST_WITH_ENCRYPTED_SEGMENTS_AND_IV)
assert 'no' == data['allow_cache']