Ezio Melotti avatar Ezio Melotti committed 9222c9d

#5421: add tests.

Comments (0)

Files changed (1)

Lib/test/test_socket.py

         self.assertRaises(socket.error, raise_gaierror,
                               "Error raising socket exception.")
 
+    def testSendtoErrors(self):
+        # Testing that sendto doens't masks failures. See #10169.
+        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+        self.addCleanup(s.close)
+        s.bind(('', 0))
+        sockname = s.getsockname()
+        # 2 args
+        with self.assertRaises(TypeError):
+            s.sendto('\u2620', sockname)
+        with self.assertRaises(TypeError):
+            s.sendto(5j, sockname)
+        with self.assertRaises(TypeError):
+            s.sendto(b'foo', None)
+        # 3 args
+        with self.assertRaises(TypeError):
+            s.sendto('\u2620', 0, sockname)
+        with self.assertRaises(TypeError):
+            s.sendto(5j, 0, sockname)
+        with self.assertRaises(TypeError):
+            s.sendto(b'foo', 0, None)
+        with self.assertRaises(TypeError):
+            s.sendto(b'foo', 'bar', sockname)
+        with self.assertRaises(TypeError):
+            s.sendto(b'foo', None, None)
+        # wrong number of args
+        with self.assertRaises(TypeError):
+            s.sendto(b'foo')
+        with self.assertRaises(TypeError):
+            s.sendto(b'foo', 0, sockname, 4)
+
     def testCrucialConstants(self):
         # Testing for mission critical constants
         socket.AF_INET
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.