|
18 | 18 |
|
19 | 19 | class TestEvaluatorDomainId: |
20 | 20 | """Test domain-id is added to SearchKeywords when available.""" |
21 | | - |
22 | | - @patch('sagemaker.core.helper.session_helper.Session') |
| 21 | + |
| 22 | + @pytest.fixture(autouse=True) |
| 23 | + def stub_aws_resolution(self): |
| 24 | + """Keep these unit tests offline. |
| 25 | +
|
| 26 | + ``Evaluator.create`` builds a default ``Session``, resolves/validates an execution |
| 27 | + role via IAM ``SimulatePrincipalPolicy``, and derives the hub name from the |
| 28 | + caller's account. Unmocked, those reach real AWS and made CI fail with |
| 29 | + ``Throttling: Rate exceeded``. |
| 30 | + """ |
| 31 | + session = Mock() |
| 32 | + with patch("sagemaker.ai_registry.evaluator.Session", return_value=session), patch( |
| 33 | + "sagemaker.train.defaults.TrainDefaults.get_sagemaker_session", |
| 34 | + return_value=session, |
| 35 | + ), patch( |
| 36 | + "sagemaker.train.defaults.TrainDefaults.get_role", |
| 37 | + return_value="arn:aws:iam::123456789012:role/test-role", |
| 38 | + ), patch( |
| 39 | + "sagemaker.ai_registry.air_hub_entity.AIRHub.get_hub_name", |
| 40 | + return_value="test-hub", |
| 41 | + ): |
| 42 | + yield |
| 43 | + |
23 | 44 | @patch('sagemaker.ai_registry.evaluator._get_current_domain_id') |
24 | 45 | @patch('sagemaker.ai_registry.evaluator.AIRHub') |
25 | 46 | def test_domain_id_added_when_available( |
26 | | - self, mock_air_hub, mock_get_domain_id, mock_session |
| 47 | + self, mock_air_hub, mock_get_domain_id |
27 | 48 | ): |
28 | 49 | """Test that domain-id is added to tags when available.""" |
29 | 50 | # Setup mocks |
30 | 51 | mock_domain_id = "d-test123456" |
31 | 52 | mock_get_domain_id.return_value = mock_domain_id |
32 | | - mock_session.return_value = Mock() |
33 | 53 |
|
34 | 54 | # Mock AIRHub methods |
35 | 55 | mock_air_hub.import_hub_content = Mock() |
@@ -62,16 +82,14 @@ def test_domain_id_added_when_available( |
62 | 82 | # Verify domain-id is in tags |
63 | 83 | assert any(tag[0] == '@domain' and tag[1] == mock_domain_id for tag in tags) |
64 | 84 |
|
65 | | - @patch('sagemaker.core.helper.session_helper.Session') |
66 | 85 | @patch('sagemaker.ai_registry.evaluator._get_current_domain_id') |
67 | 86 | @patch('sagemaker.ai_registry.evaluator.AIRHub') |
68 | 87 | def test_domain_id_not_added_when_unavailable( |
69 | | - self, mock_air_hub, mock_get_domain_id, mock_session |
| 88 | + self, mock_air_hub, mock_get_domain_id |
70 | 89 | ): |
71 | 90 | """Test that domain-id is not added when unavailable (non-Studio).""" |
72 | 91 | # Setup mocks - domain_id returns None |
73 | 92 | mock_get_domain_id.return_value = None |
74 | | - mock_session.return_value = Mock() |
75 | 93 |
|
76 | 94 | # Mock AIRHub methods |
77 | 95 | mock_air_hub.import_hub_content = Mock() |
@@ -104,18 +122,16 @@ def test_domain_id_not_added_when_unavailable( |
104 | 122 | # Verify domain-id is NOT in tags |
105 | 123 | assert not any(tag[0] == '@domain' for tag in tags) |
106 | 124 |
|
107 | | - @patch('sagemaker.core.helper.session_helper.Session') |
108 | 125 | @patch('sagemaker.ai_registry.evaluator._get_current_domain_id') |
109 | 126 | @patch('sagemaker.ai_registry.evaluator.AIRHub') |
110 | 127 | def test_explicit_domain_id_used_without_auto_detection( |
111 | | - self, mock_air_hub, mock_get_domain_id, mock_session |
| 128 | + self, mock_air_hub, mock_get_domain_id |
112 | 129 | ): |
113 | 130 | """An explicit domain_id is tagged and auto-detection is not invoked. |
114 | 131 |
|
115 | 132 | Covers the non-Studio case (P467494019) where the domain cannot be inferred and |
116 | 133 | must be supplied by the caller. |
117 | 134 | """ |
118 | | - mock_session.return_value = Mock() |
119 | 135 | mock_air_hub.import_hub_content = Mock() |
120 | 136 | mock_air_hub.describe_hub_content = Mock(return_value={ |
121 | 137 | 'HubContentName': 'test-evaluator', |
|
0 commit comments