|
1 | 1 | import unittest |
2 | | -import warnings |
3 | 2 | from unittest.mock import patch, Mock |
4 | 3 |
|
5 | 4 | from skyflow import LogLevel, Env |
@@ -427,68 +426,59 @@ def _build_client(self): |
427 | 426 |
|
428 | 427 | def test_update_log_level_emits_deprecation_warning(self): |
429 | 428 | client = self._build_client() |
430 | | - with warnings.catch_warnings(record=True) as caught: |
431 | | - warnings.simplefilter("always") |
| 429 | + with patch('skyflow.client.skyflow.log_warn') as mock_warn: |
432 | 430 | client.update_log_level(LogLevel.INFO) |
433 | | - deprecation_warnings = [w for w in caught if issubclass(w.category, DeprecationWarning)] |
434 | | - self.assertGreaterEqual(len(deprecation_warnings), 1) |
435 | | - self.assertTrue(any("set_log_level" in str(w.message) for w in deprecation_warnings)) |
436 | | - |
437 | | - def test_update_log_level_warning_points_at_caller(self): |
438 | | - client = self._build_client() |
439 | | - with warnings.catch_warnings(record=True) as caught: |
440 | | - warnings.simplefilter("always") |
441 | | - client.update_log_level(LogLevel.INFO) |
442 | | - self.assertEqual(caught[0].filename, __file__) |
| 431 | + mock_warn.assert_called_once() |
| 432 | + self.assertIn("set_log_level", mock_warn.call_args[0][0]) |
443 | 433 |
|
444 | 434 | def test_update_log_level_delegates_to_set_log_level(self): |
445 | 435 | client = self._build_client() |
446 | | - with warnings.catch_warnings(record=True): |
447 | | - warnings.simplefilter("always") |
448 | | - client.update_log_level(LogLevel.INFO) |
| 436 | + client.update_log_level(LogLevel.INFO) |
449 | 437 | self.assertEqual(client.get_log_level(), LogLevel.INFO) |
450 | 438 |
|
451 | 439 |
|
452 | 440 | class TestFileUploadRequestDeprecation(unittest.TestCase): |
453 | 441 | def test_keyword_args_no_warning(self): |
454 | | - with warnings.catch_warnings(record=True) as caught: |
455 | | - warnings.simplefilter("always") |
| 442 | + with patch('skyflow.vault.data._file_upload_request.log_warn') as mock_warn: |
456 | 443 | req = FileUploadRequest( |
457 | 444 | table="table", |
458 | 445 | column_name="col", |
459 | 446 | skyflow_id="sky123", |
460 | 447 | ) |
461 | | - self.assertEqual(len(caught), 0) |
| 448 | + mock_warn.assert_not_called() |
462 | 449 | self.assertEqual(req.table, "table") |
463 | 450 | self.assertEqual(req.column_name, "col") |
464 | 451 | self.assertEqual(req.skyflow_id, "sky123") |
465 | 452 |
|
| 453 | + def test_only_table_positional_no_warning(self): |
| 454 | + with patch('skyflow.vault.data._file_upload_request.log_warn') as mock_warn: |
| 455 | + req = FileUploadRequest("table", column_name="col", skyflow_id="sky123") |
| 456 | + mock_warn.assert_not_called() |
| 457 | + self.assertEqual(req.table, "table") |
| 458 | + |
466 | 459 | def test_old_positional_order_emits_deprecation_warning(self): |
467 | | - with warnings.catch_warnings(record=True) as caught: |
468 | | - warnings.simplefilter("always") |
| 460 | + with patch('skyflow.vault.data._file_upload_request.log_warn') as mock_warn: |
469 | 461 | req = FileUploadRequest("table", "sky123", "col") |
470 | | - self.assertEqual(len(caught), 1) |
471 | | - self.assertTrue(issubclass(caught[0].category, DeprecationWarning)) |
472 | | - self.assertIn("FileUploadRequest", str(caught[0].message)) |
| 462 | + mock_warn.assert_called_once() |
| 463 | + self.assertIn("FileUploadRequest", mock_warn.call_args[0][0]) |
473 | 464 |
|
474 | 465 | def test_old_positional_order_remaps_args_correctly(self): |
475 | | - with warnings.catch_warnings(record=True): |
476 | | - warnings.simplefilter("always") |
477 | | - req = FileUploadRequest("table", "sky123", "col") |
| 466 | + req = FileUploadRequest("table", "sky123", "col") |
478 | 467 | self.assertEqual(req.skyflow_id, "sky123") |
479 | 468 | self.assertEqual(req.column_name, "col") |
480 | 469 |
|
481 | | - def test_old_positional_order_warning_points_at_caller(self): |
482 | | - with warnings.catch_warnings(record=True) as caught: |
483 | | - warnings.simplefilter("always") |
484 | | - FileUploadRequest("table", "sky123", "col") |
485 | | - self.assertEqual(caught[0].filename, __file__) |
486 | | - |
487 | 470 | def test_single_positional_arg_emits_warning_and_sets_skyflow_id(self): |
488 | | - with warnings.catch_warnings(record=True) as caught: |
489 | | - warnings.simplefilter("always") |
| 471 | + with patch('skyflow.vault.data._file_upload_request.log_warn') as mock_warn: |
490 | 472 | req = FileUploadRequest("table", "sky123") |
491 | | - self.assertEqual(len(caught), 1) |
492 | | - self.assertTrue(issubclass(caught[0].category, DeprecationWarning)) |
| 473 | + mock_warn.assert_called_once() |
493 | 474 | self.assertEqual(req.skyflow_id, "sky123") |
494 | 475 | self.assertIsNone(req.column_name) |
| 476 | + |
| 477 | + def test_optional_fields_default_to_none(self): |
| 478 | + req = FileUploadRequest(table="table") |
| 479 | + self.assertIsNone(req.skyflow_id) |
| 480 | + self.assertIsNone(req.column_name) |
| 481 | + self.assertIsNone(req.file_path) |
| 482 | + self.assertIsNone(req.base64) |
| 483 | + self.assertIsNone(req.file_object) |
| 484 | + self.assertIsNone(req.file_name) |
0 commit comments