from __future__ import print_function
import nnpy, unittest

class Tests(unittest.TestCase):
    def test_basic(self):

        pub = nnpy.Socket(nnpy.AF_SP, nnpy.PUB)
        pub.bind('inproc://foo')
        self.assertEqual(pub.getsockopt(nnpy.SOL_SOCKET, nnpy.DOMAIN), 1)

        sub = nnpy.Socket(nnpy.AF_SP, nnpy.SUB)
        sub.connect('inproc://foo')
        sub.setsockopt(nnpy.SUB, nnpy.SUB_SUBSCRIBE, '')

        pub.send('FLUB')
        poller = nnpy.PollSet((sub, nnpy.POLLIN))
        self.assertEqual(poller.poll(), 1)
        self.assertEqual(sub.recv(), 'FLUB')
        self.assertEqual(pub.get_statistic(nnpy.STAT_MESSAGES_SENT), 1)

def suite():
    return unittest.makeSuite(Tests)

if __name__ == '__main__':
    unittest.main(defaultTest='suite')

from __future__ import print_function
import nnpy, unittest

class Tests(unittest.TestCase):
    def test_basic(self):

        pub = nnpy.Socket(nnpy.AF_SP, nnpy.PUB)
        pub.setsockopt(nnpy.SOL_SOCKET, nnpy.IPV4ONLY, 0)
        pub.bind('inproc://foo')
        self.assertEqual(pub.getsockopt(nnpy.SOL_SOCKET, nnpy.DOMAIN), 1)

        sub = nnpy.Socket(nnpy.AF_SP, nnpy.SUB)
        sub_conn = sub.connect('inproc://foo')
        sub.setsockopt(nnpy.SUB, nnpy.SUB_SUBSCRIBE, '')

        pub.send('FLUB')
        poller = nnpy.PollSet((sub, nnpy.POLLIN))
        self.assertEqual(poller.poll(), 1)
        self.assertEqual(sub.recv(), 'FLUB')
        self.assertEqual(pub.get_statistic(nnpy.STAT_MESSAGES_SENT), 1)
        pub.close()
        sub.shutdown(sub_conn)

def suite():
    return unittest.makeSuite(Tests)

if __name__ == '__main__':
    unittest.main(defaultTest='suite')

Add some more test coverage
Add some more test coverage

  from __future__ import print_function
  import nnpy, unittest
  
  class Tests(unittest.TestCase):
      def test_basic(self):
  
          pub = nnpy.Socket(nnpy.AF_SP, nnpy.PUB)
+         pub.setsockopt(nnpy.SOL_SOCKET, nnpy.IPV4ONLY, 0)
          pub.bind('inproc://foo')
          self.assertEqual(pub.getsockopt(nnpy.SOL_SOCKET, nnpy.DOMAIN), 1)
  
          sub = nnpy.Socket(nnpy.AF_SP, nnpy.SUB)
-         sub.connect('inproc://foo')
+         sub_conn = sub.connect('inproc://foo')
          sub.setsockopt(nnpy.SUB, nnpy.SUB_SUBSCRIBE, '')
  
          pub.send('FLUB')
          poller = nnpy.PollSet((sub, nnpy.POLLIN))
          self.assertEqual(poller.poll(), 1)
          self.assertEqual(sub.recv(), 'FLUB')
          self.assertEqual(pub.get_statistic(nnpy.STAT_MESSAGES_SENT), 1)
+         pub.close()
+         sub.shutdown(sub_conn)
  
  def suite():
      return unittest.makeSuite(Tests)
  
  if __name__ == '__main__':
      unittest.main(defaultTest='suite')
  
Add some more test coverage
## Code Before:
from __future__ import print_function
import nnpy, unittest

class Tests(unittest.TestCase):
    def test_basic(self):

        pub = nnpy.Socket(nnpy.AF_SP, nnpy.PUB)
        pub.bind('inproc://foo')
        self.assertEqual(pub.getsockopt(nnpy.SOL_SOCKET, nnpy.DOMAIN), 1)

        sub = nnpy.Socket(nnpy.AF_SP, nnpy.SUB)
        sub.connect('inproc://foo')
        sub.setsockopt(nnpy.SUB, nnpy.SUB_SUBSCRIBE, '')

        pub.send('FLUB')
        poller = nnpy.PollSet((sub, nnpy.POLLIN))
        self.assertEqual(poller.poll(), 1)
        self.assertEqual(sub.recv(), 'FLUB')
        self.assertEqual(pub.get_statistic(nnpy.STAT_MESSAGES_SENT), 1)

def suite():
    return unittest.makeSuite(Tests)

if __name__ == '__main__':
    unittest.main(defaultTest='suite')

## Instruction:
Add some more test coverage
## Code After:
from __future__ import print_function
import nnpy, unittest

class Tests(unittest.TestCase):
    def test_basic(self):

        pub = nnpy.Socket(nnpy.AF_SP, nnpy.PUB)
        pub.setsockopt(nnpy.SOL_SOCKET, nnpy.IPV4ONLY, 0)
        pub.bind('inproc://foo')
        self.assertEqual(pub.getsockopt(nnpy.SOL_SOCKET, nnpy.DOMAIN), 1)

        sub = nnpy.Socket(nnpy.AF_SP, nnpy.SUB)
        sub_conn = sub.connect('inproc://foo')
        sub.setsockopt(nnpy.SUB, nnpy.SUB_SUBSCRIBE, '')

        pub.send('FLUB')
        poller = nnpy.PollSet((sub, nnpy.POLLIN))
        self.assertEqual(poller.poll(), 1)
        self.assertEqual(sub.recv(), 'FLUB')
        self.assertEqual(pub.get_statistic(nnpy.STAT_MESSAGES_SENT), 1)
        pub.close()
        sub.shutdown(sub_conn)

def suite():
    return unittest.makeSuite(Tests)

if __name__ == '__main__':
    unittest.main(defaultTest='suite')
