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