|
18 | 18 |
|
19 | 19 | from poetry_plugin_export.exporter import Exporter |
20 | 20 | from tests.markers import MARKER_CPYTHON |
| 21 | +from tests.markers import MARKER_DARWIN |
| 22 | +from tests.markers import MARKER_LINUX |
21 | 23 | from tests.markers import MARKER_PY |
22 | 24 | from tests.markers import MARKER_PY27 |
23 | 25 | from tests.markers import MARKER_PY36 |
@@ -2321,3 +2323,78 @@ def test_exporter_omits_unwanted_extras( |
2321 | 2323 | exporter.export("requirements.txt", Path(tmp_dir), io) |
2322 | 2324 |
|
2323 | 2325 | assert io.fetch_output() == "\n".join(expected) + "\n" |
| 2326 | + |
| 2327 | + |
| 2328 | +def test_exporter_respects_package_sources(tmp_dir: str, poetry: Poetry) -> None: |
| 2329 | + poetry.locker.mock_lock_data( # type: ignore[attr-defined] |
| 2330 | + { |
| 2331 | + "package": [ |
| 2332 | + { |
| 2333 | + "name": "foo", |
| 2334 | + "python-versions": ">=3.6", |
| 2335 | + "version": "1.0.0", |
| 2336 | + "category": "main", |
| 2337 | + "optional": False, |
| 2338 | + "dependencies": {}, |
| 2339 | + "source": { |
| 2340 | + "type": "url", |
| 2341 | + "url": "https://example.com/foo-darwin.whl", |
| 2342 | + }, |
| 2343 | + }, |
| 2344 | + { |
| 2345 | + "name": "foo", |
| 2346 | + "python-versions": ">=3.6", |
| 2347 | + "version": "1.0.0", |
| 2348 | + "category": "main", |
| 2349 | + "optional": False, |
| 2350 | + "dependencies": {}, |
| 2351 | + "source": { |
| 2352 | + "type": "url", |
| 2353 | + "url": "https://example.com/foo-linux.whl", |
| 2354 | + }, |
| 2355 | + }, |
| 2356 | + ], |
| 2357 | + "metadata": { |
| 2358 | + "lock-version": "1.1", |
| 2359 | + "python-versions": "^3.6", |
| 2360 | + "content-hash": ( |
| 2361 | + "832b13a88e5020c27cbcd95faa577bf0dbf054a65c023b45dc9442b640d414e6" |
| 2362 | + ), |
| 2363 | + "hashes": { |
| 2364 | + "foo": [], |
| 2365 | + }, |
| 2366 | + }, |
| 2367 | + } |
| 2368 | + ) |
| 2369 | + root = poetry.package.with_dependency_groups([], only=True) |
| 2370 | + root.python_versions = "^3.6" |
| 2371 | + root.add_dependency( |
| 2372 | + Factory.create_dependency( |
| 2373 | + name="foo", |
| 2374 | + constraint={ |
| 2375 | + "url": "https://example.com/foo-linux.whl", |
| 2376 | + "platform": "linux", |
| 2377 | + }, |
| 2378 | + ) |
| 2379 | + ) |
| 2380 | + root.add_dependency( |
| 2381 | + Factory.create_dependency( |
| 2382 | + name="foo", |
| 2383 | + constraint={ |
| 2384 | + "url": "https://example.com/foo-darwin.whl", |
| 2385 | + "platform": "darwin", |
| 2386 | + }, |
| 2387 | + ) |
| 2388 | + ) |
| 2389 | + poetry._package = root |
| 2390 | + |
| 2391 | + io = BufferedIO() |
| 2392 | + exporter = Exporter(poetry) |
| 2393 | + exporter.export("requirements.txt", Path(tmp_dir), io) |
| 2394 | + |
| 2395 | + expected = f"""\ |
| 2396 | +foo @ https://example.com/foo-darwin.whl ; {MARKER_PY36} and {MARKER_DARWIN} |
| 2397 | +foo @ https://example.com/foo-linux.whl ; {MARKER_PY36} and {MARKER_LINUX} |
| 2398 | +""" |
| 2399 | + |
| 2400 | + assert io.fetch_output() == expected |
0 commit comments