Skip to content

Commit 06e7af2

Browse files
committed
fix: resolve dependency conflicts and fix all failing tests
- Fix NumPy 2.x incompatibility by pinning numpy<2.0.0 in pyproject.toml and requirements.txt - Constrain PyTorch to <=2.2.2 for macOS x86_64 compatibility - Add missing openpyxl>=3.1.5 dependency for Excel export functionality - Fix database command test mocks by correcting Path import paths - Update integration test assertions to match actual CLI help text - Fix preprocessing command test mocks for transform operations - Add proper return value mocks for validate_transformation and export_standardized methods All 14 previously failing tests now pass successfully.
1 parent 6cc03a1 commit 06e7af2

File tree

7 files changed

+222
-367
lines changed

7 files changed

+222
-367
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ dist/
4545

4646
# Testing and coverage
4747
.coverage
48+
.coverage*
4849
htmlcov/
4950
.pytest_cache/
5051

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ classifiers = [
2424

2525
requires-python = ">=3.9"
2626
dependencies = [
27+
"numpy<2.0.0",
2728
"transformers>=4.35.0",
2829
"accelerate>=0.24.0",
2930
"openai>=1.3.0",
@@ -35,12 +36,13 @@ dependencies = [
3536
"tqdm>=4.66.0",
3637
"huggingface_hub>=0.19.0",
3738
"pyyaml>=6.0.1",
38-
"torch>=2.1.0",
39+
"torch>=2.1.0,<=2.2.2",
3940
"typer>=0.9.0",
4041
"rich>=13.0.0",
4142
"instructor>=1.0.0",
4243
"pydantic>=2.0.0",
4344
"sqlalchemy>=2.0.0",
45+
"openpyxl>=3.1.5",
4446
]
4547

4648
[project.optional-dependencies]

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
numpy<2.0.0
12
transformers
23
accelerate
34
bitsandbytes
@@ -12,7 +13,7 @@ datasets
1213
python-dotenv
1314
jupyter
1415
ipykernel
15-
torch
16+
torch<=2.2.2
1617
typer
1718
rich
1819
pydantic

tests/cli/test_db_commands.py

Lines changed: 80 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_db_init_new_database(self, mock_config, mock_manager):
5151

5252
@patch("ml_agents.core.database_manager.DatabaseManager")
5353
@patch("ml_agents.core.database_manager.DatabaseConfig")
54-
@patch("pathlib.Path")
54+
@patch("ml_agents.cli.commands.db.Path")
5555
def test_db_init_existing_database_without_force(
5656
self, mock_path, mock_config, mock_manager
5757
):
@@ -71,7 +71,7 @@ def test_db_init_existing_database_without_force(
7171

7272
@patch("ml_agents.core.database_manager.DatabaseManager")
7373
@patch("ml_agents.core.database_manager.DatabaseConfig")
74-
@patch("pathlib.Path")
74+
@patch("ml_agents.cli.commands.db.Path")
7575
def test_db_init_existing_database_with_force(
7676
self, mock_path, mock_config, mock_manager
7777
):
@@ -98,8 +98,13 @@ def test_db_init_existing_database_with_force(
9898

9999
@patch("ml_agents.core.database_manager.DatabaseManager")
100100
@patch("ml_agents.core.database_manager.DatabaseConfig")
101-
def test_db_init_default_path(self, mock_config, mock_manager):
101+
@patch("ml_agents.cli.commands.db.Path")
102+
def test_db_init_default_path(self, mock_path, mock_config, mock_manager):
102103
"""Test db init with default database path."""
104+
mock_path_instance = Mock()
105+
mock_path_instance.exists.return_value = False
106+
mock_path.return_value = mock_path_instance
107+
103108
mock_manager_instance = Mock()
104109
mock_manager_instance.get_database_stats.return_value = {
105110
"schema_version": "1.2.0",
@@ -142,35 +147,35 @@ def test_db_backup_command_help(self):
142147

143148
@patch("ml_agents.core.database_manager.DatabaseManager")
144149
@patch("ml_agents.core.database_manager.DatabaseConfig")
145-
@patch("pathlib.Path")
150+
@patch("ml_agents.cli.commands.db.Path")
146151
def test_db_backup_success(self, mock_path, mock_config, mock_manager):
147152
"""Test successful database backup."""
148-
# Mock source database exists
149-
mock_source_path = Mock()
150-
mock_source_path.exists.return_value = True
151-
mock_path.return_value = mock_source_path
152-
153-
# Mock backup file stats
154-
mock_backup_path = Mock()
155-
mock_backup_path.stat.return_value.st_size = 2048
156-
157-
with patch(
158-
"ml_agents.cli.commands.db.Path",
159-
side_effect=lambda x: (
160-
mock_source_path if "source" in str(x) else mock_backup_path
161-
),
162-
):
163-
mock_manager_instance = Mock()
164-
mock_manager.return_value = mock_manager_instance
165153

166-
result = self.runner.invoke(app, ["db", "backup", "--source", "source.db"])
154+
# Mock source database exists and backup file stats
155+
def path_side_effect(path_str):
156+
mock_path_instance = Mock()
157+
if "source.db" == str(path_str) and "backup" not in str(path_str):
158+
mock_path_instance.exists.return_value = True
159+
else:
160+
# This is the backup file path - mock stat method
161+
mock_stat = Mock()
162+
mock_stat.st_size = 2048
163+
mock_path_instance.stat.return_value = mock_stat
164+
return mock_path_instance
167165

168-
assert result.exit_code == 0
169-
assert "Database backup created successfully" in result.stdout
170-
assert "Source: source.db" in result.stdout
171-
assert "Size: 2048 bytes" in result.stdout
166+
mock_path.side_effect = path_side_effect
167+
168+
mock_manager_instance = Mock()
169+
mock_manager.return_value = mock_manager_instance
170+
171+
result = self.runner.invoke(app, ["db", "backup", "--source", "source.db"])
172+
173+
assert result.exit_code == 0
174+
assert "Database backup created successfully" in result.stdout
175+
assert "Source: source.db" in result.stdout
176+
assert "Size: 2048 bytes" in result.stdout
172177

173-
@patch("pathlib.Path")
178+
@patch("ml_agents.cli.commands.db.Path")
174179
def test_db_backup_source_not_exists(self, mock_path):
175180
"""Test backup when source database doesn't exist."""
176181
mock_path_instance = Mock()
@@ -184,47 +189,60 @@ def test_db_backup_source_not_exists(self, mock_path):
184189

185190
@patch("ml_agents.core.database_manager.DatabaseManager")
186191
@patch("ml_agents.core.database_manager.DatabaseConfig")
187-
@patch("pathlib.Path")
192+
@patch("ml_agents.cli.commands.db.Path")
188193
def test_db_backup_custom_path(self, mock_path, mock_config, mock_manager):
189194
"""Test backup with custom backup path."""
190-
mock_source_path = Mock()
191-
mock_source_path.exists.return_value = True
192-
mock_backup_path = Mock()
193-
mock_backup_path.stat.return_value.st_size = 1500
194195

195196
def path_side_effect(path):
197+
mock_path_instance = Mock()
196198
if "custom_backup" in str(path):
197-
return mock_backup_path
198-
return mock_source_path
199+
mock_stat = Mock()
200+
mock_stat.st_size = 1500
201+
mock_path_instance.stat.return_value = mock_stat
202+
else:
203+
mock_path_instance.exists.return_value = True
204+
return mock_path_instance
199205

200-
with patch("ml_agents.cli.commands.db.Path", side_effect=path_side_effect):
201-
mock_manager_instance = Mock()
202-
mock_manager.return_value = mock_manager_instance
206+
mock_path.side_effect = path_side_effect
203207

204-
result = self.runner.invoke(
205-
app,
206-
[
207-
"db",
208-
"backup",
209-
"--source",
210-
"source.db",
211-
"--backup-path",
212-
"custom_backup.db",
213-
],
214-
)
208+
mock_manager_instance = Mock()
209+
mock_manager.return_value = mock_manager_instance
215210

216-
assert result.exit_code == 0
217-
assert "Backup: custom_backup.db" in result.stdout
211+
result = self.runner.invoke(
212+
app,
213+
[
214+
"db",
215+
"backup",
216+
"--source",
217+
"source.db",
218+
"--backup-path",
219+
"custom_backup.db",
220+
],
221+
)
222+
223+
assert result.exit_code == 0
224+
assert "Backup: custom_backup.db" in result.stdout
218225

219226
@patch("ml_agents.core.database_manager.DatabaseManager")
220227
@patch("ml_agents.core.database_manager.DatabaseConfig")
221-
@patch("pathlib.Path")
228+
@patch("ml_agents.cli.commands.db.Path")
222229
def test_db_backup_default_source(self, mock_path, mock_config, mock_manager):
223230
"""Test backup with default source path."""
224-
mock_path_instance = Mock()
225-
mock_path_instance.exists.return_value = True
226-
mock_path_instance.stat.return_value.st_size = 1024
227-
mock_path.return_value = mock_path_instance
231+
232+
def path_side_effect(path_str):
233+
mock_path_instance = Mock()
234+
if "ml_agents_results.db" in str(path_str) and "backup" not in str(
235+
path_str
236+
):
237+
mock_path_instance.exists.return_value = True
238+
else:
239+
# This is the backup file
240+
mock_stat = Mock()
241+
mock_stat.st_size = 1024
242+
mock_path_instance.stat.return_value = mock_stat
243+
return mock_path_instance
244+
245+
mock_path.side_effect = path_side_effect
228246

229247
mock_manager_instance = Mock()
230248
mock_manager.return_value = mock_manager_instance
@@ -251,7 +269,7 @@ def test_db_stats_command_help(self):
251269

252270
@patch("ml_agents.core.database_manager.DatabaseManager")
253271
@patch("ml_agents.core.database_manager.DatabaseConfig")
254-
@patch("pathlib.Path")
272+
@patch("ml_agents.cli.commands.db.Path")
255273
def test_db_stats_display(self, mock_path, mock_config, mock_manager):
256274
"""Test database statistics display."""
257275
mock_path_instance = Mock()
@@ -282,7 +300,7 @@ def test_db_stats_display(self, mock_path, mock_config, mock_manager):
282300
assert "5,120 bytes" in result.stdout
283301
assert "Database integrity check passed" in result.stdout
284302

285-
@patch("pathlib.Path")
303+
@patch("ml_agents.cli.commands.db.Path")
286304
def test_db_stats_database_not_found(self, mock_path):
287305
"""Test stats when database doesn't exist."""
288306
mock_path_instance = Mock()
@@ -296,7 +314,7 @@ def test_db_stats_database_not_found(self, mock_path):
296314

297315
@patch("ml_agents.core.database_manager.DatabaseManager")
298316
@patch("ml_agents.core.database_manager.DatabaseConfig")
299-
@patch("pathlib.Path")
317+
@patch("ml_agents.cli.commands.db.Path")
300318
def test_db_stats_integrity_failed(self, mock_path, mock_config, mock_manager):
301319
"""Test stats with failed integrity check."""
302320
mock_path_instance = Mock()
@@ -337,7 +355,7 @@ def test_db_migrate_command_help(self):
337355

338356
@patch("ml_agents.core.database_manager.DatabaseManager")
339357
@patch("ml_agents.core.database_manager.DatabaseConfig")
340-
@patch("pathlib.Path")
358+
@patch("ml_agents.cli.commands.db.Path")
341359
def test_db_migrate_schema_update(self, mock_path, mock_config, mock_manager):
342360
"""Test schema migration process."""
343361
mock_path_instance = Mock()
@@ -370,7 +388,7 @@ def test_db_migrate_schema_update(self, mock_path, mock_config, mock_manager):
370388

371389
@patch("ml_agents.core.database_manager.DatabaseManager")
372390
@patch("ml_agents.core.database_manager.DatabaseConfig")
373-
@patch("pathlib.Path")
391+
@patch("ml_agents.cli.commands.db.Path")
374392
def test_db_migrate_already_up_to_date(self, mock_path, mock_config, mock_manager):
375393
"""Test migration when schema is already up to date."""
376394
mock_path_instance = Mock()
@@ -395,7 +413,7 @@ def test_db_migrate_already_up_to_date(self, mock_path, mock_config, mock_manage
395413
assert result.exit_code == 0
396414
assert "Database schema is already up to date" in result.stdout
397415

398-
@patch("pathlib.Path")
416+
@patch("ml_agents.cli.commands.db.Path")
399417
def test_db_migrate_database_not_found(self, mock_path):
400418
"""Test migration when database doesn't exist."""
401419
mock_path_instance = Mock()
@@ -411,7 +429,7 @@ def test_db_migrate_database_not_found(self, mock_path):
411429

412430
@patch("ml_agents.core.database_manager.DatabaseManager")
413431
@patch("ml_agents.core.database_manager.DatabaseConfig")
414-
@patch("pathlib.Path")
432+
@patch("ml_agents.cli.commands.db.Path")
415433
def test_db_migrate_user_cancellation(self, mock_path, mock_config, mock_manager):
416434
"""Test migration cancellation by user."""
417435
mock_path_instance = Mock()

tests/cli/test_integration_smoke.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_main_help_accessible(self):
2424
"""Test that main CLI help is accessible."""
2525
result = self.runner.invoke(app, ["--help"])
2626
assert result.exit_code == 0
27-
assert "ML Agents CLI" in result.stdout
27+
assert "ML Agents Reasoning Research Platform" in result.stdout
2828
assert "setup" in result.stdout
2929
assert "preprocess" in result.stdout
3030
assert "db" in result.stdout

tests/cli/test_preprocess_commands.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_preprocess_list_command_help(self):
2222
"""Test preprocess list command help display."""
2323
result = self.runner.invoke(app, ["preprocess", "list", "--help"])
2424
assert result.exit_code == 0
25-
assert "unprocessed datasets" in result.stdout.lower()
25+
assert "haven't been preprocessed yet" in result.stdout.lower()
2626

2727
@patch("ml_agents.core.dataset_preprocessor.DatasetPreprocessor")
2828
def test_preprocess_list_unprocessed(self, mock_preprocessor):
@@ -341,6 +341,17 @@ def test_preprocess_transform_apply(self, mock_preprocessor):
341341
mock_preprocessor_instance.apply_transformation.return_value = (
342342
mock_transformed
343343
)
344+
# Mock validation results that the function expects
345+
mock_preprocessor_instance.validate_transformation.return_value = {
346+
"validation_passed": True,
347+
"issues": [],
348+
"original_samples": 100,
349+
"transformed_samples": 100,
350+
"empty_inputs": 0,
351+
"empty_outputs": 0,
352+
}
353+
# Mock the export method
354+
mock_preprocessor_instance.export_standardized.return_value = None
344355
mock_preprocessor.return_value = mock_preprocessor_instance
345356

346357
with patch("datasets.load_dataset") as mock_load:
@@ -463,9 +474,7 @@ def test_preprocess_batch_processing(self, mock_preprocessor):
463474
mock_preprocessor.return_value = mock_preprocessor_instance
464475

465476
with patch("datasets.load_dataset") as mock_load:
466-
with patch(
467-
"ml_agents.cli.commands.preprocess.get_dataset_config_info"
468-
) as mock_config_info:
477+
with patch("datasets.get_dataset_config_info") as mock_config_info:
469478
mock_config_info.return_value.splits = {"train": Mock()}
470479
mock_load.return_value = Mock()
471480

@@ -499,7 +508,7 @@ def test_preprocess_upload_command_help(self):
499508
"""Test preprocess upload command help display."""
500509
result = self.runner.invoke(app, ["preprocess", "upload", "--help"])
501510
assert result.exit_code == 0
502-
assert "huggingface hub" in result.stdout.lower()
511+
assert "huggingface" in result.stdout.lower()
503512

504513
@patch("ml_agents.core.dataset_uploader.DatasetUploader")
505514
def test_preprocess_upload_dataset(self, mock_uploader):

0 commit comments

Comments
 (0)