46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
from pytchat.parser.live import Parser
|
|
import json
|
|
from aioresponses import aioresponses
|
|
from pytchat.exceptions import NoContents
|
|
|
|
|
|
def _open_file(path):
|
|
with open(path, mode='r', encoding='utf-8') as f:
|
|
return f.read()
|
|
|
|
|
|
parser = Parser(is_replay=False)
|
|
|
|
|
|
@aioresponses()
|
|
def test_finishedlive(*mock):
|
|
'''配信が終了した動画を正しく処理できるか'''
|
|
|
|
_text = _open_file('tests/testdata/finished_live.json')
|
|
_text = json.loads(_text)
|
|
|
|
try:
|
|
parser.parse(parser.get_contents(_text))
|
|
assert False
|
|
except NoContents:
|
|
assert True
|
|
|
|
|
|
@aioresponses()
|
|
def test_parsejson(*mock):
|
|
'''jsonを正常にパースできるか'''
|
|
|
|
_text = _open_file('tests/testdata/paramgen_firstread.json')
|
|
_text = json.loads(_text)
|
|
|
|
try:
|
|
parser.parse(parser.get_contents(_text))
|
|
jsn = _text
|
|
timeout = jsn["response"]["continuationContents"]["liveChatContinuation"]["continuations"][0]["timedContinuationData"]["timeoutMs"]
|
|
continuation = jsn["response"]["continuationContents"]["liveChatContinuation"][
|
|
"continuations"][0]["timedContinuationData"]["continuation"]
|
|
assert timeout == 5035
|
|
assert continuation == "0ofMyAPiARp8Q2c4S0RRb0xhelJMZDBsWFQwdERkalFhUTZxNXdiMEJQUW83YUhSMGNITTZMeTkzZDNjdWVXOTFkSFZpWlM1amIyMHZiR2wyWlY5amFHRjBQM1k5YXpSTGQwbFhUMHREZGpRbWFYTmZjRzl3YjNWMFBURWdBZyUzRCUzRCiPz5-Os-PkAjAAOABAAUorCAAQABgAIAAqDnN0YXRpY2NoZWNrc3VtOgBAAEoCCAFQgJqXjrPj5AJYA1CRwciOs-PkAli3pNq1k-PkAmgBggEECAEQAIgBAKABjbfnjrPj5AI%3D"
|
|
except Exception:
|
|
assert False
|