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 #154 from JoshKarpel/show-fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns authored May 1, 2020
2 parents c4f0ac1 + cec29b7 commit aae1f85
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 68 deletions.
66 changes: 40 additions & 26 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ toml = "^0.9.4"
pygments = "^2.4.2"
pprintpp = "^0.4.0"
cucumber-tag-expressions = "^2.0.0"
click-default-group = "^1.2.2"

[tool.poetry.dev-dependencies]
black = "^19.9b0"
Expand Down
9 changes: 9 additions & 0 deletions ward/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def name(self):
def path(self):
return self.fn.ward_meta.path

@property
def line_number(self) -> int:
return inspect.getsourcelines(self.fn)[1]

@property
def is_generator_fixture(self):
return inspect.isgeneratorfunction(inspect.unwrap(self.fn))
Expand Down Expand Up @@ -131,6 +135,9 @@ def get(
return fixtures.get(fixture_key)


_FIXTURES = []


def fixture(func=None, *, scope: Optional[Union[Scope, str]] = Scope.Test):
if not isinstance(scope, Scope):
scope = Scope.from_str(scope)
Expand All @@ -148,6 +155,8 @@ def fixture(func=None, *, scope: Optional[Union[Scope, str]] = Scope.Test):
else:
func.ward_meta = WardMeta(is_fixture=True, scope=scope, path=path)

_FIXTURES.append(func)

@wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
Expand Down
138 changes: 106 additions & 32 deletions ward/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import List, Optional, Tuple

import click
from click_default_group import DefaultGroup
from colorama import init
from cucumber_tag_expressions import parse as parse_tags
from cucumber_tag_expressions.model import Expression
Expand All @@ -17,14 +18,54 @@
from ward.config import set_defaults_from_config
from ward.rewrite import rewrite_assertions_in_tests
from ward.suite import Suite
from ward.terminal import SimpleTestResultWrite, get_exit_code
from ward.terminal import SimpleTestResultWrite, output_fixtures, get_exit_code

init()

sys.path.append(".")


@click.command(context_settings={"max_content_width": 100})
# TODO: simplify to use invoke_without_command and ctx.forward once https://github.com/pallets/click/issues/430 is resolved
@click.group(
context_settings={"max_content_width": 100},
cls=DefaultGroup,
default="test",
default_if_no_args=True,
)
@click.pass_context
def run(ctx: click.Context):
pass


config = click.option(
"--config",
type=click.Path(
exists=False, file_okay=True, dir_okay=False, readable=True, allow_dash=False
),
callback=set_defaults_from_config,
help="Read configuration from PATH.",
is_eager=True,
)
path = click.option(
"-p",
"--path",
type=click.Path(exists=True),
multiple=True,
is_eager=True,
help="Look for items in PATH.",
)
exclude = click.option(
"--exclude",
type=click.STRING,
multiple=True,
help="Paths to ignore while searching for items. Accepts glob patterns.",
)


@run.command()
@config
@path
@exclude
@click.option(
"--search",
help="Search test names, bodies, descriptions and module names for the search query and only run matching tests.",
Expand Down Expand Up @@ -53,35 +94,11 @@
default="standard",
help="Specify the order in which tests should run.",
)
@click.option(
"--exclude",
type=click.STRING,
multiple=True,
help="Paths to ignore while searching for tests. Accepts glob patterns.",
)
@click.option(
"--capture-output/--no-capture-output",
default=True,
help="Enable or disable output capturing.",
)
@click.version_option(version=__version__)
@click.option(
"--config",
type=click.Path(
exists=False, file_okay=True, dir_okay=False, readable=True, allow_dash=False
),
callback=set_defaults_from_config,
help="Read configuration from PATH.",
is_eager=True,
)
@click.option(
"-p",
"--path",
type=click.Path(exists=True),
multiple=True,
is_eager=True,
help="Look for tests in PATH.",
)
@click.option(
"--show-slowest",
type=int,
Expand All @@ -93,9 +110,12 @@
help="Print all tests without executing them",
default=False,
)
@click.version_option(version=__version__)
@click.pass_context
def run(
def test(
ctx: click.Context,
config: str,
config_path: Optional[Path],
path: Tuple[str],
exclude: Tuple[str],
search: Optional[str],
Expand All @@ -104,11 +124,10 @@ def run(
test_output_style: str,
order: str,
capture_output: bool,
config: str,
config_path: Optional[Path],
show_slowest: int,
dry_run: bool,
):
"""Run tests."""
start_run = default_timer()
paths = [Path(p) for p in path]
mod_infos = get_info_for_modules(paths, exclude)
Expand All @@ -127,12 +146,67 @@ def run(
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
)
writer.output_header(time_to_collect=time_to_collect)

results = writer.output_all_test_results(test_results, fail_limit=fail_limit)
time_taken = default_timer() - start_run
writer.output_test_result_summary(results, time_taken, show_slowest)

exit_code = get_exit_code(results)

sys.exit(exit_code.value)


@run.command()
@config
@path
@exclude
@click.option(
"--show-scopes/--no-show-scopes",
help="Display each fixture's scope.",
default=True,
)
@click.option(
"--show-docstrings/--no-show-docstrings",
help="Display each fixture's docstring.",
default=False,
)
@click.option(
"--show-direct-dependencies/--no-show-direct-dependencies",
help="Display the fixtures that each fixture depends on directly.",
default=False,
)
@click.option(
"--show-dependency-trees/--no-show-dependency-trees",
help="Display the entire dependency tree for each fixture.",
default=False,
)
@click.option(
"--full/--no-full",
help="Display all available information on each fixture.",
default=False,
)
@click.pass_context
def fixtures(
ctx: click.Context,
config: str,
config_path: Optional[Path],
path: Tuple[str],
exclude: Tuple[str],
show_scopes: bool,
show_docstrings: bool,
show_direct_dependencies: bool,
show_dependency_trees: bool,
full: bool,
):
"""Show information on fixtures."""
paths = [Path(p) for p in path]
mod_infos = get_info_for_modules(paths, exclude)
modules = list(load_modules(mod_infos))

output_fixtures(
show_scopes=show_scopes or full,
show_docstrings=show_docstrings or full,
show_direct_dependencies=show_direct_dependencies or full,
show_dependency_trees=show_dependency_trees or full,
)
Loading

0 comments on commit aae1f85

Please sign in to comment.