# -*- coding: utf-8 -*-
import mock
import unittest
import tempfile

from gribble.config import GribbleConfig

try:
    from gribble.transports.zmq_transport import ZmqTransport
    skip = False
except ImportError, e:
    if e.message == 'No module named zmq':
        skip = True
    else:
        raise


@unittest.skipIf(skip, 'zmq not installed')
class ZmqTests(unittest.TestCase):

    def setUp(self):
        empty_conf = tempfile.NamedTemporaryFile(delete=True)
        self.gribble_config = GribbleConfig(mock.Mock(config=empty_conf.name))

    def test_pub(self):
        self.gribble_config.set('zeromq_address', ['tcp://localhost:2120'])
        transport = ZmqTransport(self.gribble_config)
        transport.interrupt()
        #assert not transport.zeromq_bind

    def test_bind(self):
        self.gribble_config.set('zeromq_bind', 'bind')
        self.gribble_config.set('zeromq_address', ['tcp://localhost:2120'])
        ZmqTransport(self.gribble_config)
        #assert transport.zeromq_bind
