| # Copyright 2020 The Pigweed Authors |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| # use this file except in compliance with the License. You may obtain a copy of |
| # the License at |
| # |
| # https://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| # License for the specific language governing permissions and limitations under |
| # the License. |
| from __future__ import annotations |
| |
| from collections.abc import Iterator |
| |
| from recipe_engine import recipe_api, recipe_test_api |
| |
| DEPS = [ |
| 'pigweed/repo', |
| 'recipe_engine/assertions', |
| 'recipe_engine/context', |
| 'recipe_engine/file', |
| 'recipe_engine/path', |
| ] |
| |
| |
| def RunSteps(api: recipe_api.RecipeScriptApi): |
| cwd = api.path.cleanup_dir |
| |
| with api.context(cwd=cwd): |
| # diff_manifests_informational calls _find_root(). Use that to cover |
| # both cases in one test. |
| api.repo.diff_manifests_informational( |
| cwd / 'manifest-internal/snapshot-a.xml', |
| cwd / 'manifest-internal/snapshot-b.xml', |
| ) |
| |
| # Next, call _find_root from a subdirectory. Should not affect |
| # context.cwd. |
| cwd = api.path.cleanup_dir / 'test' / 'dir' / 'sub' |
| api.file.ensure_directory('test dir', cwd) |
| expected = str(cwd) |
| api.path.mock_add_paths(api.path.cleanup_dir / 'test' / '.repo') |
| with api.context(cwd=cwd): |
| api.repo._find_root() # pylint: disable=protected-access |
| api.assertions.assertEqual(expected, str(api.context.cwd)) |
| |
| |
| def GenTests(api) -> Iterator[recipe_test_api.TestData]: |
| yield api.test('tests') |