<commit_before>from ..helpers import assert_equal, patch
import datetime
from tagalog import source_host

def test_no_source_host_defaults():
    data = [{'@message': 'one'},
            {'@message': 'two'},
            {'@message': 'three'}]
    out = source_host(data)

    assert_equal(next(out), {'@message': 'one', '@source_host': 'default'})
    assert_equal(next(out), {'@message': 'two', '@source_host': 'default'})
    assert_equal(next(out), {'@message': 'three', '@source_host': 'default'})<commit_msg>[#46898331] Add desired unit tests for source_host<commit_after>from ..helpers import assert_equal, patch
import datetime
from tagalog import source_host


def test_no_source_host_defaults():
    data = [{'@message': 'one'},
            {'@message': 'two'},
            {'@message': 'three'}]
    out = source_host(data)

    # FIXME: Replace 'default' with mocked method that looks up the FQDN of
    # the machine which it is running on.
    assert_equal(next(out), {'@message': 'one', '@source_host': 'default'})
    assert_equal(next(out), {'@message': 'two', '@source_host': 'default'})
    assert_equal(next(out), {'@message': 'three', '@source_host': 'default'})


def test_source_host_provided():
    data = [{'@source_host': 'orangutan.zoo.tld', '@message': 'one'},
            {'@source_host': 'orangutan.zoo.tld', '@message': 'two'},
            {'@source_host': 'orangutan.zoo.tld', '@message': 'three'}]
    out = source_host(data, source_host='chimpanzee.zoo.tld')

    assert_equal(next(out), {'@source_host': 'orangutan.zoo.tld', '@message': 'one'})
    assert_equal(next(out), {'@source_host': 'orangutan.zoo.tld', '@message': 'two'})
    assert_equal(next(out), {'@source_host': 'orangutan.zoo.tld', '@message': 'three'})


def test_source_host_provided_custom_key():
    data = [{'@message': 'one'},
            {'@message': 'two'},
            {'@message': 'three'}]
    out = source_host(data, source_host='orangutan.zoo.tld', key='host')

    assert_equal(next(out), {'host': 'orangutan.zoo.tld', '@message': 'one'})
    assert_equal(next(out), {'host': 'orangutan.zoo.tld', '@message': 'two'})
    assert_equal(next(out), {'host': 'orangutan.zoo.tld', '@message': 'three'})


def test_source_host_dont_overwrite_existing():
    data = [{'@source_host': 'orangutan.zoo.tld', '@message': 'one'},
            {'@source_host': 'orangutan.zoo.tld', '@message': 'two'},
            {'@source_host': 'orangutan.zoo.tld', '@message': 'three'}]
    out = source_host(data, source_host='chimpanzee.zoo.tld')

    assert_equal(next(out), {'@source_host': 'orangutan.zoo.tld', '@message': 'one'})
    assert_equal(next(out), {'@source_host': 'orangutan.zoo.tld', '@message': 'two'})
    assert_equal(next(out), {'@source_host': 'orangutan.zoo.tld', '@message': 'three'})
{'fraction_non_alphanumeric': 0.21009305654974947, 'fraction_numerical': 0.002863278453829635, 'mean_word_length': 4.739219712525667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6587424', 'n_tokens_mistral': 1010, 'n_tokens_neox': 994, 'n_words': 192}