From 4de557d304379ba5b7501e30f758d67714c5b911 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Fri, 26 Aug 2016 20:10:25 +0100 Subject: [PATCH] Somre more basic tests. --- tests/timing_test.py | 23 +++++++++++++++++++++++ tests/utils_test.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 tests/timing_test.py create mode 100644 tests/utils_test.py diff --git a/tests/timing_test.py b/tests/timing_test.py new file mode 100644 index 00000000..af7436b2 --- /dev/null +++ b/tests/timing_test.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +import socket +import time +import unittest + +import econtext.master +import econtext.utils + + +@econtext.utils.with_broker +def do_stuff(broker): + context = econtext.master.connect(broker) + t0 = time.time() + ncalls = 1000 + for x in xrange(ncalls): + context.call(socket.gethostname) + return (1e6 * (time.time() - t0)) / ncalls + + +class LocalContextTimingTest(unittest.TestCase): + def test_timing(self): + self.assertLess(do_stuff(), 1000) diff --git a/tests/utils_test.py b/tests/utils_test.py new file mode 100644 index 00000000..35993f03 --- /dev/null +++ b/tests/utils_test.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +import unittest + +import econtext.master +import econtext.utils + + +def func0(broker): + return broker + + +@econtext.utils.with_broker +def func(broker): + return broker + + +class RunWithBrokerTest(unittest.TestCase): + # test_shutdown_on_exception + # test_shutdown_on_success + + def test_run_with_broker(self): + broker = econtext.utils.run_with_broker(func0) + self.assertTrue(isinstance(broker, econtext.master.Broker)) + self.assertFalse(broker._thread.isAlive()) + + +class WithBrokerTest(unittest.TestCase): + def test_with_broker(self): + broker = func() + self.assertTrue(isinstance(broker, econtext.master.Broker)) + self.assertFalse(broker._thread.isAlive())