mirror of
https://github.com/davegallant/rfd.git
synced 2025-08-07 09:02:32 +00:00
Add integration tests (#79)
Adds integration tests in pytest to detect breaking changes.
This commit is contained in:
37
rfd/cli.py
37
rfd/cli.py
@@ -7,11 +7,11 @@ import sys
|
||||
import click
|
||||
from colorama import init, Fore, Style
|
||||
from .api import get_threads, get_posts
|
||||
from .threads import parse_threads, search_threads, sort_threads
|
||||
from .threads import parse_threads, search_threads, sort_threads, generate_thread_output
|
||||
from .scores import get_vote_color
|
||||
from .__version__ import version as current_version
|
||||
|
||||
init()
|
||||
print()
|
||||
|
||||
logging.getLogger()
|
||||
logging.getLogger().setLevel(logging.INFO)
|
||||
@@ -27,14 +27,6 @@ def get_terminal_width():
|
||||
return int(columns)
|
||||
|
||||
|
||||
def get_vote_color(score):
|
||||
if score > 0:
|
||||
return Fore.GREEN + " [+" + str(score) + "] "
|
||||
if score < 0:
|
||||
return Fore.RED + " [" + str(score) + "] "
|
||||
return Fore.BLUE + " [" + str(score) + "] "
|
||||
|
||||
|
||||
def print_version(ctx, value):
|
||||
if not value or ctx.resilient_parsing:
|
||||
return
|
||||
@@ -42,31 +34,6 @@ def print_version(ctx, value):
|
||||
ctx.exit()
|
||||
|
||||
|
||||
def generate_thread_output(_threads):
|
||||
for count, thread in enumerate(_threads, 1):
|
||||
output = ""
|
||||
dealer = thread.dealer_name
|
||||
if dealer and dealer is not None:
|
||||
dealer = "[" + dealer + "] "
|
||||
else:
|
||||
dealer = ""
|
||||
output += (
|
||||
" "
|
||||
+ str(count)
|
||||
+ "."
|
||||
+ get_vote_color(thread.score)
|
||||
+ Fore.RESET
|
||||
+ "%s%s" % (dealer, thread.title)
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ " (%d views)" % thread.views
|
||||
+ Fore.RESET
|
||||
)
|
||||
output += Fore.BLUE + " {}".format(thread.url)
|
||||
output += Style.RESET_ALL
|
||||
output += "\n\n"
|
||||
yield output
|
||||
|
||||
|
||||
@click.group(invoke_without_command=True)
|
||||
@click.option(
|
||||
"-v",
|
||||
|
@@ -1,3 +1,6 @@
|
||||
from colorama import Fore
|
||||
|
||||
|
||||
def calculate_score(post):
|
||||
"""Calculate either topic or post score. If votes cannot be retrieved, the score is 0.
|
||||
|
||||
@@ -16,3 +19,11 @@ def calculate_score(post):
|
||||
pass
|
||||
|
||||
return score
|
||||
|
||||
|
||||
def get_vote_color(score):
|
||||
if score > 0:
|
||||
return Fore.GREEN + " [+" + str(score) + "] "
|
||||
if score < 0:
|
||||
return Fore.RED + " [" + str(score) + "] "
|
||||
return Fore.BLUE + " [" + str(score) + "] "
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import re
|
||||
from colorama import Fore, Style
|
||||
from . import API_BASE_URL
|
||||
from .scores import calculate_score
|
||||
from .scores import calculate_score, get_vote_color
|
||||
|
||||
# pylint: disable=old-style-class
|
||||
class Thread:
|
||||
@@ -74,3 +75,28 @@ def search_threads(threads, regex):
|
||||
deal.dealer_name and regexp.search(deal.dealer_name.lower())
|
||||
):
|
||||
yield deal
|
||||
|
||||
|
||||
def generate_thread_output(threads):
|
||||
for count, thread in enumerate(threads, 1):
|
||||
output = ""
|
||||
dealer = thread.dealer_name
|
||||
if dealer and dealer is not None:
|
||||
dealer = "[" + dealer + "] "
|
||||
else:
|
||||
dealer = ""
|
||||
output += (
|
||||
" "
|
||||
+ str(count)
|
||||
+ "."
|
||||
+ get_vote_color(thread.score)
|
||||
+ Fore.RESET
|
||||
+ "%s%s" % (dealer, thread.title)
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ " (%d views)" % thread.views
|
||||
+ Fore.RESET
|
||||
)
|
||||
output += Fore.BLUE + " {}".format(thread.url)
|
||||
output += Style.RESET_ALL
|
||||
output += "\n\n"
|
||||
yield output
|
||||
|
Reference in New Issue
Block a user