Conditions | 7 |
Total Lines | 35 |
Lines | 0 |
Ratio | 0 % |
1 | from plugin.core.helpers.variable import merge |
||
10 | @classmethod |
||
11 | def run(cls): |
||
12 | metadata = {} |
||
13 | |||
14 | # Retrieve names of test functions |
||
15 | names = [ |
||
16 | name for name in dir(cls) |
||
17 | if name.startswith('test_') |
||
18 | ] |
||
19 | |||
20 | if not names: |
||
21 | return cls.on_failure('No tests defined') |
||
22 | |||
23 | # Run tests |
||
24 | for name in names: |
||
25 | # Retrieve function by name |
||
26 | func = getattr(cls, name, None) |
||
27 | |||
28 | if not func: |
||
29 | return cls.on_failure('Unable to find function: %r' % name) |
||
30 | |||
31 | try: |
||
32 | # Run test function |
||
33 | result = func() |
||
34 | |||
35 | if not result: |
||
36 | continue |
||
37 | |||
38 | # Merge function result into `metadata` |
||
39 | merge(metadata, result, recursive=True) |
||
40 | except Exception, ex: |
||
41 | return cls.on_exception('Exception raised in %r: %s' % (name, ex)) |
||
42 | |||
43 | # Tests successful |
||
44 | return cls.on_success(metadata) |
||
45 | |||
78 |