diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-02-28 22:25:22 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-02-28 22:25:22 (GMT) |
commit | 061cfb5258f27c895a070502d4f83a8c1a394561 (patch) | |
tree | 8c44a58404bd44a248eb2b4405c93e0faf75e834 /Lib/test/test_socket.py | |
parent | 8d0f257211186de3475dd996c3a32772d2e34456 (diff) | |
download | cpython-061cfb5258f27c895a070502d4f83a8c1a394561.zip cpython-061cfb5258f27c895a070502d4f83a8c1a394561.tar.gz cpython-061cfb5258f27c895a070502d4f83a8c1a394561.tar.bz2 |
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r-- | Lib/test/test_socket.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 5a5a214..d761a73 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -325,6 +325,26 @@ class GeneralModuleTests(unittest.TestCase): if not fqhn in all_host_names: self.fail("Error testing host resolution mechanisms. (fqdn: %s, all: %s)" % (fqhn, repr(all_host_names))) + @unittest.skipUnless(hasattr(socket, 'sethostname'), "test needs socket.sethostname()") + @unittest.skipUnless(hasattr(socket, 'gethostname'), "test needs socket.gethostname()") + def test_sethostname(self): + oldhn = socket.gethostname() + try: + socket.sethostname('new') + except socket.error as e: + if e.errno == errno.EPERM: + self.skipTest("test should be run as root") + else: + raise + try: + # running test as root! + self.assertEqual(socket.gethostname(), 'new') + # Should work with bytes objects too + socket.sethostname(b'bar') + self.assertEqual(socket.gethostname(), 'bar') + finally: + socket.sethostname(oldhn) + def testRefCountGetNameInfo(self): # Testing reference count for getnameinfo if hasattr(sys, "getrefcount"): |