|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import importlib.util |
| 4 | +import json |
4 | 5 | import sys |
5 | 6 | import unittest |
6 | 7 | from pathlib import Path |
@@ -100,6 +101,66 @@ def test_require_consumer_files_treats_missing_paths_as_issues(self): |
100 | 101 | self.assertEqual(report.missing_files, ["ExamplePlatform/requirements.txt"]) |
101 | 102 | self.assertEqual(report.issues, []) |
102 | 103 |
|
| 104 | + def test_collect_dependency_pins_from_projects(self): |
| 105 | + projects_root = self._make_projects_root( |
| 106 | + { |
| 107 | + "ExampleA/pyproject.toml": "quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@a11", |
| 108 | + "ExampleB/requirements.txt": "us-equity-strategies @ git+https://github.com/QuantStrategyLab/UsEquityStrategies.git@b22", |
| 109 | + "ExampleB/requirements-lock.txt": "crypto-strategies @ git+https://github.com/QuantStrategyLab/CryptoStrategies.git@c33", |
| 110 | + } |
| 111 | + ) |
| 112 | + |
| 113 | + pins = check_internal_dependency_matrix.collect_dependency_pins_from_projects(projects_root) |
| 114 | + rows = [(pin.consumer_repo, pin.path, pin.package, pin.source_repo, pin.ref) for pin in pins] |
| 115 | + |
| 116 | + self.assertEqual(rows, [ |
| 117 | + ("ExampleA", "pyproject.toml", "quant-platform-kit", "QuantPlatformKit", "a11"), |
| 118 | + ("ExampleB", "requirements-lock.txt", "crypto-strategies", "CryptoStrategies", "c33"), |
| 119 | + ("ExampleB", "requirements.txt", "us-equity-strategies", "UsEquityStrategies", "b22"), |
| 120 | + ]) |
| 121 | + |
| 122 | + def test_sync_rewrites_matrix_with_stable_order(self): |
| 123 | + projects_root = self._make_projects_root( |
| 124 | + { |
| 125 | + "ExampleB/requirements.txt": "us-equity-strategies @ git+https://github.com/QuantStrategyLab/UsEquityStrategies.git@b22", |
| 126 | + "ExampleA/pyproject.toml": "quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@a11", |
| 127 | + } |
| 128 | + ) |
| 129 | + matrix_path = projects_root / "internal_dependency_matrix.json" |
| 130 | + matrix_path.write_text( |
| 131 | + ( |
| 132 | + "{\n" |
| 133 | + ' "schema_version": 1,\n' |
| 134 | + ' "dependencies": [\n' |
| 135 | + ' {\n' |
| 136 | + ' "consumer_repo": "ExampleB",\n' |
| 137 | + ' "path": "requirements.txt",\n' |
| 138 | + ' "package": "us-equity-strategies",\n' |
| 139 | + ' "source_repo": "UsEquityStrategies",\n' |
| 140 | + ' "ref": "b22"\n' |
| 141 | + " }\n" |
| 142 | + " ]\n" |
| 143 | + "}\n" |
| 144 | + ), |
| 145 | + encoding="utf-8", |
| 146 | + ) |
| 147 | + |
| 148 | + projects_payload = check_internal_dependency_matrix.matrix_payload( |
| 149 | + check_internal_dependency_matrix.collect_dependency_pins_from_projects(projects_root) |
| 150 | + ) |
| 151 | + exit_code = check_internal_dependency_matrix.main( |
| 152 | + ["--sync", "--projects-root", str(projects_root), "--matrix", str(matrix_path)] |
| 153 | + ) |
| 154 | + synced_payload = json.loads(matrix_path.read_text(encoding="utf-8")) |
| 155 | + |
| 156 | + self.assertEqual(exit_code, 0) |
| 157 | + self.assertEqual(synced_payload["schema_version"], 1) |
| 158 | + self.assertEqual(synced_payload["dependencies"], projects_payload["dependencies"]) |
| 159 | + self.assertLess( |
| 160 | + synced_payload["dependencies"][0]["path"], |
| 161 | + synced_payload["dependencies"][-1]["path"], |
| 162 | + ) |
| 163 | + |
103 | 164 | def _make_projects_root(self, files: dict[str, str]) -> Path: |
104 | 165 | import tempfile |
105 | 166 |
|
|
0 commit comments