Passed
Pull Request — master (#38)
by Paolo
03:00
created

validation.tests.common   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 23
dl 0
loc 50
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A MetaDataValidationTestMixin.tearDown() 0 7 1
A MetaDataValidationTestMixin.setUp() 0 19 1
A PickableMock.__reduce__() 0 2 1
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