import unittest

from mopidy.utils import network

class FormatHostnameTest(unittest.TestCase):
    def setUp(self):
        self.has_ipv6 = network.has_ipv6

    def tearDown(self):
        network.has_ipv6 = self.has_ipv6

    def test_format_hostname_prefixes_ipv4_addresses_when_ipv6_available(self):
        network.has_ipv6 = True
        self.assertEqual(network.format_hostname('0.0.0.0'), '::ffff:0.0.0.0')
        self.assertEqual(network.format_hostname('1.0.0.1'), '::ffff:1.0.0.1')

    def test_format_hostname_does_nothing_when_only_ipv4_available(self):
        network.has_ipv6 = False
        self.assertEquals(network.format_hostname('0.0.0.0'), '0.0.0.0')

@@ -1,12 +1,24 @@
+import mock%0A
 import unitt
@@ -673,16 +673,665 @@
 0'), '0.0.0.0')%0A
+%0Aclass TryIPv6SocketTest(unittest.TestCase):%0A    @mock.patch('socket.has_ipv6', False)%0A    def test_system_that_claims_no_ipv6_support(self):%0A        self.assertFalse(network._try_ipv6_socket())%0A%0A    @mock.patch('socket.has_ipv6', True)%0A    @mock.patch('socket.socket')%0A    def test_system_with_broken_ipv6(self, socket_mock):%0A        socket_mock.side_effect = IOError()%0A        self.assertFalse(network._try_ipv6_socket())%0A%0A    @mock.patch('socket.has_ipv6', True)%0A    @mock.patch('socket.socket')%0A    def test_with_working_ipv6(self, socket_mock):%0A        socket_mock.return_value = mock.Mock()%0A        self.assertTrue(network._try_ipv6_socket())%0A

Add test for try_ipv6_socket