def test_disallow_inane_opens_and_closes_normal(self): pl = Pipeline() with self.assertRaises(Exception) as e: pl.close() self.assertEqual( str(e.exception), 'Cannot close a Pipeline that is already closed!') pl.open() with self.assertRaises(Exception) as e: pl.open() self.assertEqual( str(e.exception), 'Cannot open a Pipeline that is already open!') pl.close() with self.assertRaises(Exception) as e: pl.close() self.assertEqual( str(e.exception), 'Cannot close a Pipeline that is already closed!')
def test_open_close_no_with(self): from math import sqrt def square_root(arg): return sqrt(arg) def cube(arg): return arg ** 3 pl = Pipeline() pl.add(ReplicatingFork(2)) pl.add(Processor(square_root), Processor(cube)) pl.add(Processor(square_root), Pipe()) pl.add(Join(2)) pl.add(Processor(print)) self.assertTrue(pl.closed, 'Pipeline should be closed') pl.open() pl.run([16, 3, 81]) self.assertTrue(pl.opened, 'Pipeline should be open') pl.close() self.assertTrue(pl.closed, 'Pipeline should be closed') pl.open() # Leave it open -- daemon children should be cleaned up self.assertTrue(pl.opened, 'Pipeline should be open')