Coverage for tests/test_bool.py: 100%

34 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-02-29 10:26 +0100

1""" 

2test for Bool() 

3""" 

4import unittest 

5 

6from stricto import Bool, Error 

7 

8 

9 

10class TestBool(unittest.TestCase): 

11 """ 

12 Tres Bool() 

13 """ 

14 def test_error_type(self): 

15 """ 

16 Test error type 

17 """ 

18 a = Bool() 

19 with self.assertRaises(Error) as e: 

20 a.set(12.3) 

21 self.assertEqual(e.exception.message, "Must be a bool") 

22 

23 def test_default(self): 

24 """ 

25 test default 

26 """ 

27 a = Bool(default=True) 

28 self.assertEqual(a, True) 

29 self.assertEqual(not a, False) 

30 

31 def test_not(self): 

32 """ 

33 Test not 

34 """ 

35 a = Bool(default=True) 

36 self.assertEqual(a, True) 

37 a.set(not a) 

38 self.assertEqual(a, False) 

39 

40 def test_not_null(self): 

41 """ 

42 Test notnull for a bool 

43 """ 

44 with self.assertRaises(Error) as e: 

45 a = Bool(notNone=True) 

46 self.assertEqual(e.exception.message, "Cannot be empty") 

47 a = Bool(notNone=True, default= True) 

48 with self.assertRaises(Error) as e: 

49 a.set(None) 

50 self.assertEqual(e.exception.message, "Cannot be empty") 

51 a = Bool() 

52 a.set(None) 

53 

54 def test_unset(self): 

55 """ 

56 Test unset for a boolean 

57 """ 

58 a = Bool() 

59 self.assertNotEqual(a, True) 

60 self.assertNotEqual(a, False) 

61 a.set(not a) 

62 self.assertNotEqual(a , True) 

63 self.assertEqual(a, False)