def test_exception_memory_error(self): """ Pass in bad data for the dynlib """ with self.assertRaises(MemoryError) as context: dynlib_app = DynlibApp( "a", "a", lib=_libpath, print_stats=print_stats, bufsize=pow(2, 50) ) dynlib_app.run() self.assertTrue("Couldn't allocate memory for read/write buffer" in str(context.exception))
def test_exception_bufsize(self): """ Pass in bad data for the dynlib """ with self.assertRaises(TypeError) as context: _ = DynlibApp( "a", "a", lib=_libpath, print_stats=print_stats, bufsize="bufsize" ) self.assertTrue("bufsize should be an Int" in str(context.exception))
def test_exception_print_stats(self): """ Pass in bad data for the dynlib """ with self.assertRaises(TypeError) as context: _ = DynlibApp( "a", "a", lib=_libpath, print_stats="print_stats", bufsize=bufsize ) self.assertTrue( "print_stats should be a Boolean or Int" in str(context.exception) )
def test_with_dynlib(self): """ We test the following graph: A -----> B ----> C ---> D ---> E | +--> F ---> G ---> H +------------------> I ---> J A and C are FileDrops; B is a DynlibApp; D, G and I are CRCApps; F, E, H and J are InMemoryDrops. The DynlibApp B copies A into C and F; therefore D, G and I should yield the same results, meaning that E, H and J should have the same contents. Similarly, A, C and F should have the same contents. This graph was experiencing some problems in a MacOS machine. Hopefully this test will shed some light on that issue and allow us to track it down and fix it. """ # Build drops and wire them together a, c = (FileDROP(x, x) for x in ('a', 'c')) b = DynlibApp('b', 'b', lib=test_dynlib._libpath) d, g, i = (CRCApp(x, x) for x in ('d', 'g', 'i')) f, e, h, j = (InMemoryDROP(x, x) for x in ('f', 'e', 'h', 'j')) for data, app in (a, b), (c, d), (f, g), (a, i): app.addInput(data) for app, data in (b, c), (b, f), (d, e), (g, h), (i, j): app.addOutput(data) # The crc32 is the same used by the CRCApp, see the imports data = os.urandom(1024) crc = six.b(str(crc32(data))) # Execute the graph and check results with droputils.DROPWaiterCtx(self, (e, h, j), 5): a.write(data) a.setCompleted() # Data and CRCs are the expected ones for what, who in (data, (a, c, f)), (crc, (e, h, j)): for drop in who: self.assertEqual(what, droputils.allDropContents(drop))