test_lib_agw_floatspin.py 2.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
import unittest
from unittests import wtc
import wx

import wx.lib.agw.floatspin as FS

#---------------------------------------------------------------------------

class lib_agw_floatspin_Tests(wtc.WidgetTestCase):

    def test_lib_agw_floatspinCtor(self):
        floatspin = FS.FloatSpin(self.frame, min_val=0, max_val=1,
                                 increment=0.01, value=0.1, agwStyle=FS.FS_LEFT)
        floatspin.SetFormat('%f')
        floatspin.SetDigits(2)

    def test_lib_agw_floatspinMethods(self):
        floatspin = FS.FloatSpin(self.frame, min_val=0, max_val=1,
                                 increment=0.01, value=0.1, agwStyle=FS.FS_LEFT)
        floatspin.SetFormat('%f')
        floatspin.SetDigits(2)

        # Some methods tests...
        self.assertTrue(floatspin.GetFormat() == '%f')
        self.assertEqual(floatspin.GetDigits(), 2)

        # Should not be possible to set 100...
        floatspin.SetValue(100.0)
        self.assertTrue(floatspin.GetValue() == 0.1)

        floatspin.SetValue(0.2)
        floatspin.SetToDefaultValue()
        self.assertTrue(floatspin.GetValue() == 0.1)

        self.assertTrue(floatspin.IsFinite(floatspin.GetValue()))
        self.assertTrue(not floatspin.InRange(50))
        self.assertTrue(floatspin.HasRange())

        self.assertEqual(floatspin.GetMin(), 0)
        self.assertEqual(floatspin.GetMax(), 1)
        self.assertEqual(floatspin.GetIncrement(), FS.FixedPoint(str(0.01), 20))


    def test_lib_agw_floatspinConstantsExist(self):
        FS.DEFAULT_PRECISION
        FS.FS_CENTRE
        FS.FS_LEFT
        FS.FS_READONLY
        FS.FS_RIGHT

    def test_lib_agw_floatspinEvents(self):
        FS.EVT_FLOATSPIN
        FS.wxEVT_FLOATSPIN

    def test_lib_agw_floatspin_fixedpoint(self):
        f1 = FS.FixedPoint(20)
        f2 = FS.FixedPoint(30)
        f3 = FS.FixedPoint("20", 20)
        f4 = FS.FixedPoint("20", 20)

        self.assertEqual(f1, 20)
        self.assertEqual(f2, 30)
        self.assertEqual(f3, f4)
        self.assertGreaterEqual(f2, f1)
        self.assertGreaterEqual(f2, 20)
        self.assertGreater(f2, 20)
        self.assertLessEqual(f1, f2)
        self.assertLessEqual(f1, 30)
        self.assertLess(f1, 30)

#---------------------------------------------------------------------------

if __name__ == '__main__':
    unittest.main()