|
| 1 | +# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +"""Test Core commands""" |
| 4 | + |
| 5 | +import pytest |
| 6 | +import vcr |
| 7 | + |
| 8 | +from idf_component_manager.core import ComponentManager |
| 9 | +from idf_component_tools.constants import MANIFEST_FILENAME |
| 10 | +from idf_component_tools.errors import FatalError |
| 11 | +from idf_component_tools.manager import ManifestManager |
| 12 | + |
| 13 | + |
| 14 | +@vcr.use_cassette('tests/fixtures/vcr_cassettes/test_init_project.yaml') |
| 15 | +def test_init_project(mock_registry, tmp_path): |
| 16 | + (tmp_path / 'main').mkdir() |
| 17 | + (tmp_path / 'components' / 'foo').mkdir(parents=True) |
| 18 | + main_manifest_path = tmp_path / 'main' / MANIFEST_FILENAME |
| 19 | + foo_manifest_path = tmp_path / 'components' / 'foo' / MANIFEST_FILENAME |
| 20 | + |
| 21 | + manager = ComponentManager(path=str(tmp_path)) |
| 22 | + manager.create_manifest() |
| 23 | + manager.create_manifest(component='foo') |
| 24 | + |
| 25 | + for filepath in [main_manifest_path, foo_manifest_path]: |
| 26 | + assert filepath.read_text().startswith('## IDF Component Manager') |
| 27 | + |
| 28 | + manager.add_dependency('cmp==4.0.3') |
| 29 | + manifest_manager = ManifestManager(str(main_manifest_path), 'main') |
| 30 | + assert manifest_manager.manifest_tree['dependencies']['espressif/cmp'] == '==4.0.3' |
| 31 | + |
| 32 | + manager.add_dependency('espressif/cmp==4.0.3', component='foo') |
| 33 | + manifest_manager = ManifestManager(str(foo_manifest_path), 'foo') |
| 34 | + assert manifest_manager.manifest_tree['dependencies']['espressif/cmp'] == '==4.0.3' |
| 35 | + |
| 36 | + |
| 37 | +@vcr.use_cassette('tests/fixtures/vcr_cassettes/test_init_project_with_path.yaml') |
| 38 | +def test_init_project_with_path(mock_registry, tmp_path): |
| 39 | + src_path = tmp_path / 'src' |
| 40 | + src_path.mkdir(parents=True, exist_ok=True) |
| 41 | + src_manifest_path = src_path / MANIFEST_FILENAME |
| 42 | + |
| 43 | + outside_project_path = tmp_path.parent |
| 44 | + outside_project_path_error_match = 'Directory ".*" is not under project directory!' |
| 45 | + component_and_path_error_match = 'Cannot determine manifest directory.' |
| 46 | + |
| 47 | + manager = ComponentManager(path=str(tmp_path)) |
| 48 | + manager.create_manifest(path=str(src_path)) |
| 49 | + |
| 50 | + with pytest.raises(FatalError, match=outside_project_path_error_match): |
| 51 | + manager.create_manifest(path=str(outside_project_path)) |
| 52 | + |
| 53 | + with pytest.raises(FatalError, match=component_and_path_error_match): |
| 54 | + manager.create_manifest(component='src', path=str(src_path)) |
| 55 | + |
| 56 | + manager.add_dependency('espressif/cmp==4.0.3', path=str(src_path)) |
| 57 | + manifest_manager = ManifestManager(str(src_manifest_path), 'src') |
| 58 | + |
| 59 | + assert manifest_manager.manifest_tree['dependencies']['espressif/cmp'] == '==4.0.3' |
| 60 | + |
| 61 | + with pytest.raises(FatalError, match=outside_project_path_error_match): |
| 62 | + manager.create_manifest(path=str(outside_project_path)) |
| 63 | + |
| 64 | + with pytest.raises(FatalError, match=component_and_path_error_match): |
| 65 | + manager.add_dependency('espressif/cmp==4.0.3', component='src', path=str(src_path)) |
0 commit comments