-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathdecorators.py
More file actions
80 lines (62 loc) · 2.35 KB
/
decorators.py
File metadata and controls
80 lines (62 loc) · 2.35 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
# -*- coding: utf-8 -*-
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
import unittest
import gdb
def skip_with_type(typename):
try:
gdbtype = gdb.lookup_type(typename)
return unittest.skip(f"found type {typename}")
except gdb.error:
pass
return lambda func: func
def skip_without_type(typename):
try:
gdbtype = gdb.lookup_type(typename)
except gdb.error:
return unittest.skip(f"missing type {typename}")
return lambda func: func
def skip_with_symbol(symname):
symbol = gdb.lookup_symbol(symname, None)[0]
if symbol is not None:
return unittest.skip(f"found symbol {symname}")
return lambda func: func
def skip_without_symbol(symname):
symbol = gdb.lookup_symbol(symname, None)[0]
if symbol is None:
return unittest.skip(f"missing symbol {symname}")
return lambda func: func
def has_super_blocks(name):
from crash.subsystem.filesystem import for_each_super_block
for sb in for_each_super_block():
if sb['s_type']['name'].string() == name:
return True
return False
can_test = {}
def skip_with_supers(name):
if not name in can_test:
can_test[name] = has_super_blocks(name)
if not can_test[name]:
return lambda func: func
return unittest.skip(f"{name} file systems in image")
def skip_without_supers(name):
if not name in can_test:
can_test[name] = has_super_blocks(name)
if can_test[name]:
return lambda func: func
return unittest.skip(f"no {name} file systems in image")
def bad_command_line(fn, ignored=True):
"""Marks test to expect CommandLineError for unimplemented options"""
def test_decorator(fn):
def test_decorated(self, *args, **kwargs):
self.assertRaises(CommandLineError, fn, self, *args, **kwargs)
return test_decorated
test_decorator.__doc__ = fn.__doc__ + " (bad command line raises CommandLineError)"
return test_decorator
def unimplemented(fn, ignored=True):
"""Marks test to expect CommandError for unimplemented options"""
def test_decorator(fn):
def test_decorated(self, *args, **kwargs):
self.assertRaises(CommandError, fn, self, *args, **kwargs)
return test_decorated
test_decorator.__doc__ = fn.__doc__ + " (unimplemented command raises CommandError)"
return test_decorator