Skip to content

Commit

Permalink
feat: pytest should have colour #14, should be a space around progres…
Browse files Browse the repository at this point in the history
…s information, reduce pytest output and improve UX of some exercises and add clear console function #15

closes #14
  • Loading branch information
THEGOLDENPRO committed Sep 26, 2024
1 parent 40c1aad commit 93bf794
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion snakelings/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.0dev4"
__version__ = "1.0.0dev5"
17 changes: 10 additions & 7 deletions snakelings/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from devgoldyutils import Colours
from rich.markdown import Markdown

from . import terminal

from .exercise import Exercise
from .execution import test_exercise
from .logger import snakelings_logger
Expand Down Expand Up @@ -42,7 +44,6 @@ def start(
True,
"--ets/--no-ets",
"--enter-to-continue/--no-enter-to-continue",
is_flag = True,
help = "ON by default, this enforces you to press enter before moving onto the next exercise."
),
wait_to_continue: bool = typer.Option(
Expand Down Expand Up @@ -76,16 +77,16 @@ def start(
for exercise in sorted(handler.get_exercises(), key = lambda x: x.id):
no_exercises = False

if exercise_id >= exercise.id and not exercise.id == exercise_id:
continue

if exercise.completed:
result, _ = test_exercise(exercise)

if result is True:
continue

if exercise_id >= exercise.id and not exercise.id == exercise_id:
continue

console.clear()
terminal.proper_clear()

markdown = Markdown(exercise.readme)
console.print(markdown)
Expand All @@ -95,8 +96,8 @@ def start(

print(f"\n{Colours.RED.apply('[🛑 Problem]')} \n{output}")

print(Colours.ORANGE.apply(f"🚧 Progress: {exercise.id} / {exercise_count}"))
print(Colours.CLAY.apply(f"⚡ Complete the '{exercise.title}' exercise!"))
print(Colours.ORANGE.apply(f"\n🚧 Progress: {exercise.id} / {exercise_count}"))
print(Colours.CLAY.apply(f"⚡ Complete the '{exercise.title}' exercise!\n"))

watch_exercise_complete(exercise) # This will halt here until the exercise is marked complete

Expand Down Expand Up @@ -153,6 +154,8 @@ def init(
snakelings_logger.debug("Copying exercises from snakelings module...")

if exercises_folder_path.exists() and next(exercises_folder_path.iterdir(), None) is not None:
# TODO: if it's a hidden file like .pytest_cache for
# example then it shouldn't count as the folder not being empty.
snakelings_logger.error(
f"The exercises folder ({exercises_folder_path.absolute()}) is not empty!" \
"\nIf you would like to update your exercises use 'snakelings update' instead."
Expand Down
5 changes: 4 additions & 1 deletion snakelings/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def test_exercise_with_pytest(exercise: Exercise) -> Tuple[bool, str]:
sys.executable,
"-m",
"pytest",
"--quiet"
"--quiet",
"--log-cli-level=warning",
"--color=yes",
"--tb=line"
]

args.extend(
Expand Down
2 changes: 2 additions & 0 deletions snakelings/exercises/2_print_from_scratch/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ version = 1

title = "Print from scratch"

hint = "Look at what the assertion error is telling you."

[pytest]
test_scripts = [
{module = "test_stdout.py"}
Expand Down
2 changes: 1 addition & 1 deletion snakelings/exercises/2_print_from_scratch/test_stdout.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ def test_output(capsys):

fuzzy_value = fuzz.ratio(captured.out, EXCEPTED_OUTPUT)

assert fuzzy_value > 80
assert fuzzy_value > 80, "You're not printing 'Hello, Snakelings!', check your code again."
3 changes: 0 additions & 3 deletions snakelings/exercises/3_assign_variable/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ version = 1

title = "Assign a varible"

[code]
execute_first = true

[pytest]
test_scripts = [
{module = "test_kitty_amount.py"}
Expand Down
4 changes: 0 additions & 4 deletions snakelings/exercises/4_assign_variable_wo_equal/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ version = 1

title = "Assign a varible"

[code]
use_pytest = true
execute_first = true

[pytest]
test_scripts = [
{module = "test_meow_meow.py"}
Expand Down
1 change: 1 addition & 0 deletions snakelings/exercises/4_assign_variable_wo_equal/readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Let's assign some variables! (2nd Edition)
Okay now, same thing as the last exercise but we're gonna change some *stuff* and you must keep the `:int` there.

# The Task!
Expand Down
1 change: 0 additions & 1 deletion snakelings/exercises/5_basic_math/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ version = 1

[code]
execute_first = true
use_pytest = true

[pytest]
test_scripts = [
Expand Down
17 changes: 17 additions & 0 deletions snakelings/terminal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os
import sys

__all__ = ()

def proper_clear():
"""
Handles clearing the terminal cross platform **properly**.
WIP! Only supports Linux and Windows atm.
"""

if sys.platform == "win32":
os.system("clear")

# Simply using the clear command won't work on terminals
# that have scrollback and will lead to side effects.
os.system("echo -ne '\033c'")

0 comments on commit 93bf794

Please sign in to comment.