Example #1
0
 def test_metadata_explicit(self):
     cell = Cell(target=NoInherentCellSpecimen(),
                 key='value',
                 changes='never',
                 label='foo',
                 description='bar',
                 sort_key='baz')
     self.assertEqual(
         cell.metadata().naming,
         EnumRow(label='foo', description='bar', sort_key='baz'))
Example #2
0
 def __test_subscription(self, changes):
     o = NoInherentCellSpecimen()
     cell = Cell(o, 'value', changes=changes)
     st = CellSubscriptionTester(cell)
     o.value = 1
     if changes == 'explicit':
         cell.poll_for_change(specific_cell=True)
     st.expect_now(1)
     st.unsubscribe()
     o.value = 2
     st.advance()  # check for unwanted callbacks
Example #3
0
 def __test_subscription(self, changes):
     o = NoInherentCellSpecimen()
     cell = Cell(o, 'value', changes=changes)
     st = CellSubscriptionTester(cell)
     o.value = 1
     if changes == 'explicit':
         cell.poll_for_change(specific_cell=True)
     st.expect_now(1)
     st.unsubscribe()
     o.value = 2
     st.advance()  # check for unwanted callbacks
Example #4
0
 def __init__(self,
              send,
              root_object,
              root_url,
              subscription_context=the_subscription_context):
     self.__subscription_context = subscription_context
     self._send = send
     self.__root_object = root_object
     self._cell = Cell(self,
                       '_root_object',
                       type=ReferenceT(),
                       changes='never')
     self._lastSerial = 0
     root_registration = _StateStreamObjectRegistration(
         ssi=self,
         subscription_context=self.__subscription_context,
         obj=self._cell,
         serial=0,
         url=root_url,
         refcount=0)
     self._registered_objs = {self._cell: root_registration}
     self.__registered_serials = {
         root_registration.serial: root_registration
     }
     self._send_batch = []
     self.__batch_delay = None
     self.__root_url = root_url
     root_registration.send_now_if_needed()
Example #5
0
def _install_gain_cell(self, source_ref, rxd_ref, name):
    def gain_getter():
        source = source_ref[0]
        return 0 if source is None else source.get_gain(name, ch)

    def gain_setter(value):
        source = source_ref[0]
        if source is not None:
            source.set_gain(float(value), name, ch)
        rxd = rxd_ref[0]
        if rxd is not None:
            # The single gain and individual-stage gain controls have an unspecified relationship to each other. Thus, changing one must poll the other.
            rxd.state_changed('gain')

    gain_range = convert_osmosdr_range(source_ref[0].get_gain_range(name, ch),
                                       unit=units.dB)

    # TODO: There should be a type of Cell such that we don't have to setattr but still implement the storage unlike LooseCell
    setattr(self, 'get_' + name, gain_getter)
    setattr(self, 'set_' + name, gain_setter)
    return name, Cell(self,
                      name,
                      type=gain_range,
                      writable=True,
                      persists=True,
                      changes='this_setter',
                      label=name)
Example #6
0
def _install_gain_cell(self, source, name, callback):
    def gain_getter():
        return source.get_gain(name, ch)

    def gain_setter(value):
        source.set_gain(float(value), name, ch)

    gain_range = convert_osmosdr_range(source.get_gain_range(name, ch))

    # TODO: There should be a type of Cell such that we don't have to setattr
    setattr(self, 'get_' + name, gain_getter)
    setattr(self, 'set_' + name, gain_setter)
    callback(Cell(self, name, ctor=gain_range, writable=True, persists=True))
Example #7
0
def _install_gain_cell(self, sourceref, name, callback):
    def gain_getter():
        source = sourceref[0]
        return 0 if source is None else source.get_gain(name, ch)
    
    def gain_setter(value):
        source = sourceref[0]
        if source is not None:
            source.set_gain(float(value), name, ch)
    
    gain_range = convert_osmosdr_range(sourceref[0].get_gain_range(name, ch), unit=units.dB)
    
    # TODO: There should be a type of Cell such that we don't have to setattr but still implement the storage unlike LooseCell
    setattr(self, 'get_' + name, gain_getter)
    setattr(self, 'set_' + name, gain_setter)
    callback(Cell(self, name,
        type=gain_range,
        writable=True,
        persists=True,
        changes='this_setter',
        label=name))
Example #8
0
 def test_repr(self):
     cell = Cell(target=NoInherentCellSpecimen(),
                 key='value',
                 changes='never')
     self.assertEqual(repr(cell),
                      '<Cell <NoInherentCellSpecimen repr>.value>')
Example #9
0
 def test_metadata_default(self):
     cell = Cell(target=NoInherentCellSpecimen(),
                 key='value',
                 changes='never')
     self.assertEqual(cell.metadata().naming,
                      EnumRow(label='value', sort_key='value'))
Example #10
0
 def test_subscription_never(self):
     o = NoInherentCellSpecimen()
     cell = Cell(o, 'value', changes='never')
     st = CellSubscriptionTester(cell)
     o.value = 1
     st.advance()  # expected no callback even if we lie