Passed
Push — master ( 684169...29f120 )
by Rafael S.
01:50
created

LogTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
dl 0
loc 37
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A accumulate_occurrences() 0 4 2
A test_accumulator_state() 0 5 2
A setUp() 0 8 1
A test_log() 0 4 2
1
"""Base class for Accumulator tests."""
2
3
from __future__ import absolute_import
4
5
import unittest
6
from trade_app.trade.holder import Accumulator
7
8
from fixtures.assets import ASSET
9
10
11
class LogTest(unittest.TestCase):
12
    """Base class for Accumulator tests."""
13
14
    maxDiff = None
15
    initial_state = None
16
    occurrences = []
17
    expected_log = {}
18
    expected_state = {
19
        'quantity': 0,
20
        'price': 0,
21
        'results': {},
22
    }
23
24
    def setUp(self):
25
        """Creates an accumulator and accumulates all occurrences."""
26
        self.accumulator = Accumulator(
27
            ASSET,
28
            state=self.initial_state,
29
            logging=True
30
        )
31
        self.accumulate_occurrences()
32
33
    def accumulate_occurrences(self):
34
        """Accumulates all occurrences defined in the test case."""
35
        for occurrence in self.occurrences:
36
            self.accumulator.accumulate(occurrence)
37
38
    def test_log(self):
39
        """Test the log for the defined occurrences."""
40
        if self.expected_log:
41
            self.assertEqual(self.accumulator.log, self.expected_log)
42
43
    def test_accumulator_state(self):
44
        """Verifies the state of the accumulator data."""
45
        for key in self.accumulator.state.keys():
46
            self.assertEqual(
47
                self.accumulator.state[key], self.expected_state[key]
48
            )
49