Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #64 from darrenburns/dots
Browse files Browse the repository at this point in the history
Wrapping test runtime output
  • Loading branch information
darrenburns authored Dec 22, 2019
2 parents 49eae09 + f13fde9 commit e53ac07
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup

version = "0.20.0a0"
version = "0.21.0a0"
description = "A modern Python 3 test framework for finding and fixing flaws faster."
with open("README.md", "r") as fh:
if platform.system() != "Windows":
Expand Down
46 changes: 41 additions & 5 deletions ward/terminal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import traceback
from dataclasses import dataclass
from pathlib import Path
from textwrap import wrap
from typing import Dict, Generator, List, Optional, Any

import sys
Expand All @@ -17,6 +19,17 @@ def print_no_break(e: Any):
print(e, end="")


def multiline_description(s: str, indent: int, width: int) -> str:
wrapped = wrap(s, width)
if len(wrapped) == 1:
return wrapped[0]
rv = wrapped[0]
for line in wrapped[1:]:
indent_str = " " * indent
rv += f"\n{indent_str}{line}"
return rv


def output_test_result_line(test_result: TestResult):
colour = outcome_to_colour(test_result.outcome)
bg = f"on_{colour}"
Expand All @@ -32,7 +45,7 @@ def output_test_result_line(test_result: TestResult):
mod_name = lightblack(
f"{test_result.test.module_name}:"
f"{test_result.test.line_number}"
f"{iter_indicator}: "
f"{iter_indicator}:"
)
if (
test_result.outcome == TestOutcome.SKIP
Expand All @@ -45,10 +58,18 @@ def output_test_result_line(test_result: TestResult):
reason = ""

name_or_desc = test_result.test.description
indent = (
len(padded_outcome) +
len(test_result.test.module_name) +
len(str(test_result.test.line_number)) +
len(iter_indicator) +
4
)
width = get_terminal_size().width - indent
print(
colored(padded_outcome, color="grey", on_color=bg),
mod_name + name_or_desc,
reason,
mod_name,
multiline_description(name_or_desc + reason, indent=indent, width=width),
)


Expand Down Expand Up @@ -115,16 +136,31 @@ def print_dot(result):
def output_dots_module(
fail_limit: int, test_results_gen: Generator[TestResult, None, None]
) -> List[TestResult]:
current_path = ""
current_path = Path("")
rel_path = ""
dots_on_line = 0
num_failures = 0
max_dots_per_line = get_terminal_size().width - 40
all_results = []
try:
for result in test_results_gen:
all_results.append(result)
if result.test.path != current_path:
print_no_break(f"\n{result.test.path.relative_to(os.getcwd())}: ")
dots_on_line = 0
print()
current_path = result.test.path
rel_path = str(current_path.relative_to(os.getcwd()))
max_dots_per_line = get_terminal_size().width - len(rel_path) - 2 # subtract 2 for ": "
final_slash_idx = rel_path.rfind("/")
if final_slash_idx != -1:
print_no_break(lightblack(rel_path[:final_slash_idx + 1]) + rel_path[final_slash_idx + 1:] + ": ")
else:
print_no_break(f"\n{rel_path}: ")
print_dot(result)
dots_on_line += 1
if dots_on_line == max_dots_per_line:
print_no_break("\n" + " " * (len(rel_path) + 2))
dots_on_line = 0
if result.outcome == TestOutcome.FAIL:
num_failures += 1
if num_failures == fail_limit:
Expand Down

0 comments on commit e53ac07

Please sign in to comment.