Beispiel #1
0
def test_numeric_string_with_units_check(self, set_name):
    from kivy.properties import NumericProperty
    from kivy.metrics import Metrics

    a = NumericProperty()
    if set_name:
        a.set_name(wid, 'a')
        a.link_eagerly(wid)
    else:
        a.link(wid, 'a')
        a.link_deps(wid, 'a')
    self.assertEqual(a.get(wid), 0)

    a.set(wid, '55dp')
    density = Metrics.density
    self.assertEqual(a.get(wid), 55 * density)
    self.assertEqual(a.get_format(wid), 'dp')

    a.set(wid, u'55dp')
    self.assertEqual(a.get(wid), 55 * density)
    self.assertEqual(a.get_format(wid), 'dp')

    a.set(wid, '99in')
    self.assertEqual(a.get(wid), 9504.0 * density)
    self.assertEqual(a.get_format(wid), 'in')

    a.set(wid, u'99in')
    self.assertEqual(a.get(wid), 9504.0 * density)
    self.assertEqual(a.get_format(wid), 'in')
Beispiel #2
0
def test_reference_child_update(self, set_name):
    from kivy.properties import NumericProperty, ReferenceListProperty

    x = NumericProperty(0)
    if set_name:
        x.set_name(wid, 'x')
        x.link_eagerly(wid)
    else:
        x.link(wid, 'x')
        x.link_deps(wid, 'x')
    y = NumericProperty(0)
    if set_name:
        y.set_name(wid, 'y')
        y.link_eagerly(wid)
    else:
        y.link(wid, 'y')
        y.link_deps(wid, 'y')
    pos = ReferenceListProperty(x, y)
    if set_name:
        pos.set_name(wid, 'pos')
        pos.link_eagerly(wid)
    else:
        pos.link(wid, 'pos')
        pos.link_deps(wid, 'pos')

    pos.get(wid)[0] = 10
    self.assertEqual(pos.get(wid), [10, 0])

    pos.get(wid)[:] = (20, 30)
    self.assertEqual(pos.get(wid), [20, 30])
Beispiel #3
0
def test_reference(self, set_name):
    from kivy.properties import NumericProperty, ReferenceListProperty

    x = NumericProperty(0)
    if set_name:
        x.set_name(wid, 'x')
        x.link_eagerly(wid)
    else:
        x.link(wid, 'x')
        x.link_deps(wid, 'x')
    y = NumericProperty(0)
    if set_name:
        y.set_name(wid, 'y')
        y.link_eagerly(wid)
    else:
        y.link(wid, 'y')
        y.link_deps(wid, 'y')
    pos = ReferenceListProperty(x, y)
    if set_name:
        pos.set_name(wid, 'pos')
        pos.link_eagerly(wid)
    else:
        pos.link(wid, 'pos')
        pos.link_deps(wid, 'pos')

    self.assertEqual(x.get(wid), 0)
    self.assertEqual(y.get(wid), 0)
    self.assertEqual(pos.get(wid), [0, 0])

    x.set(wid, 50)
    self.assertEqual(pos.get(wid), [50, 0])

    y.set(wid, 50)
    self.assertEqual(pos.get(wid), [50, 50])

    pos.set(wid, [0, 0])
    self.assertEqual(pos.get(wid), [0, 0])
    self.assertEqual(x.get(wid), 0)
    self.assertEqual(y.get(wid), 0)

    # test observer
    global observe_called
    observe_called = 0

    def observe(obj, value):
        global observe_called
        observe_called = 1

    pos.bind(wid, observe)

    self.assertEqual(observe_called, 0)
    x.set(wid, 99)
    self.assertEqual(observe_called, 1)
Beispiel #4
0
def test_numericcheck(self, set_name):
    from kivy.properties import NumericProperty

    a = NumericProperty()
    if set_name:
        a.set_name(wid, 'a')
        a.link_eagerly(wid)
    else:
        a.link(wid, 'a')
        a.link_deps(wid, 'a')
    self.assertEqual(a.get(wid), 0)
    a.set(wid, 99)
    self.assertEqual(a.get(wid), 99)
Beispiel #5
0
def test_numeric_string_without_units(self, set_name):
    from kivy.properties import NumericProperty

    a = NumericProperty()
    if set_name:
        a.set_name(wid, 'a')
        a.link_eagerly(wid)
    else:
        a.link(wid, 'a')
        a.link_deps(wid, 'a')
    self.assertEqual(a.get(wid), 0)

    a.set(wid, '2')
    self.assertEqual(a.get(wid), 2)
Beispiel #6
0
def test_propertynone(self, set_name):
    from kivy.properties import NumericProperty

    a = NumericProperty(0, allownone=True)
    if set_name:
        a.set_name(wid, 'a')
        a.link_eagerly(wid)
    else:
        a.link(wid, 'a')
        a.link_deps(wid, 'a')
    self.assertEqual(a.get(wid), 0)
    try:
        a.set(wid, None)
        self.assertEqual(a.get(wid), None)
    except ValueError:
        pass
    a.set(wid, 1)
    self.assertEqual(a.get(wid), 1)