Ajout de tests pour les statistiques des revues
This commit is contained in:
parent
27df2d4d65
commit
65595039e1
16
tests/datas/reviewstats_1.csv
Normal file
16
tests/datas/reviewstats_1.csv
Normal file
@ -0,0 +1,16 @@
|
||||
20110930-12h00 1
|
||||
20111007-12h00 2
|
||||
20111014-12h00 4
|
||||
20111021-12h00 5
|
||||
20111028-12h00 10
|
||||
20111104-12h00 6
|
||||
20111111-12h00 1
|
||||
20111118-12h00 2
|
||||
20111125-12h00 4
|
||||
20111202-12h00 5
|
||||
20111209-12h00 1
|
||||
20111216-12h00 2
|
||||
20111223-12h00 4
|
||||
20111230-12h00 1
|
||||
20120106-12h00 2
|
||||
20120113-12h00 1
|
|
16
tests/datas/reviewstats_2.csv
Normal file
16
tests/datas/reviewstats_2.csv
Normal file
@ -0,0 +1,16 @@
|
||||
20110930-12h00 1
|
||||
20111007-12h00 2
|
||||
20111014-12h00 4
|
||||
20111021-12h00 5
|
||||
20111028-12h00 10
|
||||
20111104-12h00 6
|
||||
20111111-12h00 1
|
||||
20111118-12h00 2
|
||||
20111125-12h00 4
|
||||
20111202-12h00 5 3
|
||||
20111209-12h00 1 7
|
||||
20111216-12h00 2 17
|
||||
20111223-12h00 4 5
|
||||
20111230-12h00 1 9
|
||||
20120106-12h00 2 5
|
||||
20120113-12h00 1 3
|
|
86
tests/test_review_stats.py
Normal file
86
tests/test_review_stats.py
Normal file
@ -0,0 +1,86 @@
|
||||
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
|
Loading…
Reference in New Issue
Block a user