| # 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. |
| """Full test of environment module.""" |
| |
| import dataclasses |
| from typing import Optional |
| |
| from PB.recipe_modules.pigweed.environment.tests.full import InputProperties |
| from recipe_engine import config_types |
| |
| DEPS = [ |
| 'pigweed/environment', |
| 'recipe_engine/path', |
| 'recipe_engine/platform', |
| 'recipe_engine/properties', |
| ] |
| |
| PROPERTIES = InputProperties |
| |
| |
| @dataclasses.dataclass |
| class _FakeCheckoutContext: |
| root: config_types.Path |
| changes_json: Optional[config_types.Path] = None |
| |
| |
| def RunSteps(api, props): # pylint: disable=invalid-name |
| # pylint: disable=missing-function-docstring |
| env = api.environment.init( |
| checkout=_FakeCheckoutContext(api.path['start_dir']), |
| use_constraint_file=False, |
| options=props.environment_options, |
| ) |
| |
| # The next couple lines help cover all of api.py. |
| try: |
| # VIRTUAL_ENV is set in almost all cases, but not in the 'empty' test. |
| _ = env.VIRTUAL_ENV |
| _ = env.VARIABLE_NAME_UNLIKELY_TO_BE_USED_ELSEWHERE |
| except AttributeError: |
| pass |
| |
| with env(): |
| pass |
| |
| |
| def GenTests(api): # pylint: disable=invalid-name |
| yield ( |
| api.test('normal') |
| + api.environment.properties(skip_submodule_check=True) |
| + api.properties(**{'$recipe_engine/led': {'led_run_id': '123'}}) |
| + api.platform.name('mac') |
| ) |
| |
| yield ( |
| api.test('doctor-fail') |
| + api.environment.properties( |
| skip_submodule_check=True, additional_cipd_files=('override.json',), |
| ) |
| + api.platform.name('linux') |
| + api.step_data('environment.doctor', retcode=1) |
| ) |
| |
| yield ( |
| api.test('windows') |
| + api.environment.properties(additional_variables=dict(ABC=123)) |
| + api.platform.name('win') |
| ) |
| |
| yield ( |
| api.test('override-cipd') |
| + api.environment.properties(skip_submodule_check=True) |
| + api.environment.override_clang(source='cipd', version='latest') |
| ) |
| |
| yield ( |
| api.test('override-cas') |
| + api.environment.properties(skip_submodule_check=True) |
| + api.environment.override_clang(source='isolated', version='123456') |
| ) |
| |
| yield api.test('empty') |