Esempio n. 1
0
    def test_isdisjoint(self):
        self.assertTrue(self.rights.isdisjoint(A.Rights([A.CAP_WRITE])))
        self.assertTrue(self.rights.isdisjoint(A.Rights([])))
        self.assertTrue(self.rights.isdisjoint(set([])))

        self.assertFalse(self.rights.isdisjoint(A.Rights([A.CAP_READ])))
        self.assertFalse(self.rights.isdisjoint(A.Rights([A.CAP_READ,
                                                          A.CAP_WRITE])))
Esempio n. 2
0
    def test_isub(self):
        self.rights.add(A.CAP_ACCEPT)
        self.rights.add(A.CAP_BIND)

        for to_sub, expected in [
                (A.Rights([A.CAP_WRITE]), set(self.rights)),
                (A.Rights([A.CAP_BIND, A.CAP_ACCEPT]), set([A.CAP_READ])),
                ([A.CAP_READ], set([]))]:
            self.rights -= to_sub

            expected_rights = A.Rights(expected)
            self.assertEqual(expected_rights, self.rights)
            self.assertRightsSetEqual(expected_rights, self.rights)
Esempio n. 3
0
    def test_ior(self):
        prev = set(self.rights)

        for to_ior, func in [
                (A.Rights([A.CAP_READ, A.CAP_WRITE, A.CAP_BIND]),
                 lambda prev: prev | {A.CAP_WRITE, A.CAP_BIND}),
                (A.Rights([A.CAP_ACCEPT]),
                 lambda prev: prev | {A.CAP_ACCEPT}),
                ([A.CAP_EVENT],
                 lambda prev: prev | {A.CAP_EVENT})]:
            self.rights |= to_ior

            expected = prev = func(prev)
            expected = A.Rights(expected)

            self.assertEqual(expected, self.rights)
            self.assertRightsSetEqual(expected, self.rights)
Esempio n. 4
0
    def test_limitSocketPair(self):
        data = b'ok'

        sendRights = A.Rights([A.CAP_SEND])
        recvRights = A.Rights([A.CAP_RECV])

        sendRights.limitFile(self.socketSideA)
        recvRights.limitFile(self.socketSideB)

        # cross your fingers
        with self.assertRaisesWithErrno(socket.error, A.ENOTCAPABLE):
            self.socketSideB.sendall(data)

        with self.assertRaisesWithErrno(socket.error, A.ENOTCAPABLE):
            self.socketSideA.recv(1024)

        self.socketSideA.sendall(data)
        self.assertEqual(data, self.socketSideB.recv(len(data)))
Esempio n. 5
0
 def test_init_with_bad_rights(self):
     with self.assertRaises(A.SpyceError):
         A.Rights([1])
Esempio n. 6
0
 def setUp(self):
     super(TestRights, self).setUp()
     self.rights = A.Rights([A.CAP_READ])
Esempio n. 7
0
 def test_ge(self):
     self.assertGreater(self.rights, A.Rights(()))
     self.assertGreater(self.rights, set([]))
Esempio n. 8
0
 def test_le(self):
     self.assertLess(A.Rights(()), self.rights)
     self.assertLess(self.rights, set([A.CAP_READ, A.CAP_WRITE]))