def test_timeout(self, mock_creation_date, mock_log_error): # no timeout mock_creation_date.return_value = date.to_string( date.get_datetime_now() - timedelta(hours=35, minutes=59)) self.assertFalse(self.request_tracker.timeout) # timeout mock_creation_date.return_value = date.to_string( date.get_datetime_now() - timedelta(hours=36, minutes=1)) self.assertTrue(self.request_tracker.timeout) mock_log_error.assert_called_once()
def _test_converter_with_file_format(self, file_format, mock_s3_fs, mock_s3_map, mock_to_mtx, mock_to_loom, mock_to_csv, mock_zipfile_write, mock_mmwrite, mock_s3_put, mock_complete_subtask_execution, mock_complete_request, mock_parse_manifest, mock_hstack, mock_creation_date, mock_os_mkdir, mock_os_remove): mock_s3_fs.return_value = None mock_s3_map.return_value = None mock_creation_date.return_value = date.to_string(datetime.datetime.utcnow()) main(["test_id", "test_exp_manifest", "test_cell_manifest", "test_gene_manifest", "test_target", file_format, "."]) if file_format == "loom": mock_to_loom.assert_called_once() elif file_format == "csv": mock_to_csv.assert_called_once() elif file_format == "mtx": mock_to_mtx.assert_called_once() mock_s3_put.assert_called_once() mock_complete_subtask_execution.assert_called_once_with(Subtask.CONVERTER) mock_complete_request.assert_called_once_with(duration=mock.ANY)
def test_empty_results(self, mock_parse_manifest, mock_upload_converted_matrix, mock_complete_subtask_execution, mock_complete_request, mock_creation_date, mock_remove): mock_creation_date.return_value = date.to_string( datetime.datetime.utcnow()) self.matrix_converter.query_results = { QueryType.CELL: CellQueryResultsReader("test_manifest_key"), QueryType.EXPRESSION: ExpressionQueryResultsReader("test_manifest_key"), QueryType.FEATURE: FeatureQueryResultsReader("test_manifest_key") } mock_parse_manifest.return_value = {"record_count": 0} self.matrix_converter.local_output_filename = "unit_test_empty_loom.loom" self.matrix_converter.run() self.assertEqual(os.path.getsize("unit_test_empty_loom.loom"), 0) mock_complete_subtask_execution.assert_called_once_with( Subtask.CONVERTER) mock_complete_request.assert_called_once() os.remove("unit_test_empty_loom.loom")
def test_is_expired(self, mock_exists, mock_creation_date, mock_log_error): with self.subTest("Expired"): mock_exists.return_value = False mock_creation_date.return_value = date.to_string( date.get_datetime_now() - timedelta(days=30, minutes=1)) self.assertTrue(self.request_tracker.is_expired) mock_log_error.assert_called_once() mock_log_error.reset_mock() with self.subTest( "Not expired. Matrix DNE but not past expiration date"): mock_exists.return_value = False mock_creation_date.return_value = date.to_string( date.get_datetime_now() - timedelta(days=29)) self.assertFalse(self.request_tracker.is_expired) mock_log_error.assert_not_called() with self.subTest("Not expired. Matrix exists"): mock_exists.return_value = True self.assertFalse(self.request_tracker.is_expired) mock_log_error.assert_not_called()
def test_run(self, mock_parse_manifest, mock_to_loom, mock_upload_converted_matrix, mock_subtask_exec, mock_complete_request, mock_creation_date, mock_os_remove): mock_creation_date.return_value = date.to_string( datetime.datetime.utcnow()) mock_to_loom.return_value = "local_matrix_path" self.matrix_converter.run() mock_manifest_calls = [ mock.call("test_exp_manifest"), mock.call("test_cell_manifest"), mock.call("test_gene_manifest") ] mock_parse_manifest.assert_has_calls(mock_manifest_calls) mock_to_loom.assert_called_once() mock_subtask_exec.assert_called_once_with(Subtask.CONVERTER) mock_complete_request.assert_called_once mock_upload_converted_matrix.assert_called_once_with( "local_matrix_path", "test_target")
def test_conversions(self): self.assertEqual(date.to_datetime(date.to_string(self.now)), self.now)