From c4a3e7896779720b9c7e55bd7553817ff4896b81 Mon Sep 17 00:00:00 2001 From: Mindiell Date: Thu, 27 Jun 2024 18:59:42 +0200 Subject: [PATCH] Ajout de tests pour les statistiques de revue. Closes #7 --- tests/datas/reviewstats_empty.csv | 0 tests/test_review_stats.py | 62 +++++++++++++++---------------- 2 files changed, 31 insertions(+), 31 deletions(-) create mode 100644 tests/datas/reviewstats_empty.csv diff --git a/tests/datas/reviewstats_empty.csv b/tests/datas/reviewstats_empty.csv new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_review_stats.py b/tests/test_review_stats.py index c277bab..919c06f 100644 --- a/tests/test_review_stats.py +++ b/tests/test_review_stats.py @@ -8,37 +8,7 @@ from review.stats import Board, UserBoard, DurationBoard, ReviewData, ReviewStat 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 + shutil.copyfile("tests/datas/reviewstats_empty.csv", "tests/reviews/reviewstats_empty.csv") def test_board(): @@ -84,3 +54,33 @@ def test_durationboard(): assert board.max == 17 assert board.sum == 49 assert board.avg == 7.0 + + +def test_reviewstats(): + review = ReviewStats("tests/reviews/reviewstats_2.csv") + review.load() + assert review.size == 16 + assert review.first is not None + assert review.biggest is not None + assert review.min_users == 1 + assert review.max_users == 10 + assert review.avg_users == 3.1875 + assert review.min_duration == 3 + assert review.max_duration == 17 + assert review.avg_duration == 7.0 + assert review.year_review(2012) == 2 + + +def test_reviewstats_empty(): + review = ReviewStats("tests/reviews/reviewstats_empty.csv") + review.load() + assert review.size == 0 + assert review.first is None + assert review.biggest is None + assert review.min_users == 0 + assert review.max_users == 0 + assert review.avg_users == 0 + assert review.min_duration == 0 + assert review.max_duration == 0 + assert review.avg_duration == 0 + assert review.year_review(2012) == 0