def test_pattern_unmatch(mocker): '''Test case the pattern for extraction is unmatched.''' _set_test_data('tests/testdata/videoinfo/pattern_unmatch.txt', mocker) try: _ = VideoInfo('__test_id__') assert False except JSONDecodeError: assert True
def test_collapsed_data(mocker): '''Test case the video page's info is collapsed.''' _set_test_data('tests/testdata/videoinfo/collapsed_page.txt', mocker) try: _ = VideoInfo('__test_id__') assert False except JSONDecodeError: assert True
def test_invalid_video_id(mocker): '''Test case invalid video_id is specified.''' _set_test_data('tests/testdata/videoinfo/invalid_video_id_page.txt', mocker) try: _ = VideoInfo('__test_id__') assert False except InvalidVideoIdException: assert True
def test_extradata_handling(mocker): '''Test case the extracted data are JSON lines.''' _set_test_data('tests/testdata/videoinfo/extradata_page.txt', mocker) try: _ = VideoInfo('__test_id__') assert True except JSONDecodeError as e: print(e.doc) assert False
def test_no_info(mocker): '''Test case the video page has renderer, but no info.''' _set_test_data('tests/testdata/videoinfo/no_info_page.txt', mocker) info = VideoInfo('__test_id__') assert info.video_id == '__test_id__' assert info.get_channel_name() is None assert info.get_thumbnail() is None assert info.get_title() is None assert info.get_channel_id() is None assert info.get_duration() is None
def test_archived_page(mocker): _set_test_data('tests/testdata/videoinfo/archived_page.txt', mocker) info = VideoInfo('__test_id__') actual_thumbnail_url = 'https://i.ytimg.com/vi/fzI9FNjXQ0o/hqdefault.jpg' assert info.video_id == '__test_id__' assert info.get_channel_name() == 'GitHub' assert info.get_thumbnail() == actual_thumbnail_url assert info.get_title() == 'GitHub Arctic Code Vault' assert info.get_channel_id() == 'UC7c3Kb6jYCRj4JOHHZTxKsQ' assert info.get_duration() == 148
def test_live_page(mocker): _set_test_data('tests/testdata/videoinfo/live_page.txt', mocker) info = VideoInfo('__test_id__') '''live page :duration = 0''' assert info.get_duration() == 0 assert info.video_id == '__test_id__' assert info.get_channel_name() == 'BGM channel' assert info.get_thumbnail() == \ 'https://i.ytimg.com/vi/fEvM-OUbaKs/hqdefault_live.jpg' assert info.get_title() == ( 'Coffee Jazz Music - Chill Out Lounge Jazz Music Radio' ' - 24/7 Live Stream - Slow Jazz') assert info.get_channel_id() == 'UCQINXHZqCU5i06HzxRkujfg'