11# -*- coding: utf-8 -*-
2+ import warnings
23from datetime import datetime , timezone
3- from typing import List , Optional
4+ from typing import Callable , List , Optional , TypedDict
45
56import pytest # type: ignore
67import responses
3132from responses import matchers
3233
3334
35+ _TestResultIdArg = TypedDict (
36+ "_TestResultIdArg" , {"test_result_id" : Optional [str ]}, total = False
37+ )
38+
3439int_index_column = Column (
3540 name = "index" , data_type = DataType .Int32 , column_type = ColumnType .Index
3641)
@@ -84,6 +89,21 @@ def test_tables(create_table):
8489 return ids
8590
8691
92+ @pytest .fixture (scope = "class" )
93+ def supports_test_result_id (client : DataFrameClient ) -> bool :
94+ """Fixture to determine if the server supports test result IDs."""
95+ api_info = client .api_info ()
96+ result = api_info .operations .create_tables .version >= 2
97+ if not result :
98+ warnings .warn (
99+ (
100+ "The selected version of the DataFrame Service does not support test "
101+ "result IDs. Tests will not attempt to set a test result ID."
102+ )
103+ )
104+ return result
105+
106+
87107@pytest .mark .enterprise
88108@pytest .mark .integration
89109class TestDataFrame :
@@ -126,6 +146,43 @@ def test__create_table__metadata_is_correct(
126146 properties = {},
127147 ),
128148 ]
149+ assert table_metadata .test_result_id is None
150+
151+ def test__create_table__supports_test_result (
152+ self ,
153+ client : DataFrameClient ,
154+ create_table : Callable [[CreateTableRequest ], str ],
155+ supports_test_result_id : bool ,
156+ ):
157+ test_result_id = "Test result" if supports_test_result_id else None
158+ id = create_table (
159+ CreateTableRequest (
160+ columns = [
161+ Column (
162+ name = "index" ,
163+ data_type = DataType .Int32 ,
164+ column_type = ColumnType .Index ,
165+ )
166+ ],
167+ name = "Test table with test result ID" ,
168+ test_result_id = test_result_id ,
169+ )
170+ )
171+
172+ table = client .get_table_metadata (id )
173+ assert table .test_result_id == test_result_id
174+
175+ page = client .list_tables (take = 1 , id = [id ])
176+ assert len (page .tables ) == 1
177+ assert page .tables [0 ].test_result_id == test_result_id
178+ assert page .continuation_token is None
179+
180+ page = client .query_tables (
181+ QueryTablesRequest (filter = "id == @0" , substitutions = [id ], take = 1 )
182+ )
183+ assert len (page .tables ) == 1
184+ assert page .tables [0 ].test_result_id == test_result_id
185+ assert page .continuation_token is None
129186
130187 def test__get_table__correct_timestamp (self , client : DataFrameClient , create_table ):
131188 id = create_table (basic_table_model )
@@ -188,7 +245,9 @@ def test__query_tables__returns(
188245 assert len (second_page .tables ) == 1
189246 assert second_page .continuation_token is None
190247
191- def test__modify_table__returns (self , client : DataFrameClient , create_table ):
248+ def test__modify_table__returns (
249+ self , client : DataFrameClient , create_table , supports_test_result_id : bool
250+ ):
192251 id = create_table (basic_table_model )
193252
194253 client .modify_table (
@@ -200,12 +259,18 @@ def test__modify_table__returns(self, client: DataFrameClient, create_table):
200259 columns = [
201260 ColumnMetadataPatch (name = "index" , properties = {"sheep" : "baa" })
202261 ],
262+ ** self ._test_result_id_if_supported (
263+ "Test result" , supports_test_result_id
264+ ),
203265 ),
204266 )
205267 table = client .get_table_metadata (id )
206268
207269 assert table .metadata_revision == 2
208270 assert table .name == "Modified table"
271+ assert table .test_result_id == (
272+ "Test result" if supports_test_result_id else None
273+ )
209274 assert table .properties == {"cow" : "moo" }
210275 assert table .columns [0 ].properties == {"sheep" : "baa" }
211276
@@ -214,6 +279,9 @@ def test__modify_table__returns(self, client: DataFrameClient, create_table):
214279
215280 assert table .properties == {"cow" : "moo" , "bee" : "buzz" }
216281 assert table .name == "Modified table"
282+ assert table .test_result_id == (
283+ "Test result" if supports_test_result_id else None
284+ )
217285
218286 client .modify_table (
219287 id ,
@@ -222,15 +290,23 @@ def test__modify_table__returns(self, client: DataFrameClient, create_table):
222290 name = None ,
223291 properties = {"cow" : None },
224292 columns = [ColumnMetadataPatch (name = "index" , properties = {"sheep" : None })],
293+ ** self ._test_result_id_if_supported (None , supports_test_result_id ),
225294 ),
226295 )
227296 table = client .get_table_metadata (id )
228297
229298 assert table .metadata_revision == 4
230299 assert table .name == id
300+ assert table .test_result_id is None
231301 assert table .properties == {"bee" : "buzz" }
232302 assert table .columns [0 ].properties == {}
233303
304+ @staticmethod
305+ def _test_result_id_if_supported (
306+ test_result_id : Optional [str ], supports_test_result_id : bool
307+ ) -> _TestResultIdArg :
308+ return {"test_result_id" : test_result_id } if supports_test_result_id else {}
309+
234310 def test__delete_table__deletes (self , client : DataFrameClient ):
235311 id = client .create_table (
236312 basic_table_model
@@ -259,13 +335,16 @@ def test__delete_tables__returns_partial_success(self, client: DataFrameClient):
259335 assert len (response .error .inner_errors ) == 1
260336
261337 def test__modify_tables__modifies_tables (
262- self , client : DataFrameClient , create_table
338+ self , client : DataFrameClient , create_table , supports_test_result_id : bool
263339 ):
264340 ids = [create_table (basic_table_model ) for _ in range (3 )]
265341
266342 updates = [
267343 TableMetadataModification (
268- id = id , name = "Modified table" , properties = {"duck" : "quack" }
344+ id = id ,
345+ name = "Modified table" ,
346+ test_result_id = "Test result" if supports_test_result_id else None ,
347+ properties = {"duck" : "quack" },
269348 )
270349 for id in ids
271350 ]
@@ -274,6 +353,9 @@ def test__modify_tables__modifies_tables(
274353
275354 for table in client .list_tables (id = ids ).tables :
276355 assert table .name == "Modified table"
356+ assert table .test_result_id == (
357+ "Test result" if supports_test_result_id else None
358+ )
277359 assert table .properties == {"duck" : "quack" }
278360
279361 updates = [
@@ -286,15 +368,34 @@ def test__modify_tables__modifies_tables(
286368 )
287369
288370 for table in client .list_tables (id = ids ).tables :
371+ assert table .name == "Modified table"
372+ assert table .test_result_id == (
373+ "Test result" if supports_test_result_id else None
374+ )
289375 assert table .properties == {"pig" : "oink" }
290376
377+ if supports_test_result_id :
378+ updates = [
379+ TableMetadataModification (id = id , test_result_id = "" ) for id in ids
380+ ]
381+
382+ assert client .modify_tables (ModifyTablesRequest (tables = updates )) is None
383+
384+ for table in client .list_tables (id = ids ).tables :
385+ assert table .name == "Modified table"
386+ assert table .test_result_id is None
387+
291388 def test__modify_tables__returns_partial_success (
292- self , client : DataFrameClient , create_table
389+ self , client : DataFrameClient , create_table , supports_test_result_id : bool
293390 ):
294391 id = create_table (basic_table_model )
295392
296393 updates = [
297- TableMetadataModification (id = id , name = "Modified table" )
394+ TableMetadataModification (
395+ id = id ,
396+ name = "Modified table" ,
397+ test_result_id = "Test result" if supports_test_result_id else None ,
398+ )
298399 for id in [id , "invalid_id" ]
299400 ]
300401
0 commit comments