File tree 2 files changed +23
-7
lines changed
tests/flytekit/unit/sensor
2 files changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -63,10 +63,15 @@ def __init__(
63
63
annotation = type_hints .get (k , None )
64
64
inputs [k ] = annotation
65
65
66
- if kwargs .get ("metadata" , None ) and timeout :
67
- raise ValueError ("You cannot set timeout and metadata at the same time in the sensor" )
68
-
69
- metadata = TaskMetadata (timeout = timeout )
66
+ # Handle metadata and timeout logic
67
+ metadata = kwargs .pop ("metadata" , None )
68
+ if metadata is not None and timeout is not None :
69
+ if metadata .timeout is not None :
70
+ raise ValueError ("You cannot set both timeout and metadata parameters at the same time in the sensor" )
71
+ else :
72
+ metadata .timeout = timeout
73
+ else :
74
+ metadata = TaskMetadata (timeout = timeout ) if timeout else TaskMetadata ()
70
75
71
76
super ().__init__ (
72
77
task_type = task_type ,
Original file line number Diff line number Diff line change @@ -79,8 +79,19 @@ def test_agent_executor_timeout_logging():
79
79
assert sensor .metadata .timeout == datetime .timedelta (seconds = 60 )
80
80
81
81
def test_file_sensor_set_timeout_and_metadata_at_the_same_time ():
82
+ """
83
+ The test is the combination of the following cases:
84
+ 1. Set timeout and metadata with timeout at the same time
85
+ 2. Set timeout and metadata without timeout
86
+ 3. Set timeout and no metadata
87
+ 4. Not set timeout and metadata with timeout
88
+ """
89
+
82
90
timeout = datetime .timedelta (seconds = 60 )
83
- metadata = TaskMetadata (timeout = timeout )
84
91
85
- with pytest .raises (ValueError , match = "You cannot set timeout and metadata at the same time in the sensor" ):
86
- FileSensor (name = "test_sensor" , timeout = 60 , metadata = metadata )
92
+ with pytest .raises (ValueError , match = "You cannot set both timeout and metadata parameters at the same time in the sensor" ):
93
+ FileSensor (name = "test_sensor" , timeout = 60 , metadata = TaskMetadata (timeout = timeout ))
94
+
95
+ FileSensor (name = "test_sensor" , timeout = 60 , metadata = TaskMetadata ())
96
+ FileSensor (name = "test_sensor" , timeout = 60 )
97
+ FileSensor (name = "test_sensor" , metadata = TaskMetadata (timeout = timeout ))
You can’t perform that action at this time.
0 commit comments