From 0a8f5b09658dfced014f1f93219367aa7192c0c5 Mon Sep 17 00:00:00 2001 From: ahmedk <karim.ahmed@xfel.eu> Date: Wed, 19 Jun 2024 19:40:17 +0200 Subject: [PATCH] fix: format warning and fix after testing --- src/cal_tools/constants.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/cal_tools/constants.py b/src/cal_tools/constants.py index 8aed18f32..4e1b17c31 100644 --- a/src/cal_tools/constants.py +++ b/src/cal_tools/constants.py @@ -1,21 +1,10 @@ -<<<<<<< HEAD import binascii import time -======= - -import binascii -import time -import warnings -from datetime import datetime, timezone ->>>>>>> 055e516a (fix: handle CCVAlreadyInject case using a warning) from hashlib import md5 from pathlib import Path from shutil import copyfile from struct import pack, unpack -<<<<<<< HEAD from typing import List, Optional, Union -======= ->>>>>>> 055e516a (fix: handle CCVAlreadyInject case using a warning) import h5py import numpy as np @@ -30,7 +19,16 @@ from cal_tools.tools import run_prop_seq_from_path class CCVAlreadyInjected(UserWarning): - """Exception when same CCV was already injected.""" + """Exception when same CCV was already injected. + expected response: { + 'success': False, 'status_code': 422, + 'info': 'Error creating calibration_constant_version', + 'app_info': { + 'calibration_constant_id': ['has already been taken'], + 'physical_detector_unit_id': ['has already been taken'], + 'begin_at': ['has already been taken'] + }, 'pagination': {}, 'data': {}} + """ pass CONDITION_NAME_MAX_LENGTH = 60 @@ -44,6 +42,14 @@ class CCVAlreadyInjectedError(InjectAPIError): ... +def custom_warning_formatter( + message, category, filename, lineno, file=None, line=None): + """Custom warning format to avoid display filename and lineno.""" + return f"{category.__name__}: {message}\n" + +# Apply the custom warning formatter +warnings.formatwarning = custom_warning_formatter + def write_ccv( const_path, pdu_name, pdu_uuid, detector_type, -- GitLab