<commit_before># encoding: utf-8
from __future__ import unicode_literals
import unittest

from nose.plugins.skip import SkipTest

from uricore import IRI, URI
from uricore.wkz_datastructures import MultiDict

import cases


class TestIRI(unittest.TestCase):

    def test_str_input_fails(self):
        self.assertRaises(TypeError, IRI, 'http://example.com'.encode('ascii'))

    def test_uri_input(self):
        iri = TestIRISnowman.ri
        uri = URI(iri)
        self.assertEquals(str(iri), str(IRI(uri)))
        self.assertEquals(unicode(iri), unicode(IRI(uri)))

    def test_repr(self):
        iri = TestIRISnowman.ri
        eval_iri = eval(repr(iri))
        self.assertEquals(iri, eval_iri)

    def test_idn_ascii_encoding(self):
        iri = IRI("http://Bücher.ch/")
        self.assertEquals(str(iri), "http://xn--bcher-kva.ch/")

    def test_convert_pile_of_poo(self):
        raise SkipTest("Not Implemented")
        uri = URI("http://u:p@www.xn--ls8h.la:80/path?q=arg#frag".encode('utf-8'))
        try:
            IRI(uri)
        except Exception as e:
            assert False, "{0} {1}".format(type(e), e)

    def test_non_existent_scheme(self):
        try:
            IRI("watwatwat://wat.wat/wat")
        except Exception as e:
            assert False, "{0} {1}".format(type(e), e)

    def test_iri_from_lenient(self):
        lenient_iri = IRI.from_lenient(u'http://de.wikipedia.org/wiki/Elf (Begriffskl\xe4rung)')
        self.assertEquals(repr(lenient_iri), "IRI(u'http://de.wikipedia.org/wiki/Elf%20%28Begriffskl%C3%A4rung%29')")


class TestIRISnowman(cases.IdentifierCase):

    ri = IRI("http://u:p@www.\N{SNOWMAN}:80/path?q=arg#frag")
    expect = dict(
        scheme="http",
        auth="u:p",
        hostname="www.\u2603",
        port="80",
        path="/path",
        query=MultiDict([('q', 'arg')]),
        querystr='q=arg',
        fragment="frag",
        netloc="u:p@www.\u2603:80",
    )

<commit_msg>test showing IRI creation failure with unicode parameters<commit_after># encoding: utf-8
from __future__ import unicode_literals
import unittest

from nose.plugins.skip import SkipTest

from uricore import IRI, URI
from uricore.wkz_datastructures import MultiDict

import cases


class TestIRI(unittest.TestCase):

    def test_str_input_fails(self):
        self.assertRaises(TypeError, IRI, 'http://example.com'.encode('ascii'))

    def test_uri_input(self):
        iri = TestIRISnowman.ri
        uri = URI(iri)
        self.assertEquals(str(iri), str(IRI(uri)))
        self.assertEquals(unicode(iri), unicode(IRI(uri)))

    def test_repr(self):
        iri = TestIRISnowman.ri
        eval_iri = eval(repr(iri))
        self.assertEquals(iri, eval_iri)

    def test_idn_ascii_encoding(self):
        iri = IRI("http://Bücher.ch/")
        self.assertEquals(str(iri), "http://xn--bcher-kva.ch/")

    def test_convert_pile_of_poo(self):
        raise SkipTest("Not Implemented")
        uri = URI("http://u:p@www.xn--ls8h.la:80/path?q=arg#frag".encode('utf-8'))
        try:
            IRI(uri)
        except Exception as e:
            assert False, "{0} {1}".format(type(e), e)

    def test_non_existent_scheme(self):
        try:
            IRI("watwatwat://wat.wat/wat")
        except Exception as e:
            assert False, "{0} {1}".format(type(e), e)

    def test_nonascii_query_keys(self):
        IRI(u'http://example.com/?gro\xdf=great')

    def test_iri_from_lenient(self):
        lenient_iri = IRI.from_lenient(u'http://de.wikipedia.org/wiki/Elf (Begriffskl\xe4rung)')
        self.assertEquals(repr(lenient_iri), "IRI(u'http://de.wikipedia.org/wiki/Elf%20%28Begriffskl%C3%A4rung%29')")


class TestIRISnowman(cases.IdentifierCase):

    ri = IRI("http://u:p@www.\N{SNOWMAN}:80/path?q=arg#frag")
    expect = dict(
        scheme="http",
        auth="u:p",
        hostname="www.\u2603",
        port="80",
        path="/path",
        query=MultiDict([('q', 'arg')]),
        querystr='q=arg',
        fragment="frag",
        netloc="u:p@www.\u2603:80",
    )


{'fraction_non_alphanumeric': 0.15363748458692972, 'fraction_numerical': 0.015782983970406905, 'mean_word_length': 2.8887823585810164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 2, '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': '4965610', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1431, 'n_words': 228}