Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b2cceb5
Interpreter --verbose as "pretty-print JSON output".
ericsnowcurrently Mar 6, 2019
8814e0a
Add ParentInfo (and fix up other info classes).
ericsnowcurrently Mar 12, 2019
367a05c
Capture parent info during discovery.
ericsnowcurrently Mar 12, 2019
fd3aced
Dump parent info by default.
ericsnowcurrently Mar 12, 2019
8e7cc45
Fix filenames on Windows.
ericsnowcurrently Mar 12, 2019
dbb6e1f
Fix a typo.
ericsnowcurrently Mar 12, 2019
d48286d
Add a __init__.py.
ericsnowcurrently Mar 12, 2019
6f9c503
Do not fail if tests were imported from other modules.
ericsnowcurrently Mar 12, 2019
de0fc92
Send the full source location.
ericsnowcurrently Mar 13, 2019
4219617
Preserve case for the source location.
ericsnowcurrently Mar 13, 2019
178c09b
Add tests for nested suites.
ericsnowcurrently Mar 13, 2019
355db29
Always show markers.
ericsnowcurrently Mar 13, 2019
906b8cf
Deal with multiple methods in a nested test suite.
ericsnowcurrently Mar 13, 2019
9abbc0f
Deal with patholigical parameterized tests.
ericsnowcurrently Mar 13, 2019
ffa03ee
Fix tests under python2.
ericsnowcurrently Mar 14, 2019
85a9699
Add some debugging helpers.
ericsnowcurrently Mar 14, 2019
1a8c8ab
Allow TestPath.func to be None.
ericsnowcurrently Mar 14, 2019
56355f4
Add TestInfo.kind.
ericsnowcurrently Mar 14, 2019
c0d433e
Do not log calls if "debugging".
ericsnowcurrently Mar 14, 2019
dbdb6dd
Deal with doctests.
ericsnowcurrently Mar 14, 2019
c8f83eb
Deal with doctests in DiscoveredTests._ensure_parent().
ericsnowcurrently Mar 14, 2019
39d3f0e
Drop debugging.
ericsnowcurrently Mar 14, 2019
3515d6e
Add --show-pytest CLI flag.
ericsnowcurrently Mar 14, 2019
63ee5a6
Add copyright notices.
ericsnowcurrently Mar 14, 2019
f26680b
Fix tests.
ericsnowcurrently Mar 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pythonFiles/testing_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
2 changes: 2 additions & 0 deletions pythonFiles/testing_tools/adapter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
26 changes: 20 additions & 6 deletions pythonFiles/testing_tools/adapter/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from __future__ import absolute_import

import argparse
Expand All @@ -7,10 +10,6 @@
from .errors import UnsupportedToolError, UnsupportedCommandError


# Set this to True to pretty-print the output.
DEBUG=False
#DEBUG=True

TOOLS = {
'pytest': {
'_add_subparser': pytest.add_cli_subparser,
Expand All @@ -22,6 +21,7 @@
}



def parse_args(
argv=sys.argv[1:],
prog=sys.argv[0],
Expand All @@ -40,6 +40,9 @@ def parse_args(
# Add "run" and "debug" subcommands when ready.
for cmdname in ['discover']:
sub = cmdsubs.add_parser(cmdname)
if cmdname == 'discover':
sub.add_argument('--simple', action='store_true')
sub.add_argument('--show-pytest', action='store_true')
subsubs = sub.add_subparsers(dest='tool')
for toolname in sorted(TOOLS):
try:
Expand All @@ -55,6 +58,14 @@ def parse_args(
cmd = ns.pop('cmd')
if not cmd:
parser.error('missing command')
if cmd == 'discover':
if '--simple' in toolargs:
toolargs.remove('--simple')
ns['simple'] = True
if '--show-pytest' in toolargs:
toolargs.remove('--show-pytest')
ns['show_pytest'] = True

tool = ns.pop('tool')
if not tool:
parser.error('missing tool')
Expand All @@ -75,8 +86,11 @@ def main(toolname, cmdname, subargs, toolargs,
except KeyError:
raise UnsupportedCommandError(cmdname)

result = run(toolargs, **subargs)
report_result(result, debug=DEBUG)
parents, result = run(toolargs, **subargs)
report_result(result, parents,
debug=('-v' in toolargs or '--verbose' in toolargs),
**subargs
)


if __name__ == '__main__':
Expand Down
3 changes: 3 additions & 0 deletions pythonFiles/testing_tools/adapter/errors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.


class UnsupportedToolError(ValueError):
def __init__(self, tool):
Expand Down
107 changes: 106 additions & 1 deletion pythonFiles/testing_tools/adapter/info.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,114 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from collections import namedtuple


class TestPath(namedtuple('TestPath', 'root relfile func sub')):
"""Where to find a single test."""

def __new__(cls, root, relfile, func, sub=None):
self = super(TestPath, cls).__new__(
cls,
str(root) if root else None,
str(relfile) if relfile else None,
str(func) if func else None,
[str(s) for s in sub] if sub else None,
)
return self

def __init__(self, *args, **kwargs):
if self.root is None:
raise TypeError('missing id')
if self.relfile is None:
raise TypeError('missing kind')
# self.func may be None (e.g. for doctests).
# self.sub may be None.


class ParentInfo(namedtuple('ParentInfo', 'id kind name root parentid')):

KINDS = ('folder', 'file', 'suite', 'function', 'subtest')

def __new__(cls, id, kind, name, root=None, parentid=None):
self = super(ParentInfo, cls).__new__(
cls,
str(id) if id else None,
str(kind) if kind else None,
str(name) if name else None,
str(root) if root else None,
str(parentid) if parentid else None,
)
return self

def __init__(self, *args, **kwargs):
if self.id is None:
raise TypeError('missing id')
if self.kind is None:
raise TypeError('missing kind')
if self.kind not in self.KINDS:
raise ValueError('unsupported kind {!r}'.format(self.kind))
if self.name is None:
raise TypeError('missing name')
if self.root is None:
if self.parentid is not None or self.kind != 'folder':
raise TypeError('missing root')
elif self.parentid is None:
raise TypeError('missing parentid')


class TestInfo(namedtuple('TestInfo', 'id name path lineno markers')):
class TestInfo(namedtuple('TestInfo', 'id name path source markers parentid kind')):
"""Info for a single test."""

MARKERS = ('skip', 'skip-if', 'expected-failure')
KINDS = ('function', 'doctest')

def __new__(cls, id, name, path, source, markers, parentid, kind='function'):
self = super(TestInfo, cls).__new__(
cls,
str(id) if id else None,
str(name) if name else None,
path or None,
str(source) if source else None,
[str(marker) for marker in markers or ()],
str(parentid) if parentid else None,
str(kind) if kind else None,
)
return self

def __init__(self, *args, **kwargs):
if self.id is None:
raise TypeError('missing id')
if self.name is None:
raise TypeError('missing name')
if self.path is None:
raise TypeError('missing path')
if self.source is None:
raise TypeError('missing source')
else:
srcfile, _, lineno = self.source.rpartition(':')
if not srcfile or not lineno or int(lineno) < 0:
raise ValueError('bad source {!r}'.format(self.source))
if self.markers:
badmarkers = [m for m in self.markers if m not in self.MARKERS]
if badmarkers:
raise ValueError('unsupported markers {!r}'.format(badmarkers))
if self.parentid is None:
raise TypeError('missing parentid')
if self.kind is None:
raise TypeError('missing kind')
elif self.kind not in self.KINDS:
raise ValueError('unsupported kind {!r}'.format(self.kind))


@property
def root(self):
return self.path.root

@property
def srcfile(self):
return self.source.rpartition(':')[0]

@property
def lineno(self):
return int(self.source.rpartition(':')[-1])
Loading