Total Complexity | 3 |
Total Lines | 50 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | #!/usr/bin/env python3 |
||
2 | # -*- coding: utf-8 -*- |
||
3 | """ |
||
4 | Created on Thu Jun 27 14:01:21 2019 |
||
5 | |||
6 | @author: Paolo Cozzi <[email protected]> |
||
7 | """ |
||
8 | |||
9 | from unittest.mock import Mock, patch |
||
10 | |||
11 | |||
12 | # https://github.com/testing-cabal/mock/issues/139#issuecomment-122128815 |
||
13 | class PickableMock(Mock): |
||
14 | """Provide a __reduce__ method to allow pickling mock objects""" |
||
15 | |||
16 | def __reduce__(self): |
||
17 | return (Mock, ()) |
||
18 | |||
19 | |||
20 | class MetaDataValidationTestMixin(object): |
||
21 | """Mock read_in_ruleset and check_ruleset methods""" |
||
22 | |||
23 | def setUp(self): |
||
24 | # call base instance |
||
25 | super().setUp() |
||
26 | |||
27 | # mocking up image_validation methods |
||
28 | self.read_in_ruleset_patcher = patch( |
||
29 | "validation.helpers.validation.read_in_ruleset") |
||
30 | self.read_in_ruleset = self.read_in_ruleset_patcher.start() |
||
31 | |||
32 | self.check_ruleset_patcher = patch( |
||
33 | "validation.helpers.validation.check_ruleset") |
||
34 | self.check_ruleset = self.check_ruleset_patcher.start() |
||
35 | self.check_ruleset.return_value = [] |
||
36 | |||
37 | # patch check ruleset with a default value |
||
38 | result = PickableMock() |
||
39 | result.get_overall_status.return_value = "Pass" |
||
40 | result.get_messages.return_value = [] |
||
41 | self.check_ruleset.return_value = result |
||
42 | |||
43 | def tearDown(self): |
||
44 | # stopping mock objects |
||
45 | self.read_in_ruleset_patcher.stop() |
||
46 | self.check_ruleset_patcher.stop() |
||
47 | |||
48 | # calling base methods |
||
49 | super().tearDown() |
||
50 |