11"""Matching logical objects"""
2- import warnings
32from abc import ABCMeta , abstractmethod
43from collections import namedtuple
54from typing import Any , Optional , Union
@@ -55,8 +54,13 @@ def evaluate(self,
5554class Comparison (MatchCriteria ):
5655 """<xtce:Comparison>"""
5756
58- def __init__ (self , required_value : str , referenced_parameter : str ,
59- operator : str = "==" , use_calibrated_value : bool = True ):
57+ def __init__ (
58+ self ,
59+ required_value : str ,
60+ referenced_parameter : str ,
61+ operator : str = "==" ,
62+ use_calibrated_value : bool = True
63+ ):
6064 """Constructor
6165
6266 Parameters
@@ -176,18 +180,11 @@ def evaluate(self,
176180 if self .referenced_parameter in packet :
177181 if self .use_calibrated_value :
178182 parsed_value = packet [self .referenced_parameter ]
179- if not parsed_value :
180- raise ComparisonError (f"Comparison { self } was instructed to useCalibratedValue (the default)"
181- f"but { self .referenced_parameter } does not appear to have a derived value." )
182183 else :
183184 parsed_value = packet [self .referenced_parameter ].raw_value
184185 elif current_parsed_value is not None :
185186 # Assume then that the comparison is a reference to its own uncalibrated value
186187 parsed_value = current_parsed_value
187- if self .use_calibrated_value :
188- warnings .warn ("Performing a comparison against a current value (e.g. a Comparison within a "
189- "context calibrator contains a reference to its own uncalibrated value but use_"
190- "calibrated_value is set to true. This is nonsensical. Using the uncalibrated value..." )
191188 else :
192189 raise ValueError ("Attempting to resolve a Comparison expression but the referenced parameter does not "
193190 "appear in the parsed data so far and no current raw value was passed "
@@ -200,9 +197,6 @@ def evaluate(self,
200197 except ValueError as err :
201198 raise ComparisonError (f"Unable to coerce { self .required_value } of type { type (self .required_value )} to "
202199 f"type { t_comparate } for comparison evaluation." ) from err
203- if required_value is None or parsed_value is None :
204- raise ValueError (f"Error in Comparison. Cannot compare { required_value } with { parsed_value } . "
205- "Neither should be None." )
206200
207201 # x.__le__(y) style call
208202 return getattr (parsed_value , operator )(required_value )
@@ -379,7 +373,7 @@ def evaluate(self,
379373 packet : packets.CCSDSPacket
380374 Packet data used to evaluate truthyness of the match criteria.
381375 current_parsed_value : Optional[Union[int, float]]
382- Current value being parsed. NOTE: This is currently ignored. See the TODO item below .
376+ Ignored .
383377
384378 Returns
385379 -------
@@ -389,21 +383,8 @@ def evaluate(self,
389383
390384 def _get_parsed_value (parameter_name : str , use_calibrated : bool ):
391385 """Retrieves the previously parsed value from the passed in packet"""
392- try :
393- return packet [parameter_name ] if use_calibrated \
394- else packet [parameter_name ].raw_value
395- except KeyError as e :
396- raise ComparisonError (f"Attempting to perform a Condition evaluation on { self .left_param } but "
397- "the referenced parameter does not appear in the hitherto parsed data passed to "
398- "the evaluate method. If you intended a comparison against the raw value of the "
399- "parameter currently being parsed, unfortunately that is not currently supported."
400- ) from e
401-
402- # TODO: Consider allowing one of the parameters to be the parameter currently being evaluated.
403- # This isn't explicitly provided for in the XTCE spec but it seems reasonable to be able to
404- # perform conditionals against the current raw value of a parameter, e.g. while determining if it
405- # should be calibrated. Note that only one of the parameters can be used this way and it must reference
406- # an uncalibrated value so the logic and error handling must be done carefully.
386+ return packet [parameter_name ] if use_calibrated else packet [parameter_name ].raw_value
387+
407388 left_value = _get_parsed_value (self .left_param , self .left_use_calibrated_value )
408389 # Convert XML operator representation to a python-compatible operator (e.g. '>' to '__gt__')
409390 operator = self ._valid_operators [self .operator ]
@@ -415,8 +396,6 @@ def _get_parsed_value(parameter_name: str, use_calibrated: bool):
415396 right_value = t_left_param (self .right_value )
416397 else :
417398 raise ValueError (f"Error when evaluating condition { self } . Neither right_param nor right_value is set." )
418- if left_value is None or right_value is None :
419- raise ComparisonError (f"Error comparing { left_value } and { right_value } . Neither should be None." )
420399
421400 # x.__le__(y) style call
422401 return getattr (left_value , operator )(right_value )
@@ -526,7 +505,7 @@ def evaluate(self,
526505 packet : packets.CCSDSPacket
527506 Packet data used to evaluate truthyness of the match criteria.
528507 current_parsed_value : Optional[Union[int, float]]
529- Current value being parsed .
508+ Ignored .
530509
531510 Returns
532511 -------
0 commit comments