コード例 #1
0
 def test_FloatAttr_thousand(self):
     """    it should instanciate the FloatAttr class and set it with a string
         which represents a float with thousand separators."""
     a = scraps.FloatAttr(thousandsep=',')
     a.__set__(self.obj, '2,222.22')
     self.assertAlmostEqual(a.__get__(self.obj), 2222.22)
     a = scraps.FloatAttr(thousandsep='.', decimalsep=',')
     a.__set__(self.obj, '2.222,22')
     self.assertAlmostEqual(a.__get__(self.obj), 2222.22)
コード例 #2
0
 def test_FloatAttr_repeat(self):
     """    it should instanciate the FloatAttr class and set the repeat parameter
         from Attribute."""
     a = scraps.FloatAttr(repeat=True)
     a.__set__(self.obj, '22.5')
     a.__set__(self.obj, '22.5')
     self.assertEquals(a.__get__(self.obj), [22.5, 22.5])
コード例 #3
0
 def test_FloatAttr_int(self):
     """it should instanciate the FloatAttr class and set it with an int."""
     a = scraps.FloatAttr()
     a.__set__(self.obj, 2)
     self.assertAlmostEqual(a.__get__(self.obj), 2.0)
コード例 #4
0
 def test_FloatAttr(self):
     """it should instanciate the FloatAttr class and set it with a valid string."""
     a = scraps.FloatAttr()
     a.__set__(self.obj, '2.2')
     self.assertAlmostEqual(a.__get__(self.obj), 2.2)
コード例 #5
0
 class MyScrap(scraps.Scrap):
     float_attr = scraps.FloatAttr()
コード例 #6
0
 class MyScrap(scraps.Scrap):
     float_attr = scraps.FloatAttr()
     _error_is_none = True
コード例 #7
0
 def test_FloatAttr_error(self):
     """    it should instanciate the FloatAttr class with an invalid string."""
     a = scraps.FloatAttr()
     with self.assertRaises(Exception):
         a.__set__(self.obj, '--')
コード例 #8
0
 def test_FloatAttr_percentage_comma(self):
     """    it should instanciate the FloatAttr class and set it with a string
         which represents a percentage and uses comma as decimal separator."""
     a = scraps.FloatAttr(decimalsep=',', percentage=True)
     a.__set__(self.obj, '22,5 %')
     self.assertAlmostEqual(a.__get__(self.obj), 22.5 / 100)
コード例 #9
0
 def test_FloatAttr_percentage(self):
     """    it should instanciate the FloatAttr class and set it with a string
         which represents a percentage, ie, a float followed by the symbol '%'."""
     a = scraps.FloatAttr(percentage=True)
     a.__set__(self.obj, '22 %')
     self.assertAlmostEqual(a.__get__(self.obj), 22. / 100)
コード例 #10
0
 def test_FloatAttr_comma(self):
     """    it should instanciate the FloatAttr class and set it with a string
         which represents a float but uses comma as decimal separator."""
     a = scraps.FloatAttr(decimalsep=',')
     a.__set__(self.obj, '2,2')
     self.assertAlmostEqual(a.__get__(self.obj), 2.2)
コード例 #11
0
 def test_FloatAttr_decimal(self):
     """it should instanciate the FloatAttr class and set it with a decimal."""
     from decimal import Decimal
     a = scraps.FloatAttr()
     a.__set__(self.obj, Decimal(2.2))
     self.assertAlmostEqual(a.__get__(self.obj), 2.2)