# Path: PyChat/client/gui/helper/helperFunc.py
# def validate_host(host):
#     """
#     Checks the hostname
#     four chunks separated by 3 dots
#     each a valid integer(0 - 255)
#     """
#     bits = host.split('.')
#     try:
#         if len(bits) != 4:
#             raise ValueError
#         for bit in bits:
#             num = int(bit)
#             if num > 255 or num < 0:
#                 raise ValueError
#     except ValueError:
#         return False
#     return True


import unittest
from PyChat.client.gui.helper.helperFunc import validate_host
#!/usr/bin/env python2

##
# PyChat
# https://github.com/leosartaj/PyChat.git
#
# Copyright (c) 2014 Sartaj Singh
# Licensed under the MIT license.
##


class TestValidateHost(unittest.TestCase):
    """
    tests the validate_host function in helperFunc module
    """
    def _checkList(self, func, list_str, val=True):
        """
        Iterates a list 
        and checks if when func is called
        it returns val or not
        """
        for item in list_str:
            self.assertEqual(func(item), val)

    def test_correct_host(self):
        correct = '127.0.0.1'

# Path: PyChat/client/gui/helper/helperFunc.py
# def validate_host(host):
#     """
#     Checks the hostname
#     four chunks separated by 3 dots
#     each a valid integer(0 - 255)
#     """
#     bits = host.split('.')
#     try:
#         if len(bits) != 4:
#             raise ValueError
#         for bit in bits:
#             num = int(bit)
#             if num > 255 or num < 0:
#                 raise ValueError
#     except ValueError:
#         return False
#     return True


# Path: PyChat/client/gui/helper/tests/tests_helperFunc/test_validate_host.py
import unittest
from PyChat.client.gui.helper.helperFunc import validate_host

#!/usr/bin/env python2

##
# PyChat
# https://github.com/leosartaj/PyChat.git
#
# Copyright (c) 2014 Sartaj Singh
# Licensed under the MIT license.
##


class TestValidateHost(unittest.TestCase):
    """
    tests the validate_host function in helperFunc module
    """
    def _checkList(self, func, list_str, val=True):
        """
        Iterates a list 
        and checks if when func is called
        it returns val or not
        """
        for item in list_str:
            self.assertEqual(func(item), val)

    def test_correct_host(self):
        correct = '127.0.0.1'

        self.assertEqual(validate_host(correct), True)