Ejemplo n.º 1
0
 def __error(self, plan):
     creator = FakeCreator(plan)
     parser = Parser(creator)
     try:
         parser.get_socket(IPAddr('0.0.0.0'), 0, socket.SOCK_DGRAM)
         self.fail("Not raised")
     except CreatorError as ce:
         self.assertTrue(creator.all_used())
         self.assertTrue(ce.fatal)
Ejemplo n.º 2
0
 def __error(self, plan):
     creator = FakeCreator(plan)
     parser = Parser(creator)
     try:
         parser.get_socket(IPAddr('0.0.0.0'), 0, socket.SOCK_DGRAM)
         self.fail("Not raised")
     except CreatorError as ce:
         self.assertTrue(creator.all_used())
         self.assertTrue(ce.fatal)
Ejemplo n.º 3
0
 def test_crash(self):
     """
     Tests that the parser correctly raises exception when it crashes
     unexpectedly.
     """
     creator = FakeCreator([('s', b'SU4\0\0\0\0\0\0'), ('r', b'')])
     parser = Parser(creator)
     try:
         parser.get_socket(IPAddr('0.0.0.0'), 0, 'UDP')
         self.fail("Not raised")
     except CreatorError as ce:
         self.assertTrue(creator.all_used())
         # Is the exception correct?
         self.assertTrue(ce.fatal)
         self.assertEqual(None, ce.errno)
Ejemplo n.º 4
0
 def test_crash(self):
     """
     Tests that the parser correctly raises exception when it crashes
     unexpectedly.
     """
     creator = FakeCreator([('s', b'SU4\0\0\0\0\0\0'), ('r', b'')])
     parser = Parser(creator)
     try:
         parser.get_socket(IPAddr('0.0.0.0'), 0, 'UDP')
         self.fail("Not raised")
     except CreatorError as ce:
         self.assertTrue(creator.all_used())
         # Is the exception correct?
         self.assertTrue(ce.fatal)
         self.assertEqual(None, ce.errno)
Ejemplo n.º 5
0
 def test_invalid_socktype(self):
     """
     Test invalid socket type is rejected
     """
     self.assertRaises(ValueError,
                       Parser(FakeCreator([])).get_socket,
                       IPAddr('0.0.0.0'), 42, 'RAW')
Ejemplo n.º 6
0
 def test_terminate_error3(self):
     """
     Test it reports an exception when there's error terminating the creator.
     This one sends data when it should have terminated.
     """
     creator = FakeCreator([('s', b'T'), ('r', b'Extra data')])
     parser = Parser(creator)
     self.__terminate_raises(parser)
Ejemplo n.º 7
0
 def test_terminate_error2(self):
     """
     Test it reports an exception when there's error terminating the creator.
     This one raises an error when sending data.
     """
     creator = FakeCreator([('e', None)])
     parser = Parser(creator)
     self.__terminate_raises(parser)
Ejemplo n.º 8
0
 def test_terminate_error1(self):
     """
     Test it reports an exception when there's error terminating the creator.
     This one raises an error when receiving the EOF.
     """
     creator = FakeCreator([('s', b'T'), ('e', None)])
     parser = Parser(creator)
     self.__terminate_raises(parser)
Ejemplo n.º 9
0
 def test_error(self):
     """
     Tests that the parser correctly raises non-fatal exception when
     the socket can not be created.
     """
     # We split the int to see if it can cope with data coming in
     # different packets
     intpart = struct.pack('@i', 42)
     creator = FakeCreator([('s', b'SU4\0\0\0\0\0\0'), ('r', b'ES' +
         intpart[:1]), ('r', intpart[1:])])
     parser = Parser(creator)
     try:
         parser.get_socket(IPAddr('0.0.0.0'), 0, 'UDP')
         self.fail("Not raised")
     except CreatorError as ce:
         self.assertTrue(creator.all_used())
         # Is the exception correct?
         self.assertFalse(ce.fatal)
         self.assertEqual(42, ce.errno)
Ejemplo n.º 10
0
 def test_error(self):
     """
     Tests that the parser correctly raises non-fatal exception when
     the socket can not be created.
     """
     # We split the int to see if it can cope with data coming in
     # different packets
     intpart = struct.pack('@i', 42)
     creator = FakeCreator([('s', b'SU4\0\0\0\0\0\0'),
                            ('r', b'ES' + intpart[:1]), ('r', intpart[1:])])
     parser = Parser(creator)
     try:
         parser.get_socket(IPAddr('0.0.0.0'), 0, 'UDP')
         self.fail("Not raised")
     except CreatorError as ce:
         self.assertTrue(creator.all_used())
         # Is the exception correct?
         self.assertFalse(ce.fatal)
         self.assertEqual(42, ce.errno)
Ejemplo n.º 11
0
 def test_invalid_family(self):
     """
     Test it rejects invalid address family.
     """
     # Note: this produces a bad logger output, since this address
     # can not be converted to string, so the original message with
     # placeholders is output. This should not happen in practice, so
     # it is harmless.
     addr = IPAddr('0.0.0.0')
     addr.family = 42
     self.assertRaises(ValueError,
                       Parser(FakeCreator([])).get_socket, addr, 42,
                       socket.SOCK_DGRAM)
Ejemplo n.º 12
0
 def __create(self, addr, socktype, encoded):
     creator = FakeCreator([('s', b'S' + encoded), ('r', b'S'), ('f', 42)])
     parser = Parser(creator)
     self.assertEqual(42, parser.get_socket(IPAddr(addr), 42, socktype))
Ejemplo n.º 13
0
 def __terminate(self):
     creator = FakeCreator([('s', b'T'), ('r', b'')])
     parser = Parser(creator)
     self.assertEqual(None, parser.terminate())
     self.assertTrue(creator.all_used())
     return parser
Ejemplo n.º 14
0
 def __create(self, addr, socktype, encoded):
     creator = FakeCreator([('s', b'S' + encoded), ('r', b'S'), ('f', 42)])
     parser = Parser(creator)
     self.assertEqual(42, parser.get_socket(IPAddr(addr), 42, socktype))
Ejemplo n.º 15
0
 def __terminate(self):
     creator = FakeCreator([('s', b'T'), ('r', b'')])
     parser = Parser(creator)
     self.assertEqual(None, parser.terminate())
     self.assertTrue(creator.all_used())
     return parser