# 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 attr

from PB.recipe_modules.pigweed.environment.tests.full import InputProperties

DEPS = [
    'pigweed/environment',
    'recipe_engine/path',
    'recipe_engine/platform',
    'recipe_engine/properties',
]

PROPERTIES = InputProperties


@attr.s
class _FakeCheckoutContext:
    root = attr.ib()
    changes_json = attr.ib(default=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')
        + api.environment.logs()
    )

    yield (
        api.test('doctor-fail')
        + api.environment.properties(skip_submodule_check=True)
        + api.platform.name('linux')
        + api.environment.logs()
        + 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')
        + api.environment.logs()
    )

    yield (
        api.test('override-cas')
        + api.environment.properties(skip_submodule_check=True)
        + api.environment.override_clang(source='isolated', version='123456')
        + api.environment.logs()
    )

    yield api.test('empty')
