<commit_before># encoding: UTF-8

from humanname import Name


def test_simple_name():
    n = Name.parse("<NAME>")
    assert n.given_name == 'Jane'
    assert n.surname == 'Doe'
    assert n.middle_names is None
    assert n.suffix is None
    assert n.display_full == '<NAME>'
    assert n.display_first_last == '<NAME>'
    assert n.display_initial_surname == '<NAME>'
    assert n.goes_by_middle_name is False
    assert n.length == 8


def test_complex_name():
    n = Name.parse("<NAME>")
    assert n.given_name == 'John'
    assert n.surname == 'de la MacDonald'
    assert n.suffix == 'Jr.'
    assert n.display_full == '<NAME>, Jr.'
    assert n.display_first_last == '<NAME>'
    assert n.display_initial_surname == 'J. <NAME>'
    assert n.length == len('<NAME>. de la MacDonald, Jr.')


def test_failure():
    assert Name.parse('nope') is None


def test_non_utf8():
    string = u"<NAME>".encode("ISO-8859-1").decode("ISO-8859-1")

    n = Name.parse(string)
    assert n.given_name == u"Björn"             # Normalized NFKD
    assert n.surname == u"O'Malley-Muñoz"       # Normalized NFKD


def test_equality_identical():
    assert Name.parse("<NAME>") == Name.parse("<NAME>")


def test_equality_consistent():
    assert Name.parse("<NAME>") == Name.parse("<NAME>")


def test_equality_inconsistent():
    assert Name.parse("<NAME>") != Name.parse("<NAME>")


def test_hash_identical():
    assert hash(Name.parse("<NAME>")) == hash(Name.parse("<NAME>"))


def test_hash_consistent():
    assert hash(Name.parse("<NAME>")) == hash(Name.parse("<NAME>"))


def test_hash_different_surnames():
    assert hash(Name.parse("<NAME>")) != hash(Name.parse("<NAME>"))


def test_matches_slug_or_localpart_matching():
    assert Name.parse("<NAME>").matches_slug_or_localpart('janexdoe')


def test_matches_slug_or_localpart_nonmatching():
    assert not Name.parse("<NAME>").matches_slug_or_localpart('johnxdoe')


def test_no_memory_leak():
    import gc
    import os

    def rss():
        gc.collect()
        out = os.popen("ps -o rss= -p %d" % os.getpid()).read()
        return int(out.strip())

    before = rss()

    for _ in range(100000):
        n = Name.parse("Reallyverylongfirstname Reallyverylonglastname")
        n.given_name
        n.surname

    after = rss()

    assert after < 1.25 * before
<commit_msg>Skip memory leak test on Windows<commit_after># encoding: UTF-8

from humanname import Name


def test_simple_name():
    n = Name.parse("<NAME>")
    assert n.given_name == 'Jane'
    assert n.surname == 'Doe'
    assert n.middle_names is None
    assert n.suffix is None
    assert n.display_full == '<NAME>'
    assert n.display_first_last == '<NAME>'
    assert n.display_initial_surname == '<NAME>'
    assert n.goes_by_middle_name is False
    assert n.length == 8


def test_complex_name():
    n = Name.parse("<NAME>")
    assert n.given_name == 'John'
    assert n.surname == 'de la MacDonald'
    assert n.suffix == 'Jr.'
    assert n.display_full == '<NAME>. <NAME> MacDonald, Jr.'
    assert n.display_first_last == '<NAME>'
    assert n.display_initial_surname == 'J. <NAME> MacDonald'
    assert n.length == len('<NAME>. de la MacDonald, Jr.')


def test_failure():
    assert Name.parse('nope') is None


def test_non_utf8():
    string = u"<NAME>".encode("ISO-8859-1").decode("ISO-8859-1")

    n = Name.parse(string)
    assert n.given_name == u"Björn"             # Normalized NFKD
    assert n.surname == u"O'Malley-Muñoz"       # Normalized NFKD


def test_equality_identical():
    assert Name.parse("Jane Doe") == Name.parse("Jane Doe")


def test_equality_consistent():
    assert Name.parse("Jane Doe") == Name.parse("J. Doe")


def test_equality_inconsistent():
    assert Name.parse("Jane Doe") != Name.parse("John Doe")


def test_hash_identical():
    assert hash(Name.parse("Jane Doe")) == hash(Name.parse("Jane Doe"))


def test_hash_consistent():
    assert hash(Name.parse("Jane Doe")) == hash(Name.parse("J. Doe"))


def test_hash_different_surnames():
    assert hash(Name.parse("Jane Doe")) != hash(Name.parse("Jane Dee"))


def test_matches_slug_or_localpart_matching():
    assert Name.parse("Jane Doe").matches_slug_or_localpart('janexdoe')


def test_matches_slug_or_localpart_nonmatching():
    assert not Name.parse("Jane Doe").matches_slug_or_localpart('johnxdoe')


def test_no_memory_leak():
    # Don't run this test on Windows
    import platform
    if platform.system() != 'Darwin' and platform.system() != 'Linux':
        return

    import gc
    import os

    def rss():
        gc.collect()
        out = os.popen("ps -o rss= -p %d" % os.getpid()).read()
        return int(out.strip())

    before = rss()

    for _ in range(100000):
        n = Name.parse("Reallyverylongfirstname Reallyverylonglastname")
        n.given_name
        n.surname

    after = rss()

    assert after < 1.25 * before

{'fraction_non_alphanumeric': 0.15145948152684222, 'fraction_numerical': 0.008981424780567463, 'mean_word_length': 3.4504995458673933, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 38, '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': '6055606', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1630, 'n_words': 375}