|
3 | 3 |
|
4 | 4 | from unittest.mock import patch |
5 | 5 | from typing import Any |
| 6 | +import subprocess |
| 7 | +import textwrap |
6 | 8 |
|
7 | 9 | import update_device_metadata |
8 | 10 | import update_device_dirs |
9 | 11 |
|
10 | 12 |
|
11 | 13 | def test_fetch_metadata(tmp_path: Any) -> None: |
12 | 14 | lineage_build_targets = tmp_path / "lineage-build-targets" |
13 | | - lineage_build_targets.write_text( |
14 | | - '''# Ignore comments |
| 15 | + lineage_build_targets.write_text(textwrap.dedent(''' |
| 16 | + # Ignore comments |
15 | 17 | crosshatch userdebug lineage-18.1 W |
16 | | - ''') |
| 18 | + ''')) |
17 | 19 |
|
18 | 20 | devices_json = tmp_path / "devices.json" |
19 | | - devices_json.write_text( |
20 | | - '''[ |
21 | | - { "model": "crosshatch", "oem": "Google", "name": "Pixel 3 XL", "lineage_recovery": true} |
| 21 | + devices_json.write_text(textwrap.dedent(''' |
| 22 | + [ |
| 23 | + { "model": "crosshatch", "oem": "Google", "name": "Pixel 3 XL", "lineage_recovery": true} |
22 | 24 | ] |
23 | | - ''') |
| 25 | + ''')) |
| 26 | + |
| 27 | + # nix-prefetch-git that is used underneath seems to require a real git repo |
| 28 | + subprocess.check_output(["git", "init", "--initial-branch=main"], cwd=tmp_path) |
| 29 | + subprocess.check_output(["git", "add", "-A"], cwd=tmp_path) |
| 30 | + subprocess.check_output(["git", "commit", "-am", "Initial commit"], cwd=tmp_path) |
24 | 31 |
|
25 | 32 | metadata = update_device_metadata.fetch_metadata( |
26 | | - f"file://{lineage_build_targets}", f"file://{devices_json}" |
| 33 | + f"file://{tmp_path}", |
| 34 | + "lineage-build-targets", |
| 35 | + "devices.json" |
27 | 36 | ) |
28 | 37 |
|
29 | 38 | assert metadata == { |
@@ -133,6 +142,8 @@ def test_fetch_vendor_dirs(ls_remote: Any, checkout_git: Any, tmpdir: Any) -> No |
133 | 142 | "vendor": "google" |
134 | 143 | }, |
135 | 144 | } |
136 | | - dirs = update_device_dirs.fetch_vendor_dirs(metadata, baseurl, 'lineage-18.1') |
| 145 | + dirs = update_device_dirs.fetch_vendor_dirs( |
| 146 | + metadata, baseurl, 'lineage-18.1', 'lineage-18.1', {} |
| 147 | + ) |
137 | 148 |
|
138 | 149 | assert 'vendor/google' in dirs |
0 commit comments