diff --git a/nnpy/tests.py b/nnpy/tests.py new file mode 100644 index 0000000..33b9bf3 --- /dev/null +++ b/nnpy/tests.py @@ -0,0 +1,25 @@ +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') diff --git a/test.py b/test.py deleted file mode 100644 index 57ed70a..0000000 --- a/test.py +++ /dev/null @@ -1,16 +0,0 @@ -from __future__ import print_function -import nnpy - -pub = nnpy.Socket(nnpy.AF_SP, nnpy.PUB) -pub.bind('inproc://foo') -print(pub.getsockopt(nnpy.SOL_SOCKET, nnpy.DOMAIN)) - -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)) -print(poller.poll()) -print(sub.recv()) -print(pub.get_statistic(nnpy.STAT_MESSAGES_SENT))