예제 #1
0
 def test_with_static_range_and_units(self):
     f = Float(setter=True,
               range=FloatRangeValidator(-1.0, 1.0, 0.01, unit='V'))
     u = get_unit_registry()
     assert f.pre_set(None, 0.1) == 0.1
     with raises(ValueError):
         f.pre_set(None, -2.0)
     assert f.pre_set(None, u.parse_expression('10 mV')) == 10.
     with raises(ValueError):
         f.pre_set(None, u.parse_expression('0.1 mV'))
예제 #2
0
    def test_with_dynamic_range_and_units(self):

        class RangeHolder(Parent):

            n = 0.0

            def _range_test(self):
                self.n += 100
                return FloatRangeValidator(-1000., 1000., step=self.n,
                                           unit='mV')

        o = RangeHolder()
        f = Float(setter=True, range='test', unit='V')
        assert f.pre_set(o, .1) == 0.1
        with raises(ValueError):
            f.pre_set(o, -5)
        o.discard_range('test')
        with raises(ValueError):
            f.pre_set(o, 0.1)

        u = get_unit_registry()
        assert f.pre_set(o, u.parse_expression('200 mV')) == 0.2
        with raises(ValueError):
            f.pre_set(o, u.parse_expression('100 mV'))
예제 #3
0
    def test_set_with_dynamic_range(self):

        class RangeHolder(Parent):

            n = 0.1

            def _range_test(self):
                self.n += .1
                return FloatRangeValidator(0.0, step=self.n)

        o = RangeHolder()
        f = Float(setter=True, range='test')
        assert f.pre_set(o, .2)
        with raises(ValueError):
            f.pre_set(o, -0.5)
        o.discard_range('test')
        with raises(ValueError):
            f.pre_set(o, 0.2)
예제 #4
0
 def test_set_with_static_range(self):
     f = Float(setter=True, range=FloatRangeValidator(0.0))
     assert f.pre_set(None, 0.1) == 0.1
     with raises(ValueError):
         f.pre_set(None, -1.0)
예제 #5
0
 def test_post_get_with_unit(self):
     f = Float(unit='V')
     assert hasattr(f.post_get(None, 0.1), 'magnitude')
     assert f.post_get(None, 0.1).to('mV').magnitude == 100.
예제 #6
0
 def test_post_get(self):
     f = Float()
     assert f.post_get(None, '0.1') == 0.1
예제 #7
0
 def test_set_with_unit(self):
     f = Float(setter=True, unit='mV')
     u = get_unit_registry()
     assert f.pre_set(None, u.parse_expression('10 V')) == 10000.