copilot-swe-agent[bot] raylim commited on
Commit
6fcc1b9
·
1 Parent(s): 8f383ed

Address code review feedback: add deterministic seeds and improve mocks

Browse files
tests/inference/test_data.py CHANGED
@@ -63,16 +63,19 @@ class TestTileFeatureTensorDataset:
63
  @pytest.fixture
64
  def sample_features(self):
65
  """Create sample features for testing."""
 
66
  return np.random.rand(100, 768).astype(np.float32)
67
 
68
  @pytest.fixture
69
  def large_features(self):
70
  """Create large sample features for testing padding/truncation."""
 
71
  return np.random.rand(25000, 768).astype(np.float32)
72
 
73
  @pytest.fixture
74
  def small_features(self):
75
  """Create small sample features for testing padding."""
 
76
  return np.random.rand(50, 768).astype(np.float32)
77
 
78
  def test_dataset_initialization(self, sample_features):
@@ -157,6 +160,7 @@ class TestTileFeatureTensorDataset:
157
 
158
  def test_features_exact_size(self):
159
  """Test that features of exactly n_max_tiles are not modified."""
 
160
  n_max_tiles = 100
161
  features = np.random.rand(n_max_tiles, 768).astype(np.float32)
162
  dataset = TileFeatureTensorDataset(
@@ -178,6 +182,7 @@ class TestTileFeatureTensorDataset:
178
 
179
  def test_different_feature_dimensions(self):
180
  """Test dataset with different feature dimensions."""
 
181
  for dim in [256, 512, 768, 1024]:
182
  features = np.random.rand(100, dim).astype(np.float32)
183
  dataset = TileFeatureTensorDataset(
 
63
  @pytest.fixture
64
  def sample_features(self):
65
  """Create sample features for testing."""
66
+ np.random.seed(42)
67
  return np.random.rand(100, 768).astype(np.float32)
68
 
69
  @pytest.fixture
70
  def large_features(self):
71
  """Create large sample features for testing padding/truncation."""
72
+ np.random.seed(42)
73
  return np.random.rand(25000, 768).astype(np.float32)
74
 
75
  @pytest.fixture
76
  def small_features(self):
77
  """Create small sample features for testing padding."""
78
+ np.random.seed(42)
79
  return np.random.rand(50, 768).astype(np.float32)
80
 
81
  def test_dataset_initialization(self, sample_features):
 
160
 
161
  def test_features_exact_size(self):
162
  """Test that features of exactly n_max_tiles are not modified."""
163
+ np.random.seed(42)
164
  n_max_tiles = 100
165
  features = np.random.rand(n_max_tiles, 768).astype(np.float32)
166
  dataset = TileFeatureTensorDataset(
 
182
 
183
  def test_different_feature_dimensions(self):
184
  """Test dataset with different feature dimensions."""
185
+ np.random.seed(42)
186
  for dim in [256, 512, 768, 1024]:
187
  features = np.random.rand(100, dim).astype(np.float32)
188
  dataset = TileFeatureTensorDataset(
tests/inference/test_paladin.py CHANGED
@@ -157,6 +157,7 @@ class TestLogitsToPointEstimates:
157
  def test_logits_to_point_estimates_shape(self):
158
  """Test that output shape is correct."""
159
  # logits shape: (batch_size, 2 * n_tasks)
 
160
  batch_size = 4
161
  n_tasks = 5
162
  logits = torch.rand(batch_size, 2 * n_tasks)
@@ -185,6 +186,7 @@ class TestLogitsToPointEstimates:
185
 
186
  def test_logits_to_point_estimates_multiple_batches(self):
187
  """Test with multiple batches."""
 
188
  logits = torch.rand(10, 8) # 10 batches, 4 tasks
189
  result = logits_to_point_estimates(logits)
190
  assert result.shape == (10, 4)
 
157
  def test_logits_to_point_estimates_shape(self):
158
  """Test that output shape is correct."""
159
  # logits shape: (batch_size, 2 * n_tasks)
160
+ torch.manual_seed(42)
161
  batch_size = 4
162
  n_tasks = 5
163
  logits = torch.rand(batch_size, 2 * n_tasks)
 
186
 
187
  def test_logits_to_point_estimates_multiple_batches(self):
188
  """Test with multiple batches."""
189
+ torch.manual_seed(42)
190
  logits = torch.rand(10, 8) # 10 batches, 4 tasks
191
  result = logits_to_point_estimates(logits)
192
  assert result.shape == (10, 4)
tests/test_gradio_app.py CHANGED
@@ -177,10 +177,10 @@ class TestGetOncotreeCodeName:
177
  """Test that invalid code returns 'Unknown'."""
178
  from mosaic.gradio_app import get_oncotree_code_name, oncotree_code_map
179
 
180
- # Mock the requests.get call to return 404
181
  mock_response = mocker.Mock()
182
- mock_response.status_code = 404
183
- mock_response.json.return_value = []
184
  mocker.patch("requests.get", return_value=mock_response)
185
 
186
  # Clear cache and use an invalid code
 
177
  """Test that invalid code returns 'Unknown'."""
178
  from mosaic.gradio_app import get_oncotree_code_name, oncotree_code_map
179
 
180
+ # Mock the requests.get call to return empty response (no matching codes)
181
  mock_response = mocker.Mock()
182
+ mock_response.status_code = 200
183
+ mock_response.json.return_value = [] # Empty list means no matching codes found
184
  mocker.patch("requests.get", return_value=mock_response)
185
 
186
  # Clear cache and use an invalid code