19
19
20
20
HOOKSCRIPT_PATH = "hookscript_example"
21
21
POST_WRITE_HOOKSCRIPT_PATH = "post_write_hookscript_example"
22
+ CUSTOM_ADAPTER_HOOKSCRIPT_PATH = "custom_adapter_hookscript_example"
22
23
23
24
POST_RUN_NAME = "hook ran and did stuff"
24
25
TEST_METADATA = {'extra_data' : True }
@@ -71,8 +72,17 @@ def setUp(self):
71
72
"baselines" ,
72
73
POST_WRITE_HOOKSCRIPT_PATH
73
74
)
74
- self .man .hook_scripts = [self .hsf , self .post_hsf ]
75
-
75
+ self .adapter_hook_jsn = baseline_reader .json_baseline_as_string (
76
+ CUSTOM_ADAPTER_HOOKSCRIPT_PATH
77
+ )
78
+ self .adapter_hookscript = otio .adapters .otio_json .read_from_string (
79
+ self .adapter_hook_jsn )
80
+ self .adapter_hookscript ._json_path = os .path .join (
81
+ baseline_reader .MODPATH ,
82
+ "baselines" ,
83
+ HOOKSCRIPT_PATH
84
+ )
85
+ self .man .hook_scripts = [self .hsf , self .post_hsf , self .adapter_hookscript ]
76
86
self .orig_manifest = otio .plugins .manifest ._MANIFEST
77
87
otio .plugins .manifest ._MANIFEST = self .man
78
88
@@ -83,6 +93,8 @@ def tearDown(self):
83
93
def test_plugin_adapter (self ):
84
94
self .assertEqual (self .hsf .name , "example hook" )
85
95
self .assertEqual (self .hsf .filepath , "example.py" )
96
+ self .assertEqual (otio .adapters .from_name ("example" ).adapter_hook_names (),
97
+ ["custom_adapter_hook" ])
86
98
87
99
def test_load_adapter_module (self ):
88
100
target = os .path .join (
@@ -101,15 +113,25 @@ def test_run_hook_function(self):
101
113
self .assertEqual (result .name , POST_RUN_NAME )
102
114
self .assertEqual (result .metadata .get ("extra_data" ), True )
103
115
116
+ def test_run_custom_hook_function (self ):
117
+ tl = otio .schema .Timeline ()
118
+ result = otio .hooks .run (hook = "custom_adapter_hook" , tl = tl ,
119
+ extra_args = TEST_METADATA )
120
+ self .assertEqual (result .metadata ["custom_hook" ], TEST_METADATA )
121
+
104
122
def test_run_hook_through_adapters (self ):
123
+ hook_map = dict (TEST_METADATA )
124
+ hook_map ["run_custom_hook" ] = True
125
+
105
126
result = otio .adapters .read_from_string (
106
127
'foo' , adapter_name = 'example' ,
107
128
media_linker_name = 'example' ,
108
- hook_function_argument_map = TEST_METADATA
129
+ hook_function_argument_map = hook_map
109
130
)
110
131
111
132
self .assertEqual (result .name , POST_RUN_NAME )
112
133
self .assertEqual (result .metadata .get ("extra_data" ), True )
134
+ self .assertEqual (result .metadata ["custom_hook" ]["extra_data" ], True )
113
135
114
136
def test_post_write_hook (self ):
115
137
self .man .adapters .extend (self .orig_manifest .adapters )
@@ -161,19 +183,20 @@ def test_available_hookscript_names(self):
161
183
# for not just assert that it returns a non-empty list
162
184
self .assertEqual (
163
185
list (otio .hooks .available_hookscripts ()),
164
- [self .hsf , self .post_hsf ]
186
+ [self .hsf , self .post_hsf , self . adapter_hookscript ]
165
187
)
166
188
self .assertEqual (
167
189
otio .hooks .available_hookscript_names (),
168
- [self .hsf .name , self .post_hsf .name ]
190
+ [self .hsf .name , self .post_hsf .name , self . adapter_hookscript . name ]
169
191
)
170
192
171
193
def test_manifest_hooks (self ):
172
194
self .assertEqual (
173
195
sorted (list (otio .hooks .names ())),
174
196
sorted (
175
197
["post_adapter_read" , "post_media_linker" ,
176
- "pre_adapter_write" , "post_adapter_write" ]
198
+ "pre_adapter_write" , "post_adapter_write" ,
199
+ "custom_adapter_hook" ]
177
200
)
178
201
)
179
202
@@ -204,6 +227,13 @@ def test_manifest_hooks(self):
204
227
]
205
228
)
206
229
230
+ self .assertEqual (
231
+ list (otio .hooks .scripts_attached_to ("custom_adapter_hook" )),
232
+ [
233
+ self .adapter_hookscript .name
234
+ ]
235
+ )
236
+
207
237
tl = otio .schema .Timeline ()
208
238
result = otio .hooks .run ("pre_adapter_write" , tl , TEST_METADATA )
209
239
self .assertEqual (result .name , POST_RUN_NAME )
0 commit comments