Skip to content

Commit

Permalink
Test Addon reattachment
Browse files Browse the repository at this point in the history
  • Loading branch information
tfarago committed May 30, 2016
1 parent 526bb21 commit 46283d9
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion concert/tests/integration/test_experiments.py
Expand Up @@ -10,12 +10,24 @@
from concert.experiments.base import Acquisition, Experiment, ExperimentError
from concert.experiments.imaging import (tomo_angular_step, tomo_max_speed,
tomo_projections_number, frames)
from concert.experiments.addons import Consumer, ImageWriter, Accumulator
from concert.experiments.addons import Addon, Consumer, ImageWriter, Accumulator
from concert.devices.cameras.dummy import Camera
from concert.tests import TestCase, suppressed_logging, assert_almost_equal, VisitChecker
from concert.storage import DummyWalker


class DummyAddon(Addon):
def __init__(self):
self.attached_num_times = 0
super(DummyAddon, self).__init__([])

def _attach(self):
self.attached_num_times += 1

def _detach(self):
self.attached_num_times -= 1


@suppressed_logging
def test_tomo_angular_step():
truth = np.arctan(2.0 / 100) * q.rad
Expand Down Expand Up @@ -215,3 +227,18 @@ def test_accumulation(self):
for consumer in acq.consumers:
self.assertFalse(isinstance(consumer, Accumulate))
self.assertEquals(acc.items, {})

def test_attach_num_times(self):
"""An attached addon cannot be attached the second time."""
addon = DummyAddon()
# Does nothing because it's attached during construction
addon.attach()
self.assertEqual(1, addon.attached_num_times)

# Detach
addon.detach()
self.assertEqual(0, addon.attached_num_times)

# Second time, cannot be called
addon.detach()
self.assertEqual(0, addon.attached_num_times)

0 comments on commit 46283d9

Please sign in to comment.