<commit_before>from liaison.sink import Sink, StatsdSink, SinkException
from liaison.config import \
    SinkConfig, StatsdOptions

import sys
if sys.version >= 3:
    import unittest
else:
    import unittest2 as unittest


class StatsdSinkTests(unittest.TestCase):

    def setUp(self):
        self.base = Sink(SinkConfig())
        self.base.sink = StatsdSink(StatsdOptions())
        self.base.sink.client.gauge = lambda x, y, d=None: (x, y, d)

    def test_ok_count_no_tag(self):
        x = self.base.ok_count(3, "srv1", "dc1", None)
        self.assertTrue(x == (
            'consul.service.dc1.srv1.ok.count', 3, None))

    def test_ok_count_tag(self):
        x = self.base.ok_count(3, "srv1", "dc1", "tag")
        self.assertTrue(x == (
            'consul.service.dc1.srv1.tag.ok.count', 3, None))

    def test_ok_percent_no_tag(self):
        x = self.base.ok_percent(0.9, "srv1", "dc1", None)
        self.assertTrue(x == (
            'consul.service.dc1.srv1.ok.percent', 0.9, None))

    def test_ok_percent_tag(self):
        x = self.base.ok_percent(0.9, "srv1", "dc1", "tag")
        self.assertTrue(x == (
            'consul.service.dc1.srv1.tag.ok.percent', 0.9, None))

    def test_critical_percent_no_tag(self):
        x = self.base.critical_percent(0.9, "srv1", "dc1", None)
        self.assertTrue(x == (
            'consul.service.dc1.srv1.critical.percent', 0.9, None))

    def test_critical_percent_tag(self):
        x = self.base.critical_percent(0.9, "srv1", "dc1", "tag")
        self.assertTrue(x == (
            'consul.service.dc1.srv1.tag.critical.percent', 0.9, None))

    def test_critical_count_no_tag(self):
        x = self.base.critical_count(3, "srv1", "dc1", None)
        self.assertTrue(x == (
            'consul.service.dc1.srv1.critical.count', 3, None))

    def test_critical_count_tag(self):
        x = self.base.critical_count(3, "srv1", "dc1", "tag")
        self.assertTrue(x == (
            'consul.service.dc1.srv1.tag.critical.count', 3, None))

    def test_invalid_sink(self):
        with self.assertRaises(SinkException):
            config = SinkConfig(type="statsd")
            config.type = "invalid"
            Sink(config)<commit_msg>I think this doesn't work as expected in unittest2<commit_after>from liaison.sink import Sink, StatsdSink, SinkException
from liaison.config import \
    SinkConfig, StatsdOptions

import sys
if sys.version >= 3:
    import unittest
else:
    import unittest2 as unittest


class StatsdSinkTests(unittest.TestCase):

    def setUp(self):
        self.base = Sink(SinkConfig())
        self.base.sink = StatsdSink(StatsdOptions())
        self.base.sink.client.gauge = lambda x, y, d=None: (x, y, d)

    def test_ok_count_no_tag(self):
        x = self.base.ok_count(3, "srv1", "dc1", None)
        self.assertTrue(x == (
            'consul.service.dc1.srv1.ok.count', 3, None))

    def test_ok_count_tag(self):
        x = self.base.ok_count(3, "srv1", "dc1", "tag")
        self.assertTrue(x == (
            'consul.service.dc1.srv1.tag.ok.count', 3, None))

    def test_ok_percent_no_tag(self):
        x = self.base.ok_percent(0.9, "srv1", "dc1", None)
        self.assertTrue(x == (
            'consul.service.dc1.srv1.ok.percent', 0.9, None))

    def test_ok_percent_tag(self):
        x = self.base.ok_percent(0.9, "srv1", "dc1", "tag")
        self.assertTrue(x == (
            'consul.service.dc1.srv1.tag.ok.percent', 0.9, None))

    def test_critical_percent_no_tag(self):
        x = self.base.critical_percent(0.9, "srv1", "dc1", None)
        self.assertTrue(x == (
            'consul.service.dc1.srv1.critical.percent', 0.9, None))

    def test_critical_percent_tag(self):
        x = self.base.critical_percent(0.9, "srv1", "dc1", "tag")
        self.assertTrue(x == (
            'consul.service.dc1.srv1.tag.critical.percent', 0.9, None))

    def test_critical_count_no_tag(self):
        x = self.base.critical_count(3, "srv1", "dc1", None)
        self.assertTrue(x == (
            'consul.service.dc1.srv1.critical.count', 3, None))

    def test_critical_count_tag(self):
        x = self.base.critical_count(3, "srv1", "dc1", "tag")
        self.assertTrue(x == (
            'consul.service.dc1.srv1.tag.critical.count', 3, None))

    def test_invalid_sink(self):
        config = SinkConfig(type="statsd")
        config.type = "invalid"
        self.assertRaises(SinkException, Sink(config))
{'fraction_non_alphanumeric': 0.15040467625899281, 'fraction_numerical': 0.026303956834532374, 'mean_word_length': 2.6647446457990114, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3469453', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1631, 'n_words': 278}