Skip to content

Commit fe8610b

Browse files
authored
Merge pull request #1166 from kernelkit/infamy
Mix of test framework fixes and improvements
2 parents d38c3f3 + a0a4051 commit fe8610b

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

test/infamy/env.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ def get_password(self, node):
117117
return self.ptop.get_password(node)
118118

119119
def is_reachable(self, node, port):
120-
ip = neigh.ll6ping(port)
121-
if not ip:
122-
return False
120+
ip = neigh.ll6ping(port)
121+
if not ip:
122+
return False
123123

124-
return util.is_reachable(ip, self, self.get_password(node))
124+
return util.is_reachable(ip, self, self.get_password(node))
125125

126-
def attach(self, node, port="mgmt", protocol=None, test_reset=True, username = None, password = None):
126+
def attach(self, node, port="mgmt", protocol=None, test_reset=True, username=None, password=None):
127127
"""Attach to node on port using protocol."""
128128

129129
name = node
@@ -133,7 +133,6 @@ def attach(self, node, port="mgmt", protocol=None, test_reset=True, username = N
133133
else:
134134
mapping = None
135135

136-
137136
# Precedence:
138137
# 1. Caller specifies `protocol`
139138
# 2. User specifies `-t` when executing test
@@ -159,8 +158,10 @@ def attach(self, node, port="mgmt", protocol=None, test_reset=True, username = N
159158

160159
if protocol == "netconf":
161160
dev = netconf.Device(name,
162-
location=netconf.Location(cport, mgmtip,
163-
username,password),
161+
location=netconf.Location(cport,
162+
mgmtip,
163+
username,
164+
password),
164165
mapping=mapping,
165166
yangdir=self.args.yangdir)
166167
if test_reset:

test/infamy/restconf.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@ class Location:
2626

2727
def xpath_to_uri(xpath, extra=None):
2828
"""Convert xpath to HTTP URI"""
29-
# If the xpath has a
3029
pattern = r'\[(.*?)=["\'](.*?)["\']\]'
3130
matches = re.findall(pattern, xpath)
3231

32+
uri_path = xpath
3333
if matches:
3434
for key, value in matches:
3535
# replace [key=value] with =value
36-
uri_path = re.sub(rf'\[{re.escape(key)}=["\']{re.escape(value)}["\']\]', f'={value}', xpath)
37-
else:
38-
uri_path = xpath
36+
uri_path = re.sub(rf'\[{re.escape(key)}=["\']{re.escape(value)}["\']\]', f'={value}', uri_path)
3937

4038
# Append extra if provided
4139
if extra is not None:

test/infamy/tap.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __enter__(self):
3030
self.out.flush()
3131
return self
3232

33-
def __exit__(self, _, e, __):
33+
def __exit__(self, t, e, tb):
3434
now = datetime.datetime.now().strftime("%F %T")
3535
self.out.write(f"# Exiting ({now})\n")
3636
self.out.flush()
@@ -40,12 +40,16 @@ def __exit__(self, _, e, __):
4040
if not e:
4141
self._not_ok("Missing explicit test result\n")
4242
else:
43-
if type(e) in (TestPass, TestSkip):
43+
if t in (TestPass, TestSkip):
4444
self.out.write(f"{self.steps}..{self.steps}\n")
4545
self.out.flush()
4646
raise SystemExit(0)
47-
48-
traceback.print_exception(e, file=self.commenter)
47+
if t is AssertionError:
48+
traceback.print_tb(tb, file=self.commenter)
49+
self.out.write(f"{str(e)}\n")
50+
self.out.flush()
51+
else:
52+
traceback.print_exception(e, file=self.commenter)
4953

5054
if type(e) is subprocess.CalledProcessError:
5155
print("Failing subprocess stdout:\n", e.stdout)
@@ -95,7 +99,10 @@ def succeed(self):
9599
def skip(self):
96100
raise TestSkip()
97101

98-
def fail(self):
102+
def fail(self, message=None):
103+
if message:
104+
self.out.write(f"# {message}\n")
105+
self.out.flush()
99106
raise TestFail()
100107

101108

0 commit comments

Comments
 (0)