import decimal import unittest from lesana import types class testTypes(unittest.TestCase): def setUp(self): pass def tearDown(self): pass def test_string(self): checker = types.LesanaString() s = checker.empty() self.assertEqual(s, "") s = checker.load("Hello World!") self.assertEqual(s, "Hello World!") def test_text(self): checker = types.LesanaText() s = checker.empty() self.assertEqual(s, "") s = checker.load("Hello World!") self.assertEqual(s, "Hello World!") def test_int(self): checker = types.LesanaInt() v = checker.empty() self.assertEqual(v, 0) v = checker.load("10") self.assertEqual(v, 10) v = checker.load(10.5) self.assertEqual(v, 10) for d in ("ten", "10.5"): with self.assertRaises(types.LesanaValueError): checker.load(d) def test_float(self): checker = types.LesanaFloat() v = checker.empty() self.assertEqual(v, 0.0) v = checker.load("10") self.assertEqual(v, 10) v = checker.load(10.5) self.assertEqual(v, 10.5) v = checker.load("10.5") self.assertEqual(v, 10.5) for d in ("ten"): with self.assertRaises(types.LesanaValueError): checker.load(d) def test_decimal(self): checker = types.LesanaDecimal() v = checker.empty() self.assertEqual(v, decimal.Decimal(0)) v = checker.load("10") self.assertEqual(v, decimal.Decimal(10)) v = checker.load(10.5) self.assertEqual(v, decimal.Decimal(10.5)) v = checker.load("10.5") self.assertEqual(v, decimal.Decimal(10.5)) for d in ("ten"): with self.assertRaises(types.LesanaValueError): checker.load(d) if __name__ == '__main__': unittest.main()