Ejemplo n.º 1
0
    def test_adapt_setitem_converts_correctly(self):
        """ Does setitem convert units correctly?
        """
        context = None
        old_log = UnitArray((1, 2, 3), units=meters)
        setitem_units = {'depth': feet}
        adapter = UnitConversionAdapter(setitem_units=setitem_units)

        # pass the log into the conversion adapter as meters
        name, new_log = adapter.adapt_setitem(context, 'depth', old_log)

        # Did the values get converted correctly?
        self.assertTrue(all(new_log == old_log.as_units(feet)))

        # Are the units assigned correctly?
        self.assertTrue(new_log.units == feet)

        return
    def test_adapt_setitem_converts_correctly(self):
        """ Does setitem convert units correctly?
        """
        context = None
        old_log = UnitArray((1, 2, 3), units=meters)
        setitem_units = {"depth": feet}
        adapter = UnitConversionAdapter(setitem_units=setitem_units)

        # pass the log into the conversion adapter as meters
        name, new_log = adapter.adapt_setitem(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_get_set_converts_correctly(self):
        """ Does get/set with different units convert correctly?
        """
        context = None
        meter_log = UnitArray((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
Ejemplo n.º 4
0
    def test_get_set_converts_correctly(self):
        """ Does get/set with different units convert correctly?
        """
        context = None
        meter_log = UnitArray((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.assertTrue(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.assertTrue(all(feet_log == meter_log.as_units(feet)))

        # Are the units assigned correctly?
        self.assertTrue(feet_log.units == feet)

        return