<commit_before>import mock
import unittest2

from akanda.router.drivers import route


class RouteTest(unittest2.TestCase):

    def setUp(self):
        self.mgr = route.RouteManager()

    def test_get_default_gateway_v6(self):
        output = 'route: writing to routing socket: No such process\n'
        with mock.patch.object(self.mgr, 'sudo') as sudo:
            sudo.return_value = output
            self.assertEqual(
                None,
                self.mgr._get_default_gateway('-inet6')
            )
            sudo.assert_called_with('-n', 'get', '-inet6', 'default')

    def test_get_default_gateway_v4(self):
        output = """<commit_msg>add unit test for parsing valid IPv6 route<commit_after>import mock
import unittest2

from akanda.router.drivers import route


class RouteTest(unittest2.TestCase):

    def setUp(self):
        self.mgr = route.RouteManager()

    def test_get_default_gateway_v6_missing(self):
        output = 'route: writing to routing socket: No such process\n'
        with mock.patch.object(self.mgr, 'sudo') as sudo:
            sudo.return_value = output
            self.assertEqual(
                None,
                self.mgr._get_default_gateway('-inet6')
            )
            sudo.assert_called_with('-n', 'get', '-inet6', 'default')

    def test_get_default_gateway_v6(self):
        output = """
   route to: ::
destination: ::
       mask: default
    gateway: fdee:9f85:83be::1
  interface: vio1
 if address: fdee:9f85:83be:0:f816:3eff:fe7b:6263
   priority: 8 (static)
      flags: <UP,GATEWAY,DONE,STATIC>
     use       mtu    expire
       0         0         0
"""
        with mock.patch.object(self.mgr, 'sudo') as sudo:
            sudo.return_value = output
            self.assertEqual(
                'fdee:9f85:83be::1',
                self.mgr._get_default_gateway('-inet6')
            )
            sudo.assert_called_with('-n', 'get', '-inet6', 'default')

    def test_get_default_gateway_v4(self):
        output = """
{'fraction_non_alphanumeric': 0.11221449851042702, 'fraction_numerical': 0.023833167825223437, 'mean_word_length': 2.2605177993527508, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2740204', 'n_tokens_mistral': 673, 'n_tokens_neox': 633, 'n_words': 131}