Fix calculation algorithm
This commit is contained in:
@@ -12,14 +12,14 @@ from pytchat.processors.speed_calculator import SpeedCalculator
|
||||
parser = Parser()
|
||||
|
||||
def test_speed_1(mocker):
|
||||
'''test speed normal
|
||||
'''test speed calculation with normal json.
|
||||
test json has 15 chatdata, duration is 30 seconds,
|
||||
so the speed of chatdata is 30 chats/minute.
|
||||
'''
|
||||
|
||||
processor = SpeedCalculator(capacity=30,video_id="")
|
||||
processor = SpeedCalculator(capacity=30)
|
||||
|
||||
_json = _open_file("tests/testdata/speed/speedtest1.json")
|
||||
_json = _open_file("tests/testdata/speed/speedtest_normal.json")
|
||||
|
||||
_, chatdata = parser.parse(json.loads(_json))
|
||||
data = {
|
||||
@@ -31,13 +31,27 @@ def test_speed_1(mocker):
|
||||
assert 30 == ret
|
||||
|
||||
def test_speed_2(mocker):
|
||||
'''test speed with no valid chat data
|
||||
|
||||
'''test speed calculation with no valid chat data.
|
||||
'''
|
||||
processor = SpeedCalculator(capacity=30)
|
||||
|
||||
processor = SpeedCalculator(capacity=30,video_id="")
|
||||
_json = _open_file("tests/testdata/speed/speedtest_undefined.json")
|
||||
|
||||
_json = _open_file("tests/testdata/speed/speedtest_none.json")
|
||||
_, chatdata = parser.parse(json.loads(_json))
|
||||
data = {
|
||||
"video_id" : "",
|
||||
"timeout" : 10,
|
||||
"chatdata" : chatdata
|
||||
}
|
||||
ret = processor.process([data])
|
||||
assert 0 == ret
|
||||
|
||||
def test_speed_3(mocker):
|
||||
'''test speed calculation with empty data.
|
||||
'''
|
||||
processor = SpeedCalculator(capacity=30)
|
||||
|
||||
_json = _open_file("tests/testdata/speed/speedtest_empty.json")
|
||||
|
||||
_, chatdata = parser.parse(json.loads(_json))
|
||||
data = {
|
||||
@@ -52,3 +66,4 @@ def test_speed_2(mocker):
|
||||
def _open_file(path):
|
||||
with open(path,mode ='r',encoding = 'utf-8') as f:
|
||||
return f.read()
|
||||
_put_chatdata
|
||||
Reference in New Issue
Block a user