Exemplo n.º 1
0
 def test_33214(self):
     with mock.patch('warnings.warn') as warn:
         t = pp.BitwiseInt(33214)
     self.assertEqual(warn.call_count, 1)
     self.assertEqual(t[0], 4)
     self.assertEqual(t.flag1, 0)
     self.assertEqual(t.flag2, 1)
Exemplo n.º 2
0
    def test_standard_operators(self):
        with mock.patch('warnings.warn') as warn:
            t = pp.BitwiseInt(323)
        self.assertEqual(warn.call_count, 1)

        self.assertTrue(t == 323)
        self.assertFalse(t == 324)

        self.assertFalse(t != 323)
        self.assertTrue(t != 324)

        self.assertTrue(t >= 323)
        self.assertFalse(t >= 324)

        self.assertFalse(t > 323)
        self.assertTrue(t > 322)

        self.assertTrue(t <= 323)
        self.assertFalse(t <= 322)

        self.assertFalse(t < 323)
        self.assertTrue(t < 324)

        self.assertTrue(t in [323])
        self.assertFalse(t in [324])
Exemplo n.º 3
0
 def test_3(self):
     with mock.patch('warnings.warn') as warn:
         t = pp.BitwiseInt(3)
     self.assertEqual(warn.call_count, 1)
     self.assertEqual(t[0], 3)
     self.assertTrue(t.flag1)
     self.assertTrue(t.flag2)
     self.assertRaises(AttributeError, getattr, t, "flag1024")
Exemplo n.º 4
0
 def test_negative_number(self):
     try:
         _ = pp.BitwiseInt(-5)
     except ValueError, err:
         self.assertEqual(
             str(err),
             'Negative numbers not supported with splittable integers object'
         )
Exemplo n.º 5
0
 def test_negative_number(self):
     with mock.patch('warnings.warn') as warn:
         try:
             _ = pp.BitwiseInt(-5)
         except ValueError as err:
             self.assertEqual(
                 str(err),
                 'Negative numbers not supported with splittable integers object'
             )
     self.assertEqual(warn.call_count, 1)
Exemplo n.º 6
0
 def test_128(self):
     t = pp.BitwiseInt(128)
     self.assertEqual(t.flag1, 0)
     self.assertEqual(t.flag2, 0)
     self.assertEqual(t.flag4, 0)
     self.assertEqual(t.flag8, 0)
     self.assertEqual(t.flag16, 0)
     self.assertEqual(t.flag32, 0)
     self.assertEqual(t.flag64, 0)
     self.assertEqual(t.flag128, 1)
Exemplo n.º 7
0
    def test_setting_flags(self):
        t = pp.BitwiseInt(3)
        self.assertEqual(t._value, 3)

        t.flag1 = False
        self.assertEqual(t._value, 2)
        t.flag2 = False
        self.assertEqual(t._value, 0)

        t.flag1 = True
        self.assertEqual(t._value, 1)
        t.flag2 = True
        self.assertEqual(t._value, 3)

        self.assertRaises(AttributeError, setattr, t, "flag1024", True)
        self.assertRaises(TypeError, setattr, t, "flag2", 1)

        t = pp.BitwiseInt(3, num_bits=11)
        t.flag1024 = True
        self.assertEqual(t._value, 1027)
Exemplo n.º 8
0
 def test_128(self):
     with mock.patch('warnings.warn') as warn:
         t = pp.BitwiseInt(128)
     self.assertEqual(warn.call_count, 1)
     self.assertEqual(t.flag1, 0)
     self.assertEqual(t.flag2, 0)
     self.assertEqual(t.flag4, 0)
     self.assertEqual(t.flag8, 0)
     self.assertEqual(t.flag16, 0)
     self.assertEqual(t.flag32, 0)
     self.assertEqual(t.flag64, 0)
     self.assertEqual(t.flag128, 1)
Exemplo n.º 9
0
    def test_323(self):
        t = pp.BitwiseInt(323)
        self.assertRaises(AttributeError, getattr, t, 'flag0')

        self.assertEqual(t.flag1, 1)
        self.assertEqual(t.flag2, 1)
        self.assertEqual(t.flag4, 0)
        self.assertEqual(t.flag8, 0)
        self.assertEqual(t.flag16, 0)
        self.assertEqual(t.flag32, 0)
        self.assertEqual(t.flag64, 1)
        self.assertEqual(t.flag128, 0)
        self.assertEqual(t.flag256, 1)
Exemplo n.º 10
0
    def test_323(self):
        with mock.patch('warnings.warn') as warn:
            t = pp.BitwiseInt(323)
        self.assertEqual(warn.call_count, 1)
        self.assertRaises(AttributeError, getattr, t, 'flag0')

        self.assertEqual(t.flag1, 1)
        self.assertEqual(t.flag2, 1)
        self.assertEqual(t.flag4, 0)
        self.assertEqual(t.flag8, 0)
        self.assertEqual(t.flag16, 0)
        self.assertEqual(t.flag32, 0)
        self.assertEqual(t.flag64, 1)
        self.assertEqual(t.flag128, 0)
        self.assertEqual(t.flag256, 1)
Exemplo n.º 11
0
    def test_setting_flags(self):
        with mock.patch('warnings.warn') as warn:
            t = pp.BitwiseInt(3)
        self.assertEqual(warn.call_count, 1)
        self.assertEqual(t._value, 3)

        t.flag1 = False
        self.assertEqual(t._value, 2)
        t.flag2 = False
        self.assertEqual(t._value, 0)

        t.flag1 = True
        self.assertEqual(t._value, 1)
        t.flag2 = True
        self.assertEqual(t._value, 3)

        self.assertRaises(AttributeError, setattr, t, "flag1024", True)
        self.assertRaises(TypeError, setattr, t, "flag2", 1)

        with mock.patch('warnings.warn') as warn:
            t = pp.BitwiseInt(3, num_bits=11)
        self.assertEqual(warn.call_count, 1)
        t.flag1024 = True
        self.assertEqual(t._value, 1027)
Exemplo n.º 12
0
    def test_standard_operators(self):
        t = pp.BitwiseInt(323)

        self.assertTrue(t == 323)
        self.assertFalse(t == 324)

        self.assertFalse(t != 323)
        self.assertTrue(t != 324)

        self.assertTrue(t >= 323)
        self.assertFalse(t >= 324)

        self.assertFalse(t > 323)
        self.assertTrue(t > 322)

        self.assertTrue(t <= 323)
        self.assertFalse(t <= 322)

        self.assertFalse(t < 323)
        self.assertTrue(t < 324)

        self.assertTrue(t in [323])
        self.assertFalse(t in [324])
Exemplo n.º 13
0
 def test_33214(self):
     t = pp.BitwiseInt(33214)
     self.assertEqual(t[0], 4)
     self.assertEqual(t.flag1, 0)
     self.assertEqual(t.flag2, 1)
Exemplo n.º 14
0
 def test_3(self):
     t = pp.BitwiseInt(3)
     self.assertEqual(t[0], 3)
     self.assertTrue(t.flag1)
     self.assertTrue(t.flag2)
     self.assertRaises(AttributeError, getattr, t, "flag1024")