def test_get_set_converts_correctly(self): """ Does get/set with different units convert correctly? """ context = None meter_log = Log((1,2,3),units=meters) setitem_units = {'depth':inch} getitem_units = {'depth':feet} adapter = UnitConversionAdapter(getitem_units=getitem_units, setitem_units=setitem_units) name, inch_log = adapter.adapt_setitem(context, 'depth', meter_log) self.assert_(all(inch_log==meter_log.as_units(inch))) name, feet_log = adapter.adapt_getitem(context, 'depth', inch_log) # Did the values get converted correctly? self.assert_(all(feet_log==meter_log.as_units(feet))) # Are the units assigned correctly? self.assert_(feet_log.units==feet) return
def test_adapt_getitem_converts_correctly(self): """ Does getitem convert units correctly? """ context = None old_log = Log((1,2,3),units=meters) getitem_units = {'depth':feet} adapter = UnitConversionAdapter(getitem_units=getitem_units) name, new_log = adapter.adapt_getitem(context, 'depth', old_log) # Did the values get converted correctly? self.assert_(all(new_log==old_log.as_units(feet))) # Are the units assigned correctly? self.assert_(new_log.units==feet) return
def test_getitem_converts_correctly(self): """ Does getitem convert units correctly? """ getitem_units = {"depth": feet} adapter = UnitConversionAdapter(getitem_units=getitem_units) old_log = Log((1, 2, 3), units=meters) self.context["depth"] = old_log self.context.push_adapter(adapter) new_log = self.context["depth"] # Did the values get converted correctly? self.assert_(all(new_log == old_log.as_units(feet))) # Are the units assigned correctly? self.assert_(new_log.units == feet) return
def test_getitem_converts_correctly(self): """ Does getitem convert units correctly? """ getitem_units = {'depth':feet} adapter = UnitConversionAdapter(getitem_units=getitem_units) old_log = Log((1,2,3),units=meters) self.context['depth'] = old_log self.context.push_adapter(adapter) new_log = self.context['depth'] # Did the values get converted correctly? self.assert_(all(new_log==old_log.as_units(feet))) # Are the units assigned correctly? self.assert_(new_log.units==feet) return
def test_setitem_converts_correctly(self): """ Does setitem convert units correctly? """ old_log = Log((1, 2, 3), units=meters) getitem_units = {"depth": feet} adapter = UnitConversionAdapter(getitem_units=getitem_units) self.context.push_adapter(adapter) # pass the log into the conversion adapter as meters self.context["depth"] = old_log # Now retreive the log from the underlying context. new_log = self.context["depth"] # Did the values get converted correctly? self.assert_(all(new_log == old_log.as_units(feet))) # Are the units assigned correctly? self.assert_(new_log.units == feet) return
def test_setitem_converts_correctly(self): """ Does setitem convert units correctly? """ old_log = Log((1,2,3),units=meters) getitem_units = {'depth':feet} adapter = UnitConversionAdapter(getitem_units=getitem_units) self.context.push_adapter(adapter) # pass the log into the conversion adapter as meters self.context['depth'] = old_log # Now retreive the log from the underlying context. new_log = self.context['depth'] # Did the values get converted correctly? self.assert_(all(new_log==old_log.as_units(feet))) # Are the units assigned correctly? self.assert_(new_log.units==feet) return