Example #1
0
 def test_string(self):
     for value in ('x', 'Y', 'z'):
         b = Bool(value, true=('x', 'y', 'z'), false=(1, 2, 3))
         self.assertEqual(str(b), str(value))
     for value in (1, 2, 3):
         b = Bool(value, true=('x', 'y', 'z'), false=(1, 2, 3))
         self.assertEqual(str(b), str(value))
Example #2
0
 def test_invalid_type(self):
     mt = multitype(Bool.partial(true=('yes', ), false=('no', )), Float,
                    Tuple.partial(options=('a', 'b', 'c')))
     with self.assert_raises(
             ValueError, 'Not a boolean; Not a number; Invalid option: hi'):
         mt('hi')
     with self.assert_raises(
             ValueError, 'Not a boolean; Not a number; Invalid option: d'):
         mt('a', 'b', 'd')
Example #3
0
    def test_equality(self):
        B = Bool.partial(true=('x', 'y', 'z'), false=(1, 2, 3))
        self.assertEqual(B('x'), B('y'))
        self.assertEqual(B('y'), B('z'))
        self.assertEqual(B('z'), True)

        self.assertEqual(B(1), B(2))
        self.assertEqual(B(2), B(3))
        self.assertEqual(B(3), False)

        self.assertNotEqual(B('x'), None)
        self.assertNotEqual(B(2), None)
Example #4
0
 def test_truths_and_falsities(self):
     b = Bool('x', true=('x', 'y', 'z'), false=(1, 2, 3))
     self.assertEqual(b.truths, ('x', 'y', 'z'))
     self.assertEqual(b.falsities, (1, 2, 3))
Example #5
0
 def test_valid_values(self):
     self.assertTrue(Bool('x', true=('x', ), false=('o', )))
     self.assertFalse(Bool('O', true=('x', ), false=('o', )))
     with self.assert_raises(ValueError, 'Not a boolean'):
         Bool('0', true=('x', ), false=('o', ))
Example #6
0
 def test_syntax(self):
     self.assertEqual(
         Bool('1', true=('1', 1, 'on'), false=('0', 0, 'off')).syntax,
         '1/0|on/off')