diff --git a/tests/test_livechat.py b/tests/test_livechat.py deleted file mode 100644 index 925538d..0000000 --- a/tests/test_livechat.py +++ /dev/null @@ -1,48 +0,0 @@ -import asyncio -import json -from pytest_httpx import HTTPXMock -from concurrent.futures import CancelledError -from pytchat.core_multithread.livechat import LiveChat -from pytchat.core_async.livechat import LiveChatAsync -from pytchat.exceptions import ResponseContextError - - -def _open_file(path): - with open(path, mode='r', encoding='utf-8') as f: - return f.read() - - -def add_response_file(httpx_mock: HTTPXMock, jsonfile_path: str): - testdata = json.loads(_open_file(jsonfile_path)) - httpx_mock.add_response(json=testdata) - - -def test_async(httpx_mock: HTTPXMock): - add_response_file(httpx_mock, 'tests/testdata/paramgen_firstread.json') - - async def test_loop(): - try: - chat = LiveChatAsync(video_id='__test_id__') - _ = await chat.get() - assert chat.is_alive() - chat.terminate() - assert not chat.is_alive() - except ResponseContextError: - assert False - loop = asyncio.get_event_loop() - try: - loop.run_until_complete(test_loop()) - except CancelledError: - assert True - - -def test_multithread(httpx_mock: HTTPXMock): - add_response_file(httpx_mock, 'tests/testdata/paramgen_firstread.json') - try: - chat = LiveChat(video_id='__test_id__') - _ = chat.get() - assert chat.is_alive() - chat.terminate() - assert not chat.is_alive() - except ResponseContextError: - assert False diff --git a/tests/test_livechat_2.py b/tests/test_livechat_2.py deleted file mode 100644 index eba1236..0000000 --- a/tests/test_livechat_2.py +++ /dev/null @@ -1,71 +0,0 @@ -import asyncio -import json -from pytest_httpx import HTTPXMock -from concurrent.futures import CancelledError -from pytchat.core_multithread.livechat import LiveChat -from pytchat.core_async.livechat import LiveChatAsync -from pytchat.processors.dummy_processor import DummyProcessor - - -def _open_file(path): - with open(path, mode='r', encoding='utf-8') as f: - return f.read() - - -def add_response_file(httpx_mock: HTTPXMock, jsonfile_path: str): - testdata = json.loads(_open_file(jsonfile_path)) - httpx_mock.add_response(json=testdata) - - -def test_async_live_stream(httpx_mock: HTTPXMock): - add_response_file(httpx_mock, 'tests/testdata/test_stream.json') - - async def test_loop(): - chat = LiveChatAsync(video_id='__test_id__', processor=DummyProcessor()) - chats = await chat.get() - rawdata = chats[0]["chatdata"] - assert list(rawdata[0]["addChatItemAction"]["item"].keys())[ - 0] == "liveChatTextMessageRenderer" - assert list(rawdata[1]["addChatItemAction"]["item"].keys())[ - 0] == "liveChatTextMessageRenderer" - assert list(rawdata[2]["addChatItemAction"]["item"].keys())[ - 0] == "liveChatPlaceholderItemRenderer" - assert list(rawdata[3]["addLiveChatTickerItemAction"]["item"].keys())[ - 0] == "liveChatTickerPaidMessageItemRenderer" - assert list(rawdata[4]["addChatItemAction"]["item"].keys())[ - 0] == "liveChatPaidMessageRenderer" - assert list(rawdata[5]["addChatItemAction"]["item"].keys())[ - 0] == "liveChatPaidStickerRenderer" - assert list(rawdata[6]["addLiveChatTickerItemAction"]["item"].keys())[ - 0] == "liveChatTickerSponsorItemRenderer" - - loop = asyncio.get_event_loop() - try: - loop.run_until_complete(test_loop()) - except CancelledError: - assert True - - - - -def test_multithread_live_stream(httpx_mock: HTTPXMock): - add_response_file(httpx_mock, 'tests/testdata/test_stream.json') - chat = LiveChat(video_id='__test_id__', processor=DummyProcessor()) - chats = chat.get() - rawdata = chats[0]["chatdata"] - # assert fetching livachat data - assert list(rawdata[0]["addChatItemAction"]["item"].keys())[ - 0] == "liveChatTextMessageRenderer" - assert list(rawdata[1]["addChatItemAction"]["item"].keys())[ - 0] == "liveChatTextMessageRenderer" - assert list(rawdata[2]["addChatItemAction"]["item"].keys())[ - 0] == "liveChatPlaceholderItemRenderer" - assert list(rawdata[3]["addLiveChatTickerItemAction"]["item"].keys())[ - 0] == "liveChatTickerPaidMessageItemRenderer" - assert list(rawdata[4]["addChatItemAction"]["item"].keys())[ - 0] == "liveChatPaidMessageRenderer" - assert list(rawdata[5]["addChatItemAction"]["item"].keys())[ - 0] == "liveChatPaidStickerRenderer" - assert list(rawdata[6]["addLiveChatTickerItemAction"]["item"].keys())[ - 0] == "liveChatTickerSponsorItemRenderer" - chat.terminate() diff --git a/tests/test_liveparam.py b/tests/test_liveparam.py deleted file mode 100644 index 66d59be..0000000 --- a/tests/test_liveparam.py +++ /dev/null @@ -1,9 +0,0 @@ -import pytest -from pytchat.paramgen import liveparam - -def test_liveparam_0(mocker): - _ts1= 1546268400 - param = liveparam._build("01234567890", - *([_ts1*1000000 for i in range(5)]), topchat_only=False) - test_param="0ofMyAN1GhxDZzhLRFFvTE1ERXlNelExTmpjNE9UQWdBUT09KIC41tWqyt8CMAA4AEABShsIABAAGAAgADoAQABKAFCAuNbVqsrfAlgDeABQgLjW1arK3wJYgLjW1arK3wJoAYIBAggBiAEAmgECCACgAYC41tWqyt8C" - assert test_param == param \ No newline at end of file