def test_start_makes_started_true(self, mock_job, __, ___): """Tests calling start() without calling stop() makes started True.""" server = IPerfServer('port') server._get_full_file_path = lambda _: MOCK_LOGFILE_PATH server.start() self.assertTrue(server.started)
def test_start_sets_current_log_file(self, _, __, ___): server = IPerfServer('port') server._get_full_file_path = lambda _: MOCK_LOGFILE_PATH server.start() self.assertEqual( server._current_log_file, MOCK_LOGFILE_PATH, 'The _current_log_file was not received from _get_full_file_path.')
def test_get_full_file_path_creates_parent_directory(self, mock_makedirs): # Will never actually be created/used. logging.log_path = '/tmp/unit_test_garbage' server = IPerfServer('port') full_file_path = server._get_full_file_path() self.assertTrue(mock_makedirs.called, 'Did not attempt to create a directory.') self.assertEqual( os.path.dirname(full_file_path), mock_makedirs.call_args[ARGS][0], 'The parent directory of the full file path was not created.')
def test_stop_exits_early_if_no_process_has_started(self, stop_proc): server = IPerfServer('port') server._get_full_file_path = lambda _: MOCK_LOGFILE_PATH server._iperf_process = None server.stop() self.assertFalse( stop_proc.called, 'stop() should not kill a process if no process is running.')
def test_stop_returns_current_log_file(self, _, __): server = IPerfServer('port') server._get_full_file_path = lambda _: MOCK_LOGFILE_PATH server._current_log_file = MOCK_LOGFILE_PATH server._iperf_process = mock.Mock() log_file = server.stop() self.assertEqual(log_file, MOCK_LOGFILE_PATH, 'The _current_log_file was not returned by stop().')
def test_start_does_not_run_two_concurrent_processes( self, start_proc, _, __): server = IPerfServer('port') server._get_full_file_path = lambda _: MOCK_LOGFILE_PATH server._iperf_process = mock.Mock() server.start() self.assertFalse( start_proc.called, 'start() should not begin a second process if another is running.')