<commit_before>from ...helpers import assert_raises, assert_regexp_matches
from mock import patch, ANY
import socket

from tagalog.shipper.statsd_timer import StatsdTimerShipper
from tagalog.shipper.shipper_error import ShipperError

class TestStatsdShipper(object):
    @patch('tagalog.shipper.statsd.socket.socket')
    def test_ship_with_provided_metric_literal(self, socket_mock):
        kwargs = {'metric': '%{@source_host}.nginx.foo', 'timed_field': 'request_time'}
        ss = StatsdTimerShipper(**kwargs)
        ss.ship({"@source_host": 'wilmaaaaa', 'request_time': 32.25})

        socket_mock.return_value.connect.assert_called_with(('127.0.0.1', 8125))
        socket_mock.return_value.send.assert_called_with(ANY)
        args, kwargs = socket_mock.return_value.send.call_args
        packet = args[0]
        assert_regexp_matches(packet, r'^wilmaaaaa:32.250*|ms$')<commit_msg>attempt to make python 3 happy<commit_after>from ...helpers import assert_raises, assert_regexp_matches
from mock import patch, ANY
import socket

from tagalog.shipper.statsd_timer import StatsdTimerShipper
from tagalog.shipper.shipper_error import ShipperError

class TestStatsdShipper(object):
    @patch('tagalog.shipper.statsd.socket.socket')
    def test_ship_with_provided_metric_literal(self, socket_mock):
        kwargs = {'metric': '%{@source_host}.nginx.foo', 'timed_field': 'request_time'}
        ss = StatsdTimerShipper(**kwargs)
        ss.ship({"@source_host": 'wilmaaaaa', 'request_time': 32.25})

        socket_mock.return_value.connect.assert_called_with(('127.0.0.1', 8125))
        socket_mock.return_value.send.assert_called_with(ANY)
        args, kwargs = socket_mock.return_value.send.call_args
        packet = args[0]
        assert_regexp_matches(packet.encode('utf-8'), r'^wilmaaaaa:32.250*|ms$')
{'fraction_non_alphanumeric': 0.11984606926882903, 'fraction_numerical': 0.02308960967564596, 'mean_word_length': 4.796178343949045, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4317940', 'n_tokens_mistral': 634, 'n_tokens_neox': 597, 'n_words': 98}