testsweet 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- testsweet/__init__.py +17 -0
- testsweet/__main__.py +28 -0
- testsweet/_catches.py +47 -0
- testsweet/_class_helpers.py +16 -0
- testsweet/_classify.py +48 -0
- testsweet/_config.py +79 -0
- testsweet/_discover.py +12 -0
- testsweet/_loaders.py +48 -0
- testsweet/_markers.py +15 -0
- testsweet/_params.py +26 -0
- testsweet/_resolve.py +105 -0
- testsweet/_runner.py +18 -0
- testsweet/_targets.py +96 -0
- testsweet/_walk.py +96 -0
- testsweet-0.1.2.dist-info/METADATA +97 -0
- testsweet-0.1.2.dist-info/RECORD +18 -0
- testsweet-0.1.2.dist-info/WHEEL +4 -0
- testsweet-0.1.2.dist-info/licenses/LICENSE +175 -0
testsweet/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from testsweet._catches import catch_exceptions, catch_warnings
|
|
2
|
+
from testsweet._config import ConfigurationError
|
|
3
|
+
from testsweet._discover import discover
|
|
4
|
+
from testsweet._markers import test
|
|
5
|
+
from testsweet._params import test_params, test_params_lazy
|
|
6
|
+
from testsweet._runner import run
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
'ConfigurationError',
|
|
10
|
+
'catch_exceptions',
|
|
11
|
+
'catch_warnings',
|
|
12
|
+
'discover',
|
|
13
|
+
'run',
|
|
14
|
+
'test',
|
|
15
|
+
'test_params',
|
|
16
|
+
'test_params_lazy',
|
|
17
|
+
]
|
testsweet/__main__.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import pathlib
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
from testsweet._config import load_config
|
|
5
|
+
from testsweet._runner import run
|
|
6
|
+
from testsweet._targets import discover_targets
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main(argv: list[str]) -> int:
|
|
10
|
+
saved_sys_path = list(sys.path)
|
|
11
|
+
try:
|
|
12
|
+
config = load_config(pathlib.Path.cwd())
|
|
13
|
+
groups = discover_targets(argv, config)
|
|
14
|
+
failed = False
|
|
15
|
+
for module, names in groups:
|
|
16
|
+
for name, exc in run(module, names=names):
|
|
17
|
+
if exc is None:
|
|
18
|
+
print(f'{name} ... ok')
|
|
19
|
+
else:
|
|
20
|
+
print(f'{name} ... FAIL: {type(exc).__name__}: {exc}')
|
|
21
|
+
failed = True
|
|
22
|
+
return 1 if failed else 0
|
|
23
|
+
finally:
|
|
24
|
+
sys.path[:] = saved_sys_path
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if __name__ == '__main__':
|
|
28
|
+
sys.exit(main(sys.argv[1:]))
|
testsweet/_catches.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class catch_exceptions:
|
|
5
|
+
def __init__(self) -> None:
|
|
6
|
+
self._excs: list[Exception] = []
|
|
7
|
+
|
|
8
|
+
def __enter__(self) -> list[Exception]:
|
|
9
|
+
return self._excs
|
|
10
|
+
|
|
11
|
+
def __exit__(self, exc_type, exc, tb) -> bool:
|
|
12
|
+
if exc is None:
|
|
13
|
+
return False
|
|
14
|
+
if isinstance(exc, Exception):
|
|
15
|
+
self._excs.append(exc)
|
|
16
|
+
return True
|
|
17
|
+
return False
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class catch_warnings:
|
|
21
|
+
def __init__(self) -> None:
|
|
22
|
+
self._warns: list[Warning] = []
|
|
23
|
+
self._catcher: warnings.catch_warnings | None = None
|
|
24
|
+
self._records: list[warnings.WarningMessage] | None = None
|
|
25
|
+
|
|
26
|
+
def __enter__(self) -> list[Warning]:
|
|
27
|
+
self._catcher = warnings.catch_warnings(
|
|
28
|
+
record=True,
|
|
29
|
+
action='always',
|
|
30
|
+
)
|
|
31
|
+
self._records = self._catcher.__enter__()
|
|
32
|
+
return self._warns
|
|
33
|
+
|
|
34
|
+
def __exit__(self, exc_type, exc, tb) -> None:
|
|
35
|
+
try:
|
|
36
|
+
assert self._records is not None
|
|
37
|
+
for r in self._records:
|
|
38
|
+
# `WarningMessage.message` is typed `Warning | str` in
|
|
39
|
+
# the stdlib stubs (since `warnings.warn` accepts a
|
|
40
|
+
# bare string), but the warnings machinery normalizes
|
|
41
|
+
# to a Warning before recording. Narrow for mypy.
|
|
42
|
+
assert isinstance(r.message, Warning)
|
|
43
|
+
self._warns.append(r.message)
|
|
44
|
+
finally:
|
|
45
|
+
assert self._catcher is not None
|
|
46
|
+
self._catcher.__exit__(None, None, None)
|
|
47
|
+
return None
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
def _public_methods(cls: type) -> list[str]:
|
|
2
|
+
seen: set[str] = set()
|
|
3
|
+
out: list[str] = []
|
|
4
|
+
for klass in cls.__mro__:
|
|
5
|
+
if klass is object:
|
|
6
|
+
continue
|
|
7
|
+
for name, value in vars(klass).items():
|
|
8
|
+
if name.startswith('_'):
|
|
9
|
+
continue
|
|
10
|
+
if not callable(value):
|
|
11
|
+
continue
|
|
12
|
+
if name in seen:
|
|
13
|
+
continue
|
|
14
|
+
seen.add(name)
|
|
15
|
+
out.append(name)
|
|
16
|
+
return out
|
testsweet/_classify.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import importlib
|
|
2
|
+
from types import ModuleType
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def _resolve_dotted(
|
|
6
|
+
target: str,
|
|
7
|
+
) -> tuple[ModuleType, list[str] | None]:
|
|
8
|
+
parts = target.split('.')
|
|
9
|
+
first_error: ModuleNotFoundError | None = None
|
|
10
|
+
|
|
11
|
+
# Try each prefix from longest to shortest.
|
|
12
|
+
for prefix_length in range(len(parts), 0, -1):
|
|
13
|
+
head = '.'.join(parts[:prefix_length])
|
|
14
|
+
tail_parts = parts[prefix_length:]
|
|
15
|
+
try:
|
|
16
|
+
module = importlib.import_module(head)
|
|
17
|
+
except ModuleNotFoundError as exc:
|
|
18
|
+
if not _is_missing_prefix_error(exc, head):
|
|
19
|
+
# The prefix exists but raised inside its own
|
|
20
|
+
# imports — propagate rather than mask as a bad
|
|
21
|
+
# selector.
|
|
22
|
+
raise
|
|
23
|
+
if first_error is None:
|
|
24
|
+
first_error = exc
|
|
25
|
+
continue
|
|
26
|
+
if not tail_parts:
|
|
27
|
+
return module, None
|
|
28
|
+
if len(tail_parts) > 2:
|
|
29
|
+
raise LookupError(
|
|
30
|
+
f'cannot resolve {target!r}: too many trailing '
|
|
31
|
+
f'segments after module {head!r}'
|
|
32
|
+
)
|
|
33
|
+
return module, ['.'.join(tail_parts)]
|
|
34
|
+
|
|
35
|
+
# No prefix imported. Re-raise the natural error.
|
|
36
|
+
assert first_error is not None
|
|
37
|
+
raise first_error
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _is_missing_prefix_error(
|
|
41
|
+
exc: ModuleNotFoundError,
|
|
42
|
+
head: str,
|
|
43
|
+
) -> bool:
|
|
44
|
+
# The prefix itself is what's missing, vs an unrelated import
|
|
45
|
+
# inside the prefix's module.
|
|
46
|
+
return exc.name is not None and (
|
|
47
|
+
exc.name == head or head.startswith(exc.name + '.')
|
|
48
|
+
)
|
testsweet/_config.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import pathlib
|
|
2
|
+
import tomllib
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
_VALID_KEYS = frozenset({'include_paths', 'exclude_paths', 'test_files'})
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ConfigurationError(Exception):
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(frozen=True)
|
|
14
|
+
class DiscoveryConfig:
|
|
15
|
+
include_paths: tuple[str, ...] = field(default=())
|
|
16
|
+
exclude_paths: tuple[str, ...] = field(default=())
|
|
17
|
+
test_files: tuple[str, ...] = field(default=())
|
|
18
|
+
project_root: pathlib.Path | None = field(default=None)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def load_config(start: pathlib.Path) -> DiscoveryConfig:
|
|
22
|
+
pyproject = _find_pyproject(start)
|
|
23
|
+
if pyproject is None:
|
|
24
|
+
return DiscoveryConfig()
|
|
25
|
+
project_root = pyproject.parent.resolve()
|
|
26
|
+
raw = tomllib.loads(pyproject.read_text())
|
|
27
|
+
section = raw.get('tool', {}).get('testsweet', {}).get('discovery', {})
|
|
28
|
+
return _build_config(section, project_root)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _find_pyproject(start: pathlib.Path) -> pathlib.Path | None:
|
|
32
|
+
current = start.resolve()
|
|
33
|
+
while True:
|
|
34
|
+
candidate = current / 'pyproject.toml'
|
|
35
|
+
if candidate.exists():
|
|
36
|
+
return candidate
|
|
37
|
+
if current.parent == current:
|
|
38
|
+
return None
|
|
39
|
+
current = current.parent
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _build_config(
|
|
43
|
+
section: dict,
|
|
44
|
+
project_root: pathlib.Path,
|
|
45
|
+
) -> DiscoveryConfig:
|
|
46
|
+
unknown = set(section) - _VALID_KEYS
|
|
47
|
+
if unknown:
|
|
48
|
+
raise ConfigurationError(
|
|
49
|
+
f'unknown key {sorted(unknown)[0]!r} in '
|
|
50
|
+
f'[tool.testsweet.discovery]'
|
|
51
|
+
)
|
|
52
|
+
return DiscoveryConfig(
|
|
53
|
+
include_paths=_to_string_tuple(
|
|
54
|
+
section.get('include_paths', []),
|
|
55
|
+
'include_paths',
|
|
56
|
+
),
|
|
57
|
+
exclude_paths=_to_string_tuple(
|
|
58
|
+
section.get('exclude_paths', []),
|
|
59
|
+
'exclude_paths',
|
|
60
|
+
),
|
|
61
|
+
test_files=_to_string_tuple(
|
|
62
|
+
section.get('test_files', []),
|
|
63
|
+
'test_files',
|
|
64
|
+
),
|
|
65
|
+
project_root=project_root,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _to_string_tuple(value: object, key: str) -> tuple[str, ...]:
|
|
70
|
+
if not isinstance(value, list):
|
|
71
|
+
raise ConfigurationError(
|
|
72
|
+
f'tool.testsweet.discovery.{key} must be a list of strings'
|
|
73
|
+
)
|
|
74
|
+
for item in value:
|
|
75
|
+
if not isinstance(item, str):
|
|
76
|
+
raise ConfigurationError(
|
|
77
|
+
f'tool.testsweet.discovery.{key} must be a list of strings'
|
|
78
|
+
)
|
|
79
|
+
return tuple(value)
|
testsweet/_discover.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from types import ModuleType
|
|
2
|
+
from typing import Callable
|
|
3
|
+
|
|
4
|
+
from testsweet._markers import TEST_MARKER
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def discover(module: ModuleType) -> list[Callable]:
|
|
8
|
+
return [
|
|
9
|
+
value
|
|
10
|
+
for value in vars(module).values()
|
|
11
|
+
if callable(value) and getattr(value, TEST_MARKER, False) is True
|
|
12
|
+
]
|
testsweet/_loaders.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import importlib
|
|
2
|
+
import importlib.util
|
|
3
|
+
import pathlib
|
|
4
|
+
import sys
|
|
5
|
+
from types import ModuleType
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _exec_module_from_path(path: pathlib.Path) -> ModuleType:
|
|
9
|
+
spec = importlib.util.spec_from_file_location(path.stem, path)
|
|
10
|
+
if spec is None or spec.loader is None:
|
|
11
|
+
raise ImportError(f'cannot load {path} as a module')
|
|
12
|
+
module = importlib.util.module_from_spec(spec)
|
|
13
|
+
spec.loader.exec_module(module)
|
|
14
|
+
return module
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _load_path(target: str) -> ModuleType:
|
|
18
|
+
return _exec_module_from_path(pathlib.Path(target).resolve())
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _load_path_for_walk(path: pathlib.Path) -> ModuleType:
|
|
22
|
+
info = _dotted_name_for_path(path)
|
|
23
|
+
if info is None:
|
|
24
|
+
return _exec_module_from_path(path)
|
|
25
|
+
dotted, rootdir = info
|
|
26
|
+
rootdir_str = str(rootdir)
|
|
27
|
+
if rootdir_str not in sys.path:
|
|
28
|
+
sys.path.insert(0, rootdir_str)
|
|
29
|
+
return importlib.import_module(dotted)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _dotted_name_for_path(
|
|
33
|
+
path: pathlib.Path,
|
|
34
|
+
) -> tuple[str, pathlib.Path] | None:
|
|
35
|
+
# Walk up while __init__.py is present; collect names. The
|
|
36
|
+
# rootdir is the first ancestor that does NOT contain
|
|
37
|
+
# __init__.py.
|
|
38
|
+
parts: list[str] = [path.stem]
|
|
39
|
+
parent = path.parent
|
|
40
|
+
while (parent / '__init__.py').exists():
|
|
41
|
+
parts.insert(0, parent.name)
|
|
42
|
+
if parent.parent == parent:
|
|
43
|
+
break
|
|
44
|
+
parent = parent.parent
|
|
45
|
+
if len(parts) == 1:
|
|
46
|
+
# Loose file; caller falls back to spec_from_file_location.
|
|
47
|
+
return None
|
|
48
|
+
return '.'.join(parts), parent
|
testsweet/_markers.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
TEST_MARKER = '__testsweet_test__'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test(target):
|
|
5
|
+
"""Mark a function or class as a test unit.
|
|
6
|
+
|
|
7
|
+
Applied to a function, the function is discovered and run as a
|
|
8
|
+
standalone test. Applied to a class, the class is discovered and
|
|
9
|
+
its public methods are run as tests; if the class implements the
|
|
10
|
+
context-manager protocol (`__enter__`/`__exit__`, typically by
|
|
11
|
+
inheriting `contextlib.AbstractContextManager`), the runner enters
|
|
12
|
+
it for the duration of its method invocations.
|
|
13
|
+
"""
|
|
14
|
+
setattr(target, TEST_MARKER, True)
|
|
15
|
+
return target
|
testsweet/_params.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from typing import Callable, Iterable
|
|
2
|
+
|
|
3
|
+
from testsweet._markers import TEST_MARKER
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
PARAMS_MARKER = '__testsweet_params__'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_params(args_iterable: Iterable) -> Callable:
|
|
10
|
+
materialized = tuple(args_iterable)
|
|
11
|
+
|
|
12
|
+
def decorator(func: Callable) -> Callable:
|
|
13
|
+
setattr(func, TEST_MARKER, True)
|
|
14
|
+
setattr(func, PARAMS_MARKER, materialized)
|
|
15
|
+
return func
|
|
16
|
+
|
|
17
|
+
return decorator
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_params_lazy(args_iterable: Iterable) -> Callable:
|
|
21
|
+
def decorator(func: Callable) -> Callable:
|
|
22
|
+
setattr(func, TEST_MARKER, True)
|
|
23
|
+
setattr(func, PARAMS_MARKER, args_iterable)
|
|
24
|
+
return func
|
|
25
|
+
|
|
26
|
+
return decorator
|
testsweet/_resolve.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
import itertools
|
|
3
|
+
from contextlib import nullcontext
|
|
4
|
+
from types import ModuleType
|
|
5
|
+
from typing import Any, Callable, Iterator
|
|
6
|
+
|
|
7
|
+
from testsweet._class_helpers import _public_methods
|
|
8
|
+
from testsweet._discover import discover
|
|
9
|
+
from testsweet._params import PARAMS_MARKER
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def resolve_units(
|
|
13
|
+
module: ModuleType,
|
|
14
|
+
names: list[str] | None = None,
|
|
15
|
+
) -> Iterator[tuple[str, Callable[[], Any]]]:
|
|
16
|
+
# `_build_plan` runs synchronously here (above
|
|
17
|
+
# `chain.from_iterable`), so `LookupError` for unmatched names
|
|
18
|
+
# fires at call time, before any iteration. The returned chain
|
|
19
|
+
# advances units sequentially: each `_expand_unit` generator is
|
|
20
|
+
# exhausted (running its `with cm:` `__exit__`) before the next
|
|
21
|
+
# one's `__enter__` runs. Per-class fixture lifecycles are
|
|
22
|
+
# therefore non-overlapping, even though the chain looks flat.
|
|
23
|
+
units = discover(module)
|
|
24
|
+
if names is None:
|
|
25
|
+
return itertools.chain.from_iterable(
|
|
26
|
+
_expand_unit(unit, None) for unit in units
|
|
27
|
+
)
|
|
28
|
+
plan = _build_plan(units, names)
|
|
29
|
+
return itertools.chain.from_iterable(
|
|
30
|
+
_expand_unit(unit, plan[unit.__qualname__])
|
|
31
|
+
for unit in units
|
|
32
|
+
if unit.__qualname__ in plan
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _expand_unit(
|
|
37
|
+
unit: Any,
|
|
38
|
+
method_filter: set[str] | None,
|
|
39
|
+
) -> Iterator[tuple[str, Callable[[], Any]]]:
|
|
40
|
+
if isinstance(unit, type):
|
|
41
|
+
instance = unit()
|
|
42
|
+
cm = (
|
|
43
|
+
instance
|
|
44
|
+
if hasattr(instance, '__enter__')
|
|
45
|
+
else nullcontext(instance)
|
|
46
|
+
)
|
|
47
|
+
with cm:
|
|
48
|
+
for method_name in _public_methods(unit):
|
|
49
|
+
if (
|
|
50
|
+
method_filter is not None
|
|
51
|
+
and method_name not in method_filter
|
|
52
|
+
):
|
|
53
|
+
continue
|
|
54
|
+
bound = getattr(instance, method_name)
|
|
55
|
+
yield from _expand_callable(bound, bound.__qualname__)
|
|
56
|
+
else:
|
|
57
|
+
yield from _expand_callable(unit, unit.__qualname__)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _expand_callable(
|
|
61
|
+
func: Callable[..., Any],
|
|
62
|
+
qualname: str,
|
|
63
|
+
) -> Iterator[tuple[str, Callable[[], Any]]]:
|
|
64
|
+
params = getattr(func, PARAMS_MARKER, None)
|
|
65
|
+
if params is None:
|
|
66
|
+
yield qualname, func
|
|
67
|
+
return
|
|
68
|
+
for i, args in enumerate(params):
|
|
69
|
+
yield f'{qualname}[{i}]', functools.partial(func, *args)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _build_plan(
|
|
73
|
+
units: list[Any],
|
|
74
|
+
names: list[str],
|
|
75
|
+
) -> dict[str, set[str] | None]:
|
|
76
|
+
# plan[unit_qualname] = None -> run as today (whole unit)
|
|
77
|
+
# = set -> run only these method names
|
|
78
|
+
plan: dict[str, set[str] | None] = {}
|
|
79
|
+
discovered_unit_names = {u.__qualname__: u for u in units}
|
|
80
|
+
unmatched: list[str] = []
|
|
81
|
+
for name in names:
|
|
82
|
+
if '.' in name:
|
|
83
|
+
head, _, method = name.partition('.')
|
|
84
|
+
unit = discovered_unit_names.get(head)
|
|
85
|
+
if (
|
|
86
|
+
unit is None
|
|
87
|
+
or not isinstance(unit, type)
|
|
88
|
+
or method not in _public_methods(unit)
|
|
89
|
+
):
|
|
90
|
+
unmatched.append(name)
|
|
91
|
+
continue
|
|
92
|
+
existing = plan.get(head, set())
|
|
93
|
+
if existing is None:
|
|
94
|
+
# already a whole-unit selector for this class — wins.
|
|
95
|
+
continue
|
|
96
|
+
existing.add(method)
|
|
97
|
+
plan[head] = existing
|
|
98
|
+
else:
|
|
99
|
+
if name not in discovered_unit_names:
|
|
100
|
+
unmatched.append(name)
|
|
101
|
+
continue
|
|
102
|
+
plan[name] = None # whole unit; class form wins
|
|
103
|
+
if unmatched:
|
|
104
|
+
raise LookupError(f'no test units matched: {sorted(unmatched)}')
|
|
105
|
+
return plan
|
testsweet/_runner.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from types import ModuleType
|
|
2
|
+
|
|
3
|
+
from testsweet._resolve import resolve_units
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def run(
|
|
7
|
+
module: ModuleType,
|
|
8
|
+
names: list[str] | None = None,
|
|
9
|
+
) -> list[tuple[str, Exception | None]]:
|
|
10
|
+
results: list[tuple[str, Exception | None]] = []
|
|
11
|
+
for name, call in resolve_units(module, names):
|
|
12
|
+
try:
|
|
13
|
+
call()
|
|
14
|
+
except Exception as exc:
|
|
15
|
+
results.append((name, exc))
|
|
16
|
+
else:
|
|
17
|
+
results.append((name, None))
|
|
18
|
+
return results
|
testsweet/_targets.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import pathlib
|
|
2
|
+
from types import ModuleType
|
|
3
|
+
|
|
4
|
+
from testsweet._classify import _resolve_dotted
|
|
5
|
+
from testsweet._config import DiscoveryConfig
|
|
6
|
+
from testsweet._loaders import _load_path, _load_path_for_walk
|
|
7
|
+
from testsweet._walk import (
|
|
8
|
+
_build_exclude_set,
|
|
9
|
+
_resolve_include_paths,
|
|
10
|
+
_walk_directory,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# A discovered test unit: a module, plus an optional list of selectors
|
|
15
|
+
# (dotted-name tails like 'Foo.bar') narrowing what to run within it.
|
|
16
|
+
# `None` means "run everything in this module".
|
|
17
|
+
TargetGroup = tuple[ModuleType, list[str] | None]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def discover_targets(
|
|
21
|
+
argv: list[str],
|
|
22
|
+
config: DiscoveryConfig,
|
|
23
|
+
) -> list[TargetGroup]:
|
|
24
|
+
excluded = _build_exclude_set(config)
|
|
25
|
+
raw: list[TargetGroup] = []
|
|
26
|
+
if not argv:
|
|
27
|
+
raw.extend(_bare_invocation(config, excluded))
|
|
28
|
+
else:
|
|
29
|
+
for arg in argv:
|
|
30
|
+
raw.extend(parse_target(arg, config, excluded))
|
|
31
|
+
|
|
32
|
+
# Group by module identity, preserving first-seen order via dict
|
|
33
|
+
# insertion order. Whole-module entries (names is None) win over
|
|
34
|
+
# selectors for the same module.
|
|
35
|
+
#
|
|
36
|
+
# Keying by id(module) is safe because `raw` holds a strong
|
|
37
|
+
# reference to every module for the duration of the loop — id()
|
|
38
|
+
# is only guaranteed unique among live objects.
|
|
39
|
+
by_id: dict[int, TargetGroup] = {}
|
|
40
|
+
for module, names in raw:
|
|
41
|
+
key = id(module)
|
|
42
|
+
existing = by_id.get(key)
|
|
43
|
+
if existing is None:
|
|
44
|
+
by_id[key] = (module, names)
|
|
45
|
+
continue
|
|
46
|
+
_, existing_names = existing
|
|
47
|
+
if existing_names is None or names is None:
|
|
48
|
+
by_id[key] = (module, None)
|
|
49
|
+
else:
|
|
50
|
+
by_id[key] = (module, existing_names + names)
|
|
51
|
+
return list(by_id.values())
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def parse_target(
|
|
55
|
+
target: str,
|
|
56
|
+
config: DiscoveryConfig | None = None,
|
|
57
|
+
excluded: set[pathlib.Path] | None = None,
|
|
58
|
+
) -> list[TargetGroup]:
|
|
59
|
+
if (
|
|
60
|
+
'/' in target
|
|
61
|
+
or target.endswith('.py')
|
|
62
|
+
or pathlib.Path(target).is_dir()
|
|
63
|
+
):
|
|
64
|
+
path = pathlib.Path(target).resolve()
|
|
65
|
+
if path.is_dir():
|
|
66
|
+
return [
|
|
67
|
+
(_load_path_for_walk(p), None)
|
|
68
|
+
for p in _walk_directory(
|
|
69
|
+
path,
|
|
70
|
+
config=config,
|
|
71
|
+
excluded=excluded,
|
|
72
|
+
)
|
|
73
|
+
]
|
|
74
|
+
return [(_load_path(target), None)]
|
|
75
|
+
return [_resolve_dotted(target)]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _bare_invocation(
|
|
79
|
+
config: DiscoveryConfig,
|
|
80
|
+
excluded: set[pathlib.Path],
|
|
81
|
+
) -> list[TargetGroup]:
|
|
82
|
+
roots = _resolve_include_paths(config)
|
|
83
|
+
if not roots:
|
|
84
|
+
roots = [pathlib.Path('.').resolve()]
|
|
85
|
+
out: list[TargetGroup] = []
|
|
86
|
+
for root in roots:
|
|
87
|
+
if root.is_file() and root.suffix == '.py':
|
|
88
|
+
out.append((_load_path_for_walk(root), None))
|
|
89
|
+
elif root.is_dir():
|
|
90
|
+
for path in _walk_directory(
|
|
91
|
+
root,
|
|
92
|
+
config=config,
|
|
93
|
+
excluded=excluded,
|
|
94
|
+
):
|
|
95
|
+
out.append((_load_path_for_walk(path), None))
|
|
96
|
+
return out
|
testsweet/_walk.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import fnmatch
|
|
2
|
+
import os
|
|
3
|
+
import pathlib
|
|
4
|
+
|
|
5
|
+
from testsweet._config import DiscoveryConfig
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
_EXCLUDED_DIR_NAMES = frozenset({'__pycache__', 'node_modules'})
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _resolve_include_paths(
|
|
12
|
+
config: DiscoveryConfig,
|
|
13
|
+
) -> list[pathlib.Path]:
|
|
14
|
+
if not config.include_paths or config.project_root is None:
|
|
15
|
+
return []
|
|
16
|
+
out: list[pathlib.Path] = []
|
|
17
|
+
for pattern in config.include_paths:
|
|
18
|
+
for match in config.project_root.glob(pattern):
|
|
19
|
+
out.append(match)
|
|
20
|
+
return out
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _build_exclude_set(
|
|
24
|
+
config: DiscoveryConfig,
|
|
25
|
+
) -> set[pathlib.Path]:
|
|
26
|
+
# Glob each exclude pattern and add every match (file or
|
|
27
|
+
# directory) directly. The walker checks each entry against this
|
|
28
|
+
# set before recursing, so an excluded directory prunes its whole
|
|
29
|
+
# subtree without us having to walk into it here.
|
|
30
|
+
if not config.exclude_paths or config.project_root is None:
|
|
31
|
+
return set()
|
|
32
|
+
excluded: set[pathlib.Path] = set()
|
|
33
|
+
for pattern in config.exclude_paths:
|
|
34
|
+
for match in config.project_root.glob(pattern):
|
|
35
|
+
excluded.add(match.resolve())
|
|
36
|
+
return excluded
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _walk_directory(
|
|
40
|
+
root: pathlib.Path,
|
|
41
|
+
config: DiscoveryConfig | None = None,
|
|
42
|
+
excluded: set[pathlib.Path] | None = None,
|
|
43
|
+
) -> list[pathlib.Path]:
|
|
44
|
+
# Symlinks (both directory and file) are not followed: we only
|
|
45
|
+
# consider entries that are real files / real directories. This
|
|
46
|
+
# avoids cycles and prevents picking up source files outside the
|
|
47
|
+
# walked tree. A test file deliberately reached via a symlink
|
|
48
|
+
# will not be discovered — the user must pass it as an explicit
|
|
49
|
+
# target, or set up `__init__.py` to make it a real package
|
|
50
|
+
# module.
|
|
51
|
+
out: list[pathlib.Path] = []
|
|
52
|
+
with os.scandir(root) as it:
|
|
53
|
+
entries = sorted(it, key=lambda e: e.name)
|
|
54
|
+
for entry in entries:
|
|
55
|
+
entry_path = pathlib.Path(entry.path)
|
|
56
|
+
if excluded is not None and entry_path.resolve() in excluded:
|
|
57
|
+
continue
|
|
58
|
+
if entry.is_dir(follow_symlinks=False):
|
|
59
|
+
if _is_excluded_dir(entry.name):
|
|
60
|
+
continue
|
|
61
|
+
out.extend(
|
|
62
|
+
_walk_directory(
|
|
63
|
+
entry_path,
|
|
64
|
+
config=config,
|
|
65
|
+
excluded=excluded,
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
elif entry.is_file(follow_symlinks=False) and entry.name.endswith(
|
|
69
|
+
'.py'
|
|
70
|
+
):
|
|
71
|
+
if not _accepts_file(entry_path, config, excluded):
|
|
72
|
+
continue
|
|
73
|
+
out.append(entry_path)
|
|
74
|
+
return out
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _accepts_file(
|
|
78
|
+
path: pathlib.Path,
|
|
79
|
+
config: DiscoveryConfig | None,
|
|
80
|
+
excluded: set[pathlib.Path] | None,
|
|
81
|
+
) -> bool:
|
|
82
|
+
if excluded is not None and path.resolve() in excluded:
|
|
83
|
+
return False
|
|
84
|
+
if config is not None and config.test_files:
|
|
85
|
+
if not any(
|
|
86
|
+
fnmatch.fnmatch(path.name, pattern)
|
|
87
|
+
for pattern in config.test_files
|
|
88
|
+
):
|
|
89
|
+
return False
|
|
90
|
+
return True
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _is_excluded_dir(name: str) -> bool:
|
|
94
|
+
if name.startswith('.'):
|
|
95
|
+
return True
|
|
96
|
+
return name in _EXCLUDED_DIR_NAMES
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: testsweet
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Python testing for humans
|
|
5
|
+
Project-URL: Homepage, https://github.com/kaapstorm/testsweet
|
|
6
|
+
Project-URL: Source, https://github.com/kaapstorm/testsweet
|
|
7
|
+
Project-URL: Documentation, https://github.com/kaapstorm/testsweet/blob/main/README.md
|
|
8
|
+
Project-URL: Changelog, https://github.com/kaapstorm/testsweet/blob/main/CHANGELOG.md
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Software Development :: Testing
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
Testsweet
|
|
23
|
+
=========
|
|
24
|
+
|
|
25
|
+
Python testing for humans
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Why?
|
|
29
|
+
----
|
|
30
|
+
|
|
31
|
+
Neither of the two most popular libraries for testing in Python,
|
|
32
|
+
[unittest](https://docs.python.org/3/library/unittest.html) and
|
|
33
|
+
[pytest](https://docs.pytest.org/), make it over the hurdle of the Zen
|
|
34
|
+
of Python.
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
Beautiful is better than ugly.
|
|
38
|
+
Explicit is better than implicit.
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
unittest is modeled closely on JUnit and the xUnit family of libraries.
|
|
42
|
+
Its strength is its familiarity to people who are accustomed to them.
|
|
43
|
+
Its weakness is its failure to take advantage of existing Python idioms
|
|
44
|
+
and conventions. It's not beautiful.
|
|
45
|
+
|
|
46
|
+
Pytest addresses a lot of the shortcomings of unittest, but the way that
|
|
47
|
+
[its fixtures](https://docs.pytest.org/en/stable/how-to/fixtures.html)
|
|
48
|
+
work is magical, especially when they are imported
|
|
49
|
+
[invisibly](https://docs.pytest.org/en/stable/how-to/writing_plugins.html#localplugin).
|
|
50
|
+
It doesn't make it past the second line of the Zen of Python.
|
|
51
|
+
|
|
52
|
+
Testsweet intends to be a Python testing library that uses existing
|
|
53
|
+
Python features and idioms: A kind and simple interface, explicit in its
|
|
54
|
+
architecture, enabling the tests that use it to be beautiful.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
Examples
|
|
58
|
+
--------
|
|
59
|
+
|
|
60
|
+
A test function:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from testsweet import test
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@test
|
|
67
|
+
def or_dicts():
|
|
68
|
+
assert {'foo': 1} | {'bar': 2} == {'foo': 1, 'bar': 2}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
A test class:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from testsweet import test
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@test
|
|
78
|
+
class OrThings:
|
|
79
|
+
def or_dicts(self):
|
|
80
|
+
assert {'foo': 1} | {'bar': 2} == {'foo': 1, 'bar': 2}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Running tests:
|
|
84
|
+
|
|
85
|
+
```shell
|
|
86
|
+
python -m testsweet tests.test_module.TestClass.test_method
|
|
87
|
+
python -m testsweet tests/test_module.py
|
|
88
|
+
python -m testsweet # Discover tests
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
Documentation
|
|
93
|
+
-------------
|
|
94
|
+
|
|
95
|
+
* [Getting Started](https://github.com/kaapstorm/testsweet/blob/main/docs/getting-started.md)
|
|
96
|
+
* [Reference](https://github.com/kaapstorm/testsweet/blob/main/docs/reference.md)
|
|
97
|
+
* [Contributing](https://github.com/kaapstorm/testsweet/blob/main/docs/contributing.md)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
testsweet/__init__.py,sha256=l5Vjq8gGglUOKhm4LKQn0GboqdnLjUoulPyAxykBOh4,453
|
|
2
|
+
testsweet/__main__.py,sha256=Wd2LbpY2TfR_sQdW3Lb0FBqwWUX0o_iymhWV0Tglztk,797
|
|
3
|
+
testsweet/_catches.py,sha256=-7d3TBuIwlyGm4rV-Ez3nXBU04wHVP5L3WTpesafVww,1519
|
|
4
|
+
testsweet/_class_helpers.py,sha256=h7Z1m-VWz4gjJajw3giBPN1QdPSdlH_1JfVa36j9Up8,471
|
|
5
|
+
testsweet/_classify.py,sha256=pShc16D_dqL1Y0IbWl2Yq4QyFBHCXQRuDJMSpLhd3V4,1532
|
|
6
|
+
testsweet/_config.py,sha256=iNNQnG2JNxNfQKkdhDToLg9PxonusQPMLkLjf_A_5T8,2317
|
|
7
|
+
testsweet/_discover.py,sha256=M9VMSEh8zuSvkKm-K8DGpipAGVXSxkIKP9inTKKp3Kw,305
|
|
8
|
+
testsweet/_loaders.py,sha256=zzo3B2qr-fGMFj-bqPBzkZqkPiXAgZi0hB_jdGjBJpI,1493
|
|
9
|
+
testsweet/_markers.py,sha256=38b2n0ReJIxmZAuucAhteCU7kHQYGe5VSka73InGUgw,563
|
|
10
|
+
testsweet/_params.py,sha256=d36VWRjnzhn-39FdKufCZExOjF-a1clVVn_2oMf_14Y,644
|
|
11
|
+
testsweet/_resolve.py,sha256=FSk0xPl5LaibRxfDZy40IrQUi4ec0IYzrZ6HsioajP0,3574
|
|
12
|
+
testsweet/_runner.py,sha256=Eb6waKC-FCz0YlpohWcfIX7uis91ZuyaAFIrOUIBt-s,471
|
|
13
|
+
testsweet/_targets.py,sha256=Z4YWXR9n9PBOtSM_KYqsmx_JSCaDzKkFbBTCkln0TAg,2997
|
|
14
|
+
testsweet/_walk.py,sha256=oeE4og1JooVyOoCSIA7OHTIBKdeMgBr1UgG1FtkU1pE,3086
|
|
15
|
+
testsweet-0.1.2.dist-info/METADATA,sha256=6VIzT-Rg37-sk1uh5G1TQNRcupUWnhT7FAhHK1WjKoA,2836
|
|
16
|
+
testsweet-0.1.2.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
17
|
+
testsweet-0.1.2.dist-info/licenses/LICENSE,sha256=CeipvOyAZxBGUsFoaFqwkx54aPnIKEtm9a5u2uXxEws,10142
|
|
18
|
+
testsweet-0.1.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|