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)
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])
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)
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)
class MyScrap(scraps.Scrap): float_attr = scraps.FloatAttr()
class MyScrap(scraps.Scrap): float_attr = scraps.FloatAttr() _error_is_none = True
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, '--')
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)
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)
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)
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)