Reworked comment & progress bar

This commit is contained in:
Collin R
2020-02-01 00:23:15 -08:00
parent 74771bd24d
commit 3dee25bd80
11 changed files with 464 additions and 303 deletions

5
tests/context.py Normal file
View File

@@ -0,0 +1,5 @@
from os.path import abspath, dirname, join
import sys
sys.path.insert(0, abspath(join(dirname(__file__), '..')))
import pointsbot

View File

@@ -1,15 +0,0 @@
import comment
levels = [
('Helper', 5),
('Trusted Helper', 15),
('Super Helper', 40),
]
tests = [1, 5, 10, 15, 30, 40, 45]
for testpoints in tests:
progbar = comment.progress_bar(testpoints, levels)
print(f'Points: {testpoints}')
print(progbar)
print()

40
tests/test_level.py Normal file
View File

@@ -0,0 +1,40 @@
import level
levels = [
('Helper', 5),
('Trusted Helper', 15),
('Super Helper', 45),
]
### Test user_level_info ###
pastlvls, curlvl, nextlvl = user_level_info(1, levels)
assert (pastlevels == [] and curlvl is None and nextlvl == levels[0])
pastlvls, curlvl, nextlvl = user_level_info(5, levels)
assert (pastlevels == [] and curlvl == levels[0] and nextlvl == levels[1])
pastlvls, curlvl, nextlvl = user_level_info(15, levels)
assert (pastlvls == levels[:1] and curlvl == levels[1] and nextlvl == levels[2])
pastlvls, curlvl, nextlvl = user_level_info(45, levels)
assert (pastlvls == levels[:2] and curlvl == levels[2] and nextlvl is None)
### Test is_max_level ###
# TODO I mean, this could be tested exhaustively with positive numbers, even if
# the number of points for the max level is decently large
assert not level.is_max_level(-1, levels)
assert not level.is_max_level(0, levels)
assert not level.is_max_level(4, levels)
assert not level.is_max_level(5, levels)
assert not level.is_max_level(14, levels)
assert not level.is_max_level(15, levels)
assert not level.is_max_level(16, levels)
assert not level.is_max_level(44, levels)
assert level.is_max_level(45, levels)
assert level.is_max_level(46, levels)

44
tests/test_reply.py Normal file
View File

@@ -0,0 +1,44 @@
from collections import namedtuple
from context import pointsbot
### Data Structures ###
MockRedditor = namedtuple('MockRedditor', 'id name')
### Functions ###
def leftpad(msg, num_indents=1):
return '\n'.join([('\t' * num_indents + l) for l in msg.split('\n')])
### Tests ###
levels = [
pointsbot.level.Level('Novice', 1),
pointsbot.level.Level('Apprentice', 5),
pointsbot.level.Level('Journeyman', 15),
pointsbot.level.Level('Expert', 45),
pointsbot.level.Level('Master I', 100),
pointsbot.level.Level('Master II', 200),
pointsbot.level.Level('Master III', 300),
pointsbot.level.Level('Master IV', 400),
pointsbot.level.Level('Master V', 500),
]
testredditors = [MockRedditor('1', 'Tim_the_Sorcerer')]
testpoints = [1, 3, 5, 10, 15, 30, 45, 75] + list(range(100, 551, 50))
for redditor in testredditors:
for points in testpoints:
level_info = pointsbot.level.user_level_info(points, levels)
body = pointsbot.reply.make(redditor, points, level_info)
print('*' * 80)
print()
print(f'Name: {redditor.name}')
print(f'Points: {points}')
print(f'Body:')
print(leftpad(body, num_indents=1))
print()
print('*' * 80)