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 #139 from mandarvaze/print-toml-path
Browse files Browse the repository at this point in the history
Show pyproject.toml path if found.
  • Loading branch information
darrenburns authored Mar 11, 2020
2 parents b35d8ae + a3e1454 commit dd67ae4
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 35 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ dev = [
ward = "ward.run:run"

[tool.ward]
path = ["tests"]
path = ["ward/tests"]
5 changes: 5 additions & 0 deletions ward/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def set_defaults_from_config(

project_root = find_project_root([Path(path) for path in search_paths])
file_config = read_config_toml(project_root, CONFIG_FILE)
if file_config:
config_path = project_root / "pyproject.toml"
else:
config_path = None
context.params["config_path"] = config_path
file_config = apply_multi_defaults(file_config, context.params)

if context.default_map is None:
Expand Down
2 changes: 1 addition & 1 deletion ward/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def build_unified_diff(lhs_repr, rhs_repr) -> str:
current_span = ""
current_span += line_to_rewrite[
index - 2
] # Subtract 2 to account for code at start of line
] # Subtract 2 to account for code at start of line
prev_char = char
index += 1

Expand Down
5 changes: 4 additions & 1 deletion ward/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def run(
order: str,
capture_output: bool,
config: str,
config_path: Optional[Path],
show_slowest: int,
dry_run: bool,
):
Expand All @@ -114,7 +115,9 @@ def run(
suite = Suite(tests=tests)
test_results = suite.generate_test_runs(order=order, dry_run=dry_run)

writer = SimpleTestResultWrite(suite=suite, test_output_style=test_output_style)
writer = SimpleTestResultWrite(
suite=suite, test_output_style=test_output_style, config_path=config_path,
)
results = writer.output_all_test_results(
test_results, time_to_collect=time_to_collect, fail_limit=fail_limit
)
Expand Down
19 changes: 14 additions & 5 deletions ward/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def output_dots_module(
if final_slash_idx != -1:
print_no_break(
lightblack(rel_path[: final_slash_idx + 1])
+ rel_path[final_slash_idx + 1:]
+ rel_path[final_slash_idx + 1 :]
+ ": "
)
else:
Expand All @@ -211,7 +211,7 @@ def output_dots_module(

def output_run_cancelled():
cprint(
"\n[WARD] Run cancelled - " "results for tests that ran shown below.",
"\n[WARD] Run cancelled - results for tests that ran shown below.",
color="yellow",
)

Expand All @@ -223,9 +223,12 @@ class TestResultWriterBase:
"dots-module": output_dots_module,
}

def __init__(self, suite: Suite, test_output_style: str):
def __init__(
self, suite: Suite, test_output_style: str, config_path: Optional[Path]
):
self.suite = suite
self.test_output_style = test_output_style
self.config_path = config_path
self.terminal_size = get_terminal_size()

def output_all_test_results(
Expand All @@ -236,8 +239,14 @@ def output_all_test_results(
) -> List[TestResult]:
python_impl = platform.python_implementation()
python_version = platform.python_version()
print(f"Ward {__version__}, {python_impl} {python_version}")
if self.config_path:
try:
path = self.config_path.relative_to(Path.cwd())
except ValueError:
path = self.config_path.name
print(f"Using config from {path}")
print(
f"Ward {__version__}, {python_impl} {python_version}\n"
f"Collected {self.suite.num_tests} tests "
f"in {time_to_collect:.2f} seconds."
)
Expand Down Expand Up @@ -521,7 +530,7 @@ def generate_chart(
- num_yellow_bars
- num_magenta_bars
)

if num_bars_remaining and num_green_bars:
num_green_bars += 1
num_bars_remaining -= 1
Expand Down
2 changes: 1 addition & 1 deletion tests/test_collect.py → ward/tests/test_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)
from ward.testing import Test, each

from tests.test_util import make_project
from ward.tests.utilities import make_project


def named():
Expand Down
6 changes: 4 additions & 2 deletions tests/test_config.py → ward/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def temp_config_file_hyphens():
@test("read_config_toml reads from only [tool.ward] section")
def _(tmp=temp_config_file):
conf = read_config_toml(Path(tempfile.gettempdir()), tmp.name)
assert conf == {"path": "test_path"}
assert "path" in conf
assert conf["path"] == "test_path"


@test("read_config_toml returns {} if config file doesnt exist")
Expand All @@ -76,7 +77,8 @@ def _(tmp=temp_config_missing):
)
def _(tmp=temp_config_file_hyphens):
conf = read_config_toml(Path(tempfile.gettempdir()), tmp.name)
assert conf == {"some_key": "some-value"}
assert "some_key" in conf
assert conf["some_key"] == "some-value"


@test("read_config_toml raises click.FileError if config file syntax invalid")
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test_fixtures.py → ward/tests/test_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List

from tests.utilities import testable_test
from ward.tests.utilities import testable_test
from ward import fixture, test, Scope
from ward.fixtures import Fixture, FixtureCache, using
from ward.testing import Test
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rewrite.py → ward/tests/test_rewrite.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ast

from tests.utilities import testable_test
from ward.tests.utilities import testable_test
from ward import test, fixture
from ward.rewrite import (
rewrite_assertions_in_tests,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_suite.py → ward/tests/test_suite.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest import mock

from tests.utilities import NUMBER_OF_TESTS, testable_test, example_test, module
from ward.tests.utilities import NUMBER_OF_TESTS, testable_test, example_test, module
from ward import fixture
from ward.models import Scope, SkipMarker
from ward.suite import Suite
Expand Down Expand Up @@ -435,7 +435,7 @@ def a():
def test_1(a=each(a, "second", a)):
events.append("running test")

suite = Suite(tests=[Test(fn=test_1, module_name="module1"), ])
suite = Suite(tests=[Test(fn=test_1, module_name="module1"),])

list(suite.generate_test_runs())

Expand Down
2 changes: 1 addition & 1 deletion tests/test_terminal.py → ward/tests/test_terminal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from tests.utilities import example_test
from ward.tests.utilities import example_test
from ward import using
from ward.terminal import outcome_to_colour, get_exit_code, ExitCode
from ward.testing import TestOutcome, each, test, TestResult
Expand Down
2 changes: 1 addition & 1 deletion tests/test_testing.py → ward/tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import sys

from tests.utilities import FORCE_TEST_PATH, testable_test
from ward.tests.utilities import FORCE_TEST_PATH, testable_test
from ward import Scope, raises
from ward.errors import ParameterisationError
from ward.fixtures import FixtureCache, fixture
Expand Down
19 changes: 1 addition & 18 deletions tests/test_util.py → ward/tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
import shutil
import tempfile
from pathlib import Path

from ward.tests.utilities import make_project
from ward import test, using, fixture
from ward.testing import each
from ward.util import (
Expand Down Expand Up @@ -31,22 +30,6 @@ def _():
assert project_root == Path(fs_root)


def make_project(root_file: str):
tempdir = Path(tempfile.gettempdir())
paths = [
tempdir / "project/a/b/c",
tempdir / "project/a/d",
tempdir / "project/a",
]
for path in paths:
path.mkdir(parents=True, exist_ok=True)

root_file = tempdir / f"project/{root_file}"
with open(root_file, "w+", encoding="utf-8"):
yield tempdir / "project"
shutil.rmtree(tempdir / "project")


@fixture
def fake_project_pyproject():
yield from make_project("pyproject.toml")
Expand Down
18 changes: 18 additions & 0 deletions tests/utilities.py → ward/tests/utilities.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import shutil
import tempfile
from collections import defaultdict
from pathlib import Path

Expand Down Expand Up @@ -65,3 +67,19 @@ def t(fix_a=f):
return fix_a

return Test(fn=t, module_name=module)


def make_project(root_file: str):
tempdir = Path(tempfile.gettempdir())
paths = [
tempdir / "project/a/b/c",
tempdir / "project/a/d",
tempdir / "project/a",
]
for path in paths:
path.mkdir(parents=True, exist_ok=True)

root_file = tempdir / f"project/{root_file}"
with open(root_file, "w+", encoding="utf-8"):
yield tempdir / "project"
shutil.rmtree(tempdir / "project")

0 comments on commit dd67ae4

Please sign in to comment.