Example #1
0
class LogTest(unittest.TestCase):
    """Base class for Accumulator tests."""

    maxDiff = None
    initial_state = None
    occurrences = []
    expected_log = {}
    expected_state = {
        'quantity': 0,
        'price': 0,
        'results': {},
    }

    def setUp(self):
        """Creates an accumulator and accumulates all occurrences."""
        self.accumulator = Accumulator(ASSET,
                                       state=self.initial_state,
                                       logging=True)
        self.accumulate_occurrences()

    def accumulate_occurrences(self):
        """Accumulates all occurrences defined in the test case."""
        for occurrence in self.occurrences:
            self.accumulator.accumulate(occurrence)

    def test_log(self):
        """Test the log for the defined occurrences."""
        if self.expected_log:
            self.assertEqual(self.accumulator.log, self.expected_log)

    def test_accumulator_state(self):
        """Verifies the state of the accumulator data."""
        for key in self.accumulator.state.keys():
            self.assertEqual(self.accumulator.state[key],
                             self.expected_state[key])
Example #2
0
class TestBaseEventAccumulation(unittest.TestCase):
    """The the accumulation of an Event object by the Accumulator."""

    def setUp(self):
        self.acc = Accumulator(ASSET)
        self.acc.state['quantity'] = 100
        self.acc.state['price'] = 10
        self.acc.state['results'] = {'trades': 1200}
        event = DummyEvent(asset=ASSET, date='2015-09-29')
        self.acc.accumulate(event)

    def test_quantity_after_event(self):
        self.assertEqual(self.acc.state['quantity'], 100)

    def test_price_after_event(self):
        self.assertEqual(self.acc.state['price'], 10)

    def test_results_after_event(self):
        self.assertEqual(self.acc.state['results'], {'trades': 1200})
Example #3
0
class TestAccumulateExercise(unittest.TestCase):
    """Base class for Exercise accumulation tests."""

    def setUp(self):
        self.option_accumulator = Accumulator(OPTION1)
        self.subject_accumulator = Accumulator(ASSET)
        self.exercise = copy.deepcopy(EXERCISE_OPERATION5)

    def fetch_and_accumulate(self):
        """Accumulate a exercise operation on the asset accumulator.

        and on the option accumulator When accumulating operations,
        the Operation object should be passed to the accumulator
        of all its assets.
        """
        self.exercise.fetch_operations()
        for operation in self.exercise.operations:
            self.subject_accumulator.accumulate(operation)
            self.option_accumulator.accumulate(operation)
Example #4
0
class TestAccumulateOption00(unittest.TestCase):
    """Accumulate a Option operation."""
    def setUp(self):
        self.operation = copy.deepcopy(OPTION_OPERATION3)
        self.accumulator = Accumulator(OPTION1)
        self.accumulator.accumulate(self.operation)

    def test_returned_result(self):
        """Check the results of the operation."""
        self.assertEqual(self.operation.results, {})

    def test_accumulator_price(self):
        """Check the cost of the option on the accumulator."""
        self.assertEqual(self.accumulator.state['price'], 10)

    def test_accumulator_quantity(self):
        """Check the quantity of the option on the accumulator."""
        self.assertEqual(self.accumulator.state['quantity'], 100)

    def test_accumulator_results(self):
        """Check the results of the option on the accumulator."""
        self.assertEqual(self.accumulator.state['results'], {})
Example #5
0
class LogTest(unittest.TestCase):
    """Base class for Accumulator tests."""

    maxDiff = None
    initial_state = None
    occurrences = []
    expected_log = {}
    expected_state = {
        'quantity': 0,
        'price': 0,
        'results': {},
    }

    def setUp(self):
        """Creates an accumulator and accumulates all occurrences."""
        self.accumulator = Accumulator(
            ASSET,
            state=self.initial_state,
            logging=True
        )
        self.accumulate_occurrences()

    def accumulate_occurrences(self):
        """Accumulates all occurrences defined in the test case."""
        for occurrence in self.occurrences:
            self.accumulator.accumulate(occurrence)

    def test_log(self):
        """Test the log for the defined occurrences."""
        if self.expected_log:
            self.assertEqual(self.accumulator.log, self.expected_log)

    def test_accumulator_state(self):
        """Verifies the state of the accumulator data."""
        for key in self.accumulator.state.keys():
            self.assertEqual(
                self.accumulator.state[key], self.expected_state[key]
            )
class TestAccumulateOption00(unittest.TestCase):
    """Accumulate a Option operation."""

    def setUp(self):
        self.operation = copy.deepcopy(OPTION_OPERATION3)
        self.accumulator = Accumulator(OPTION1)
        self.accumulator.accumulate(self.operation)

    def test_returned_result(self):
        """Check the results of the operation."""
        self.assertEqual(self.operation.results, {})

    def test_accumulator_price(self):
        """Check the cost of the option on the accumulator."""
        self.assertEqual(self.accumulator.state['price'], 10)

    def test_accumulator_quantity(self):
        """Check the quantity of the option on the accumulator."""
        self.assertEqual(self.accumulator.state['quantity'], 100)

    def test_accumulator_results(self):
        """Check the results of the option on the accumulator."""
        self.assertEqual(self.accumulator.state['results'], {})