def test_time_greater_than_predicate(): time1 = time_type.TimeType(seconds=1593610856, useconds=223451) time2 = time_type.TimeType(seconds=1593610856, useconds=223502) time_pred = predicates.greater_than(time1) assert not time_pred(time1) assert time_pred(time2)
def test_comparing_item_to_converted_time_succeeds(sample_event): time = time_type.TimeType(seconds=12345) sample_event.time = time_type.TimeType(seconds=9999999) time_pred = predicates.greater_than(time) converted_time_pred = filtering_utils.time_to_data_predicate(time_pred) # Now, this returns the correct value assert converted_time_pred(sample_event)
def test_comparing_item_to_time_fails(sample_event): """ Test that comparing a time to an event is problematic, since this assertion SHOULD always be true but is, in fact, false because we're comparing a data object to a time object """ time = time_type.TimeType(seconds=12345) sample_event.time = time_type.TimeType(seconds=9999999) time_pred = predicates.greater_than(time) # This SHOULD return true, but it doesn't assert not time_pred(sample_event)
def get_empty_obj(ch_temp): ''' Obtains a channel object that is empty (has a value of None) Args: ch_temp: (ChTemplate object) Template describing the channel Returns: A ChData Object with ch value of None ''' return ChData(None, time_type.TimeType(), ch_temp)
def get_empty_obj(event_temp): ''' Obtains an event object that is empty (arguments = None) Args: event_temp: (EventTemplate obj) Template describing event Returns: An EventData object with argument value of None ''' return EventData(None, time_type.TimeType(), event_temp)
def __init__(self): ''' Constructor. Each subclass will define new constructors with necessary arguments. The necessary fields are time, id, and template. Returns: An initialized SysData object ''' if not self.id: self.id = 0 if not self.template: self.template = data_template.DataTemplate() if not self.time: self.time = time_type.TimeType()
def __init__(self): """ Constructor. Each subclass will define new constructors with necessary arguments. The necessary fields are time, id, and template. Returns: An initialized SysData object """ if not hasattr(self, "id"): self.id = 0 if not hasattr(self, "template"): self.template = data_template.DataTemplate() if not hasattr(self, "time"): self.time = time_type.TimeType()
def decode_api(self, data): ''' Decodes the given data and returns the result. This function allows for non-registered code to call the same decoding code as is used to parse data passed to the data_callback function. Args: data: Binary data to decode Returns: Parsed version of the event data in the form of a EventData object or None if the data is not decodable ''' ptr = 0 # Decode event ID here... id_obj = u32_type.U32Type() id_obj.deserialize(data, ptr) ptr += id_obj.getSize() event_id = id_obj.val # Decode time... event_time = time_type.TimeType() event_time.deserialize(data, ptr) ptr += event_time.getSize() if event_id in self.__dict: event_temp = self.__dict[event_id] arg_vals = self.decode_args(data, ptr, event_temp) return event_data.EventData(arg_vals, event_time, event_temp) else: print("Event decode error: id %d not in dictionary"%event_id) return None
def sample_event(sample_template): event = EventData([], time_type.TimeType(), sample_template) return event