forked from mindiell/hebdobot
87 lines
2.4 KiB
Python
87 lines
2.4 KiB
Python
|
from datetime import datetime, timedelta
|
||
|
import re
|
||
|
import shutil
|
||
|
|
||
|
from review.stats import Board, UserBoard, DurationBoard, ReviewData, ReviewStats
|
||
|
|
||
|
|
||
|
def setup_function():
|
||
|
shutil.copyfile("tests/datas/reviewstats_1.csv", "tests/reviews/reviewstats_1.csv")
|
||
|
shutil.copyfile("tests/datas/reviewstats_2.csv", "tests/reviews/reviewstats_2.csv")
|
||
|
|
||
|
|
||
|
def load_reviewstats(filepath):
|
||
|
final_datas = []
|
||
|
try:
|
||
|
with open(filepath) as file_handle:
|
||
|
lines = file_handle.read().splitlines()
|
||
|
for line in lines:
|
||
|
if line.strip() != "":
|
||
|
datas = re.split(r"\s+", line)
|
||
|
if len(datas) == 2:
|
||
|
final_datas.append(
|
||
|
ReviewData(
|
||
|
datetime.strptime(datas[0], "%Y%m%d-%Hh%M"),
|
||
|
int(datas[1]),
|
||
|
None,
|
||
|
)
|
||
|
)
|
||
|
else:
|
||
|
final_datas.append(
|
||
|
ReviewData(
|
||
|
datetime.strptime(datas[0], "%Y%m%d-%Hh%M"),
|
||
|
int(datas[1]),
|
||
|
int(datas[2]),
|
||
|
)
|
||
|
)
|
||
|
except FileNotFoundError:
|
||
|
# no file, no stats
|
||
|
pass
|
||
|
|
||
|
return final_datas
|
||
|
|
||
|
|
||
|
def test_board():
|
||
|
board = Board()
|
||
|
assert board.datas == {}
|
||
|
assert board["test"] == 0
|
||
|
assert board.position("test") is None
|
||
|
assert board.min == 0
|
||
|
assert board.max == 0
|
||
|
assert board.avg == 0
|
||
|
assert board.sum == 0
|
||
|
|
||
|
|
||
|
def test_userboard():
|
||
|
review = ReviewStats("tests/reviews/reviewstats_1.csv")
|
||
|
review.load()
|
||
|
board = review.users_board
|
||
|
assert board["test"] == 0
|
||
|
assert board[1] == 5
|
||
|
assert board.min == 1
|
||
|
assert board.max == 10
|
||
|
assert board.sum == 51
|
||
|
assert board.avg == 3.1875
|
||
|
|
||
|
|
||
|
def test_durationboard():
|
||
|
review = ReviewStats("tests/reviews/reviewstats_1.csv")
|
||
|
review.load()
|
||
|
board = review.durations_board
|
||
|
assert board["test"] == 0
|
||
|
assert board.min == 0
|
||
|
assert board.max == 0
|
||
|
assert board.sum == 0
|
||
|
assert board.avg == 0
|
||
|
|
||
|
|
||
|
def test_durationboard():
|
||
|
review = ReviewStats("tests/reviews/reviewstats_2.csv")
|
||
|
review.load()
|
||
|
board = review.durations_board
|
||
|
assert board["test"] == 0
|
||
|
assert board.min == 3
|
||
|
assert board.max == 17
|
||
|
assert board.sum == 49
|
||
|
assert board.avg == 7.0
|