def test_starting_fifo_OUT_end(self,patched_NTF,*args): self.assertFalse(hasattr(te.SharedFIFOfile.TMPFILE,'file_spool')) self.assertEqual(len(te.threading.enumerate()),1) self.fifo_obj = te.SharedFIFOfile(interval_len=0.01) self.assertFalse(hasattr(self.fifo_obj,'side')) self.assertFalse(hasattr(self.fifo_obj,'current_reading_file')) self.assertFalse(hasattr(self.fifo_obj,'current_writing_file')) self.assertFalse(hasattr(self.fifo_obj,'spooler')) self.assertFalse(patched_NTF.called) self.fifo_obj.start_OUT_end() self.assertTrue(hasattr(self.fifo_obj,'side')) self.assertEqual(self.fifo_obj.side,'reading') self.assertEqual(patched_NTF.call_count,1) self.assertTrue(hasattr(self.fifo_obj,'current_reading_file')) self.assertFalse(hasattr(self.fifo_obj,'current_writing_file')) self.assertIs(self.fifo_obj.current_reading_file.rh, patched_NTF.return_value) self.assertIs(self.fifo_obj.current_reading_file.rh.name,'dummy_temp_file') self.assertTrue(hasattr(te.SharedFIFOfile.TMPFILE,'file_spool')) self.assertSequenceEqual(te.SharedFIFOfile.TMPFILE.file_spool,[]) self.assertTrue(te.SharedFIFOfile.TMPFILE.writing_side_conn.poll()) self.assertEqual(te.SharedFIFOfile.TMPFILE.writing_side_conn.recv(),'dummy_temp_file') self.assertEqual(len(te.threading.enumerate()),2) self.assertTrue(hasattr(self.fifo_obj,'spooler')) self.assertTrue(self.fifo_obj.spooler.is_alive())
def test_wh_rollover_writing_end(self,patched_open,patched_Pipe, patched_getsize,patched_NTF,*args): def patched_Pipe_side_effect(): writing_side_conn,reading_side_conn = Pipe() patched_Pipe.wrsconn = Mock(wraps=writing_side_conn) patched_Pipe.rdsconn = Mock(wraps=reading_side_conn) return patched_Pipe.wrsconn,patched_Pipe.rdsconn patched_Pipe.side_effect = patched_Pipe_side_effect def patched_NTF_side_effect(*args,**kwargs): return_val = Mock() return_val.name = kwargs['prefix'] return return_val patched_NTF.side_effect = patched_NTF_side_effect class TesterProc(te.multiprocessing.Process): def __init__(self,fifo_obj,shutdown): te.multiprocessing.Process.__init__(self) self.fifo_obj = fifo_obj self.shutdown = shutdown def run(self): self.fifo_obj.start_OUT_end() while not self.shutdown.wait(0.01): pass self.fifo_obj.close() self.fifo_obj = te.SharedFIFOfile(max_file_size_GB=0.000001, size_check_delay=1,interval_len=0.01) self.shutdown_EV = te.multiprocessing.Event() self.other_proc = TesterProc(self.fifo_obj,self.shutdown_EV) self.other_proc.start() self.fifo_obj.start_IN_end() patched_Pipe.wrsconn.recv.reset_mock() patched_open.reset_mock() patched_getsize.reset_mock() self.fifo_obj.wh self.assertFalse(patched_getsize.called) self.assertFalse(patched_Pipe.wrsconn.send.called) self.assertFalse(patched_Pipe.wrsconn.recv.called) self.assertFalse(patched_open.return_value.close.called) self.assertFalse(patched_open.called) self.fifo_obj.wh patched_getsize.assert_has_calls([call('FIFOfile001_'), call('FIFOfile002_')]) patched_Pipe.wrsconn.send.assert_called_once_with(None) patched_Pipe.wrsconn.recv.assert_called_once_with() patched_open.return_value.close.assert_called_once_with() patched_open.assert_called_once_with('FIFOfile002_','wb',0) self.shutdown_EV.set() self.fifo_obj.close() self.other_proc.join()
def test_TMPFILE_class_init_w_conns(self,*args): self.assertFalse(hasattr(te.SharedFIFOfile.TMPFILE,'instcount')) self.assertFalse(hasattr(te.SharedFIFOfile.TMPFILE,'writing_side_conn')) self.assertFalse(hasattr(te.SharedFIFOfile.TMPFILE,'reading_side_conn')) fifo_obj = te.SharedFIFOfile() self.assertTrue(hasattr(te.SharedFIFOfile.TMPFILE,'instcount')) self.assertTrue(hasattr(te.SharedFIFOfile.TMPFILE,'writing_side_conn')) self.assertTrue(hasattr(te.SharedFIFOfile.TMPFILE,'reading_side_conn')) te.SharedFIFOfile.TMPFILE.writing_side_conn.send('test_packet1') self.assertEqual(te.SharedFIFOfile.TMPFILE.reading_side_conn.recv(),'test_packet1') te.SharedFIFOfile.TMPFILE.reading_side_conn.send('test_packet2') self.assertEqual(te.SharedFIFOfile.TMPFILE.writing_side_conn.recv(),'test_packet2')
def test_FIFO_close_reading_end(self,patched_Condition,patched_getsize, patched_NTF,*args): def patched_Condition_side_effect(*args,**kwargs): patched_Condition.instance = Mock(wraps=Condition()) return patched_Condition.instance patched_Condition.side_effect = patched_Condition_side_effect def patched_NTF_ret_val_close_side_effect(): self.assertFalse(patched_Condition.instance.notify.called) self.assertFalse(patched_Condition.instance.release.called) patched_NTF.return_value.close.side_effect = \ patched_NTF_ret_val_close_side_effect class TesterProc(te.multiprocessing.Process): def __init__(self,fifo_obj,shutdown): te.multiprocessing.Process.__init__(self) self.fifo_obj = fifo_obj self.shutdown = shutdown def run(self): with patch('__builtin__.open',mock_open(),create=True) as patched_open: self.fifo_obj.start_IN_end() while not self.shutdown.wait(0.01): pass self.fifo_obj.close() self.fifo_obj = te.SharedFIFOfile(interval_len=0.01) self.shutdown_EV = te.multiprocessing.Event() self.other_proc = TesterProc(self.fifo_obj,self.shutdown_EV) self.other_proc.start() self.shutdown_EV.set() self.fifo_obj.start_OUT_end() self.assertTrue(self.fifo_obj.spooler.is_alive()) self.assertFalse(patched_Condition.instance.acquire.called) self.assertFalse(patched_NTF.return_value.close.called) self.fifo_obj.close() self.other_proc.join() self.assertFalse(self.fifo_obj.spooler.is_alive()) patched_Condition.instance.acquire.assert_called_once_with() patched_NTF.return_value.close.assert_called_once_with() patched_Condition.instance.notify.assert_called_once_with() patched_Condition.instance.release.assert_called_once_with()
def test_FIFO_close_writing_end(self,patched_Condition,patched_getsize, patched_NTF,patched_TmpDir,*args): def patched_Condition_side_effect(*args,**kwargs): patched_Condition.instance = Mock(wraps=Condition()) return patched_Condition.instance patched_Condition.side_effect = patched_Condition_side_effect class TesterProc(te.multiprocessing.Process): def __init__(self,fifo_obj,shutdown): te.multiprocessing.Process.__init__(self) self.fifo_obj = fifo_obj self.shutdown = shutdown def run(self): self.fifo_obj.start_OUT_end() while not self.shutdown.wait(0.01): pass self.fifo_obj.close() self.fifo_obj = te.SharedFIFOfile(interval_len=0.01) self.shutdown_EV = te.multiprocessing.Event() self.other_proc = TesterProc(self.fifo_obj,self.shutdown_EV) self.other_proc.start() self.assertFalse(patched_Condition.instance.acquire.called) with patch('__builtin__.open',mock_open(),create=True) as patched_open: self.fifo_obj.start_IN_end() patched_Condition.instance.acquire.assert_called_once_with() self.shutdown_EV.set() self.assertFalse(patched_open.return_value.close.called) self.assertFalse(patched_Condition.instance.wait.called) self.assertFalse(patched_TmpDir.return_value.__exit__.called) self.assertFalse(te.SharedFIFOfile.TMPFILE.writing_side_conn.closed) self.assertFalse(te.SharedFIFOfile.TMPFILE.reading_side_conn.closed) self.fifo_obj.close() patched_open.return_value.close.assert_called_once_with() patched_Condition.instance.wait.assert_called_once_with(30) patched_TmpDir.return_value.__exit__.assert_called_once_with(None, None,None) self.assertTrue(te.SharedFIFOfile.TMPFILE.writing_side_conn.closed) self.assertTrue(te.SharedFIFOfile.TMPFILE.reading_side_conn.closed) self.other_proc.join()
def test_starting_fifo_IN_end(self,patched_getsize,*args): self.fifo_obj = te.SharedFIFOfile(interval_len=0.01) self.assertFalse(hasattr(self.fifo_obj,'side')) self.assertFalse(hasattr(self.fifo_obj,'current_reading_file')) self.assertFalse(hasattr(self.fifo_obj,'current_writing_file')) te.SharedFIFOfile.TMPFILE.reading_side_conn.send('dummy_temp_file') with patch('__builtin__.open',mock_open(),create=True) as patched_open: self.fifo_obj.start_IN_end() self.assertTrue(hasattr(self.fifo_obj,'side')) self.assertEqual(self.fifo_obj.side,'writing') self.assertFalse(hasattr(self.fifo_obj,'current_reading_file')) self.assertTrue(hasattr(self.fifo_obj,'current_writing_file')) self.assertEqual(self.fifo_obj.current_writing_file.name,'dummy_temp_file') patched_getsize.assert_called_once_with('dummy_temp_file') self.fifo_obj.current_writing_file._size == 100 patched_open.assert_called_once_with('dummy_temp_file','wb',0) self.assertIs(self.fifo_obj.current_writing_file.wh, patched_open.return_value)
def setUp(self): reload(te) self.fifo_obj = te.SharedFIFOfile(top_path=None, max_file_size_GB=1.7695128917694092e-08, size_check_delay=0,interval_len=0.01) self.shutdown_EV = te.multiprocessing.Event()