forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfo.py
More file actions
114 lines (95 loc) · 3.9 KB
/
info.py
File metadata and controls
114 lines (95 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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 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])