|
3 | 3 | """ |
4 | 4 |
|
5 | 5 | import json |
| 6 | +import copy |
6 | 7 | from test.conftest import ApioRunner |
7 | 8 | from apio.profile import Profile |
| 9 | +from apio.utils import util |
| 10 | + |
8 | 11 |
|
9 | 12 | TEST_DATA = { |
10 | 13 | "installed-packages": { |
11 | | - "examples": {"version": "0.1.4"}, |
12 | | - "verible": {"version": "0.0.1"}, |
| 14 | + "drivers": {"version": "2025.06.13"}, |
| 15 | + "examples": {"version": "2025.06.21"}, |
13 | 16 | }, |
14 | 17 | "preferences": {"theme": "light"}, |
15 | 18 | "remote-config": { |
| 19 | + "metadata": { |
| 20 | + "loaded-at": "2025-06-29-07-18", |
| 21 | + "loaded-by": util.get_apio_version(), |
| 22 | + "loaded-from": ( |
| 23 | + "https://github.com/FPGAwars/apio/raw/develop/" |
| 24 | + "remote-config/apio-0.9.7.jsonc" |
| 25 | + ), |
| 26 | + }, |
16 | 27 | "packages": { |
17 | | - "drivers": {"version": "1.2.0"}, |
18 | | - "examples": {"version": "0.1.4"}, |
19 | | - } |
| 28 | + "drivers": { |
| 29 | + "release": { |
| 30 | + "package-file": "apio-drivers-${PLATFORM}-${YYYYMMDD}.tgz", |
| 31 | + "release-tag": "${YYYY-MM-DD}", |
| 32 | + "version": "2025.06.13", |
| 33 | + }, |
| 34 | + "repository": { |
| 35 | + "name": "tools-drivers", |
| 36 | + "organization": "FPGAwars", |
| 37 | + }, |
| 38 | + }, |
| 39 | + "examples": { |
| 40 | + "release": { |
| 41 | + "package-file": "apio-examples-${YYYYMMDD}.tgz", |
| 42 | + "release-tag": "${YYYY-MM-DD}", |
| 43 | + "version": "2025.06.21", |
| 44 | + }, |
| 45 | + "repository": { |
| 46 | + "name": "apio-examples", |
| 47 | + "organization": "FPGAwars", |
| 48 | + }, |
| 49 | + }, |
| 50 | + }, |
20 | 51 | }, |
21 | 52 | } |
22 | 53 |
|
23 | 54 |
|
24 | | -def test_profile_loading(apio_runner: ApioRunner): |
| 55 | +def test_profile_loading_config_ok(apio_runner: ApioRunner): |
25 | 56 | """Tests the loading and validation of a profile file.""" |
26 | 57 |
|
27 | 58 | with apio_runner.in_sandbox() as sb: |
28 | 59 |
|
29 | 60 | # -- Write a test profile.json file. |
30 | 61 | path = sb.home_dir / "profile.json" |
31 | | - sb.write_file(path, json.dumps(TEST_DATA, indent=2)) |
| 62 | + test_data = copy.deepcopy(TEST_DATA) |
| 63 | + sb.write_file( |
| 64 | + path, |
| 65 | + json.dumps( |
| 66 | + test_data, |
| 67 | + indent=2, |
| 68 | + ), |
| 69 | + ) |
| 70 | + |
| 71 | + # -- Read back the content. |
| 72 | + profile = Profile(sb.home_dir, "http://fake-domain.com/config") |
| 73 | + |
| 74 | + # -- Verify |
| 75 | + assert profile.preferences == test_data["preferences"] |
| 76 | + assert profile.packages == test_data["installed-packages"] |
| 77 | + assert profile.remote_config == test_data["remote-config"] |
| 78 | + assert not profile.remote_config_fetched |
| 79 | + |
| 80 | + |
| 81 | +def test_profile_loading_config_stale(apio_runner: ApioRunner): |
| 82 | + """Tests the loading and validation of a profile file.""" |
| 83 | + |
| 84 | + with apio_runner.in_sandbox() as sb: |
| 85 | + |
| 86 | + # -- Write a test profile.json file. We set an old apio version |
| 87 | + # -- to cause the cached remote config to be classified as stale. |
| 88 | + path = sb.home_dir / "profile.json" |
| 89 | + test_data = copy.deepcopy(TEST_DATA) |
| 90 | + test_data["remote-config"]["metadata"]["loaded-by"] = "0.9.6" |
| 91 | + sb.write_file( |
| 92 | + path, |
| 93 | + json.dumps( |
| 94 | + test_data, |
| 95 | + indent=2, |
| 96 | + ), |
| 97 | + ) |
32 | 98 |
|
33 | 99 | # -- Read back the content. |
34 | 100 | profile = Profile(sb.home_dir, "http://fake-domain.com/config") |
35 | 101 |
|
36 | 102 | # -- Verify |
37 | | - assert profile.preferences == TEST_DATA["preferences"] |
38 | | - assert profile.packages == TEST_DATA["installed-packages"] |
39 | | - assert profile.remote_config == TEST_DATA["remote-config"] |
| 103 | + assert profile.preferences == test_data["preferences"] |
| 104 | + assert profile.packages == test_data["installed-packages"] |
| 105 | + assert profile.remote_config == {} # Config rejected |
40 | 106 | assert not profile.remote_config_fetched |
0 commit comments