Example #1
0
class DemodulatorTester(object):
    """
    Set up an environment for testing a demodulator and do some fundamental tests.
    """
    def __init__(self, mode, state=None):
        # TODO: Refactor things so that we can take the demod ctor rather than a mode string
        if state is None:
            state = {}
        mode_def = lookup_mode(mode)
        if mode_def is None:
            raise Exception('No such mode is registered: ' + repr(mode))
        # TODO: Tell the simulated device to have no modulators, or have a simpler dummy source for testing, so we don't waste time on setup
        self.__top = Top(devices={'s1': SimulatedDevice()})
        (_, receiver) = self.__top.add_receiver(mode, key='a', state=state)
        self.__demodulator = receiver.get_demodulator()
        if not isinstance(self.__demodulator, mode_def.demod_class):
            raise Exception('Demodulator not of expected class: ' +
                            repr(self.__demodulator))
        self.__top.start()  # TODO overriding internals

    def close(self):
        if self.__top is not None:
            self.__top.stop()
            self.__top = None

    def __enter__(self):
        state_smoke_test(self.__demodulator)

    def __exit__(self, exc_type, exc_value, traceback):
        self.close()
Example #2
0
class DemodulatorTester(object):
    """
    Set up an environment for testing a demodulator and do some fundamental tests.
    """
    def __init__(self, mode, state=None):
        # TODO: Refactor things so that we can take the demod ctor rather than a mode string
        if state is None:
            state = {}
        mode_def = lookup_mode(mode)
        if mode_def is None:
            raise Exception('No such mode is registered: ' + repr(mode))
        # TODO: Tell the simulated device to have no modulators, or have a simpler dummy source for testing, so we don't waste time on setup
        self.__top = Top(devices={'s1': SimulatedDevice()})
        (_, receiver) = self.__top.add_receiver(mode, key='a', state=state)
        self.__demodulator = receiver.get_demodulator()
        if not isinstance(self.__demodulator, mode_def.demod_class):
            raise Exception('Demodulator not of expected class: ' + repr(self.__demodulator))
        self.__top.start()  # TODO overriding internals
    
    def close(self):
        if self.__top is not None:
            self.__top.stop()
            self.__top = None
    
    def __enter__(self):
        state_smoke_test(self.__demodulator)
    
    def __exit__(self, exc_type, exc_value, traceback):
        self.close()