"""
safe_test.py by Dalofeco

Defines test cases for the provided pyutils_dalofeco package.
"""
from pyutils_dalofeco import Safe


class TestSafe:

    @staticmethod
    def test_keys_in_dict():

        # Define test dict
        test_dict = {
            'unique': 2,
            'other': 4,
            'me': 'da',
            'not_checked': None,
        }

        # Define valid test keys
        valid_test_keys = ['unique', 'other', 'me']
        invalid_test_keys = ['unique', 'other', 'not_here']
        improper_type_test_keys = [dict(), 2]

        # Assertion cases
        assert Safe.keys_in_dict(test_dict, valid_test_keys) is True
        assert Safe.keys_in_dict(test_dict, invalid_test_keys) is False
        assert Safe.keys_in_dict(test_dict, improper_type_test_keys) is False
        assert Safe.keys_in_dict(None, 22) is False

    @staticmethod
    def test_which_key_in_dict():

        # Define test dict
        test_dict = {
            'train': 2,
            'test': 4,
            'dev': 'da',
            'validation': None,
        }

        # Define valid test keys
        key_options = ['unique', 'train', 'me']
        multiple_key_options = ['train', 'test', 'dev']
        no_valid_key = ['quantum', 'theory', 'of', 23]
        no_valid_bad_type = ['quantum', 'theory', 'of', 23]

        # Test proper operation with only one key
        assert Safe.which_key_in_dict(test_dict, key_options) == 'train'

        # Test multiple key options to return the first match
        assert Safe.which_key_in_dict(
            test_dict, multiple_key_options,
        ) == 'train'

        # Test no valid outcomes with proper args
        assert not Safe.which_key_in_dict(test_dict, no_valid_key)

        # Test invalid key types
        assert not Safe.which_key_in_dict(test_dict, no_valid_bad_type)

        # Test empty lists and dicts
        assert not Safe.which_key_in_dict({}, [])

        # Test improper types
        assert not Safe.which_key_in_dict([], {})

    @staticmethod
    def test_is_domain():
        valid_domains = [
            'yahoo.com',
            'realtek.com',
            'googlemail.com',
            'gmail.org',
            'facebook.net',
            'legit.co.uk',
            'me.com',
            'labanca.es',
            'truestory.com',
            'yahoo.com',
            'example.com',
            'subdomain.example.com',
            'example-one.com',
            'example.name',
            'example.museum',
            'example.co.jp',
            'example.com',
        ]

        invalid_domains = [
            'temporary',
            '%^%#$',
            'example.com>', 'example',
            'example.com (<NAME>)',
            'example',
            '-example.com',
            '111.222.333.44444',
            'example..com',
            '.red.com',
        ]

        # Test valid domains
        for valid_domain in valid_domains:
            assert Safe.is_domain(valid_domain)

        # Test invalid domains
        for invalid_domain in invalid_domains:
            assert not Safe.is_domain(invalid_domain)

        # Invalid type
        assert not Safe.is_domain(2)

    @staticmethod
    def test_is_ip_address():

        valid_ips = [
            '172.16.17.32',
            '8.8.8.8',
            '10.0.0.2',
            '172.16.58.3',
        ]

        invalid_ips = [
            '2.2.',
            '234.343.3333.23',
            '172.16.58.3.345',
        ]

        # Test valid ips
        for valid_ip in valid_ips:
            assert Safe.is_ip_address(valid_ip)

        # Test invalid ips
        for invalid_ip in invalid_ips:
            assert not Safe.is_ip_address(invalid_ip)

        # Test invalid data type
        assert not Safe.is_ip_address(2)

    @staticmethod
    def test_is_email():

        # Define valid emails of various formats in list
        valid_emails = [
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            'email@172.16.17.32',
            '<EMAIL>',
            '<EMAIL>',
            '_______<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
        ]

        # Define invalid emails of various formats in list
        invalid_emails = [
            '<EMAIL>',
            'herewego@temporary',
            '<EMAIL>',
            'plainaddress',
            '#@%^%#$@#$@#.com',
            '@example.com',
            '<NAME> <<EMAIL>>',
            '<EMAIL>',
            '<EMAIL>',
            <EMAIL>',
            '<EMAIL>',
            'email..<EMAIL>',
            'あいうえ<EMAIL>',
            '<EMAIL> (<NAME>)',
            'email@<EMAIL>',
            '<EMAIL>',
            'email@111.222.333.44444',
            '<EMAIL>',
            'Abc..<EMAIL>',
        ]

        # Assertion cases for all emails
        for valid_email in valid_emails:
            assert Safe.is_email(valid_email)
        for invalid_email in invalid_emails:
            assert not Safe.is_email(invalid_email)

        # Test for bad argument type
        assert not Safe.is_email(2)

    @staticmethod
    def test_is_namespace_email():

        # Define valid emails of various formats in list
        valid_emails = [
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>@{}.es',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
        ]

        # Define invalid emails of various formats in list
        invalid_emails = [
            '<EMAIL>',
            '<EMAIL>',
            <EMAIL>',
            '<EMAIL>',
            'herewego@{}',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
        ]

        # Define valid namespaces
        valid_namespaces = [
            'google', 'gmail', 'realtek',
            'however', 'twenty.coordinate', '2345',
        ]

        # Define invalid namespaces
        invalid_namespaces = ['rau*d', 'h&8']

        # Assertion cases for all emails
        for valid_email in valid_emails:
            for valid_namespace in valid_namespaces:
                assert Safe.is_valid_namespace_email(
                    valid_email.format(valid_namespace), valid_namespace,
                ) is True
            for invalid_namespace in invalid_namespaces:
                assert Safe.is_valid_namespace_email(
                    valid_email.format(
                        invalid_namespace,
                    ), invalid_namespace,
                ) is False

        for invalid_email in invalid_emails:
            for valid_namespace in valid_namespaces:
                assert Safe.is_valid_namespace_email(
                    invalid_email.format(valid_namespace), valid_namespace,
                ) is False
            for invalid_namespace in invalid_namespaces:
                assert Safe.is_valid_namespace_email(
                    invalid_email.format(
                        invalid_namespace,
                    ), invalid_namespace,
                ) is False

        # Test improper types
        assert Safe.is_valid_namespace_email(2, 'da') is False
        assert Safe.is_valid_namespace_email('do', dict()) is False

"""
safe_test.py by Dalofeco

Defines test cases for the provided pyutils_dalofeco package.
"""
from pyutils_dalofeco import Safe


class TestSafe:

    @staticmethod
    def test_keys_in_dict():

        # Define test dict
        test_dict = {
            'unique': 2,
            'other': 4,
            'me': 'da',
            'not_checked': None,
        }

        # Define valid test keys
        valid_test_keys = ['unique', 'other', 'me']
        invalid_test_keys = ['unique', 'other', 'not_here']
        improper_type_test_keys = [dict(), 2]

        # Assertion cases
        assert Safe.keys_in_dict(test_dict, valid_test_keys) is True
        assert Safe.keys_in_dict(test_dict, invalid_test_keys) is False
        assert Safe.keys_in_dict(test_dict, improper_type_test_keys) is False
        assert Safe.keys_in_dict(None, 22) is False

    @staticmethod
    def test_which_key_in_dict():

        # Define test dict
        test_dict = {
            'train': 2,
            'test': 4,
            'dev': 'da',
            'validation': None,
        }

        # Define valid test keys
        key_options = ['unique', 'train', 'me']
        multiple_key_options = ['train', 'test', 'dev']
        no_valid_key = ['quantum', 'theory', 'of', 23]
        no_valid_bad_type = ['quantum', 'theory', 'of', 23]

        # Test proper operation with only one key
        assert Safe.which_key_in_dict(test_dict, key_options) == 'train'

        # Test multiple key options to return the first match
        assert Safe.which_key_in_dict(
            test_dict, multiple_key_options,
        ) == 'train'

        # Test no valid outcomes with proper args
        assert not Safe.which_key_in_dict(test_dict, no_valid_key)

        # Test invalid key types
        assert not Safe.which_key_in_dict(test_dict, no_valid_bad_type)

        # Test empty lists and dicts
        assert not Safe.which_key_in_dict({}, [])

        # Test improper types
        assert not Safe.which_key_in_dict([], {})

    @staticmethod
    def test_is_domain():
        valid_domains = [
            'yahoo.com',
            'realtek.com',
            'googlemail.com',
            'gmail.org',
            'facebook.net',
            'legit.co.uk',
            'me.com',
            'labanca.es',
            'truestory.com',
            'yahoo.com',
            'example.com',
            'subdomain.example.com',
            'example-one.com',
            'example.name',
            'example.museum',
            'example.co.jp',
            'example.com',
        ]

        invalid_domains = [
            'temporary',
            '%^%#$',
            'example.com>', 'example',
            'example.com (<NAME>)',
            'example',
            '-example.com',
            '111.222.333.44444',
            'example..com',
            '.red.com',
        ]

        # Test valid domains
        for valid_domain in valid_domains:
            assert Safe.is_domain(valid_domain)

        # Test invalid domains
        for invalid_domain in invalid_domains:
            assert not Safe.is_domain(invalid_domain)

        # Invalid type
        assert not Safe.is_domain(2)

    @staticmethod
    def test_is_ip_address():

        valid_ips = [
            '172.16.17.32',
            '8.8.8.8',
            '10.0.0.2',
            '172.16.58.3',
        ]

        invalid_ips = [
            '2.2.',
            '234.343.3333.23',
            '172.16.58.3.345',
        ]

        # Test valid ips
        for valid_ip in valid_ips:
            assert Safe.is_ip_address(valid_ip)

        # Test invalid ips
        for invalid_ip in invalid_ips:
            assert not Safe.is_ip_address(invalid_ip)

        # Test invalid data type
        assert not Safe.is_ip_address(2)

    @staticmethod
    def test_is_email():

        # Define valid emails of various formats in list
        valid_emails = [
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            'email@172.16.17.32',
            '<EMAIL>',
            '<EMAIL>',
            '_______<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
        ]

        # Define invalid emails of various formats in list
        invalid_emails = [
            '<EMAIL>',
            'herewego@temporary',
            '<EMAIL>',
            'plainaddress',
            '#@%^%#$@#$@#.com',
            '@example.com',
            '<NAME> <<EMAIL>>',
            '<EMAIL>',
            '<EMAIL>',
            <EMAIL>',
            '<EMAIL>',
            'email..<EMAIL>',
            'あいうえ<EMAIL>',
            '<EMAIL> (<NAME>)',
            'email@<EMAIL>',
            '<EMAIL>',
            'email@111.222.333.44444',
            '<EMAIL>',
            'Abc..<EMAIL>',
        ]

        # Assertion cases for all emails
        for valid_email in valid_emails:
            assert Safe.is_email(valid_email)
        for invalid_email in invalid_emails:
            assert not Safe.is_email(invalid_email)

        # Test for bad argument type
        assert not Safe.is_email(2)

    @staticmethod
    def test_is_namespace_email():

        # Define valid emails of various formats in list
        valid_emails = [
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>@{}.es',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
        ]

        # Define invalid emails of various formats in list
        invalid_emails = [
            '<EMAIL>',
            '<EMAIL>',
            <EMAIL>',
            '<EMAIL>',
            'herewego@{}',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
            '<EMAIL>',
        ]

        # Define valid namespaces
        valid_namespaces = [
            'google', 'gmail', 'realtek',
            'however', 'twenty.coordinate', '2345',
        ]

        # Define invalid namespaces
        invalid_namespaces = ['rau*d', 'h&8']

        # Assertion cases for all emails
        for valid_email in valid_emails:
            for valid_namespace in valid_namespaces:
                assert Safe.is_valid_namespace_email(
                    valid_email.format(valid_namespace), valid_namespace,
                ) is True
            for invalid_namespace in invalid_namespaces:
                assert Safe.is_valid_namespace_email(
                    valid_email.format(
                        invalid_namespace,
                    ), invalid_namespace,
                ) is False

        for invalid_email in invalid_emails:
            for valid_namespace in valid_namespaces:
                assert Safe.is_valid_namespace_email(
                    invalid_email.format(valid_namespace), valid_namespace,
                ) is False
            for invalid_namespace in invalid_namespaces:
                assert Safe.is_valid_namespace_email(
                    invalid_email.format(
                        invalid_namespace,
                    ), invalid_namespace,
                ) is False

        # Test improper types
        assert Safe.is_valid_namespace_email(2, 'da') is False
        assert Safe.is_valid_namespace_email('do', dict()) is False

safe_test.py by Dalofeco  Defines test cases for the provided pyutils_dalofeco package. # Define test dict # Define valid test keys # Assertion cases # Define test dict # Define valid test keys # Test proper operation with only one key # Test multiple key options to return the first match # Test no valid outcomes with proper args # Test invalid key types # Test empty lists and dicts # Test improper types #$', # Test valid domains # Test invalid domains # Invalid type # Test valid ips # Test invalid ips # Test invalid data type # Define valid emails of various formats in list # Define invalid emails of various formats in list #$@#$@#.com', # Assertion cases for all emails # Test for bad argument type # Define valid emails of various formats in list # Define invalid emails of various formats in list # Define valid namespaces # Define invalid namespaces # Assertion cases for all emails # Test improper types