<commit_before>import json
from io import BytesIO

from twisted.trial import unittest
from twisted.internet import task
from twisted.internet import defer

from twisted.python import failure
from twisted.internet import error

import txnats

from tests.base import BaseTest

class TestPartitionTolerance(BaseTest):

    def test_reconnect(self):
        """
        Ensure reconnect is called upon connection lost.
        """
        def msg_handler(*args, **kwargs):
            pass

        self.call_count = 0

        def reconnect(nats_protocol):
            self.call_count += 1
            self.assertIsInstance(nats_protocol, txnats.io.NatsProtocol)

        def event_subscriber(event):
            if event["type"] == txnats.io.CONNECTION_LOST:
                print "connection lost", event["reason"]
                reconnect(event["protocol"])
            elif event["type"] == txnats.io.DISCONNECT:
                print "Clean disconnect", event["reason"]

        nats_protocol = txnats.io.NatsProtocol(
            own_reactor=self.reactor, 
            event_subscribers=[event_subscriber])
        nats_protocol.transport = BytesIO()<commit_msg>Remove print statements from test<commit_after>import json
from io import BytesIO

from twisted.trial import unittest
from twisted.internet import task
from twisted.internet import defer

from twisted.python import failure
from twisted.internet import error

import txnats

from tests.base import BaseTest

class TestPartitionTolerance(BaseTest):

    def test_reconnect(self):
        """
        Ensure reconnect is called upon connection lost.
        """
        def msg_handler(*args, **kwargs):
            pass

        self.call_count = 0

        def reconnect(nats_protocol):
            self.call_count += 1
            self.assertIsInstance(nats_protocol, txnats.io.NatsProtocol)

        def event_subscriber(event):
            if event["type"] == txnats.io.CONNECTION_LOST:
                reconnect(event["protocol"])

        nats_protocol = txnats.io.NatsProtocol(
            own_reactor=self.reactor, 
            event_subscribers=[event_subscriber])
        nats_protocol.transport = BytesIO()
{'fraction_non_alphanumeric': 0.08023842274186153, 'fraction_numerical': 0.0018340210912425492, 'mean_word_length': 2.6672268907563024, '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': '636903', 'n_tokens_mistral': 615, 'n_tokens_neox': 592, 'n_words': 148}