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