summaryrefslogtreecommitdiff
path: root/zephyr/zmake/tests/conftest.py
blob: 38e34bef56bc54601b002d7affe2ce0a9e3337f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Copyright 2021 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Common settings and fixtures for all tests."""

import os
import pathlib

import hypothesis
import pytest

import zmake.zmake as zm

hypothesis.settings.register_profile(
    "cq", suppress_health_check=hypothesis.HealthCheck.all()
)

# pylint: disable=redefined-outer-name,unused-argument


@pytest.fixture
def zmake_factory_from_dir(tmp_path):
    """Creates module dirs and returns a Zmake object factory."""

    os.mkdir(tmp_path / "ec")
    os.mkdir(tmp_path / "ec" / "zephyr")
    (tmp_path / "ec" / "zephyr" / "module.yml").write_text("")
    zephyr_base = tmp_path / "zephyr_base"

    def _zmake_factory(**kwargs):
        return zm.Zmake(zephyr_base=zephyr_base, modules_dir=tmp_path, **kwargs)

    return _zmake_factory


@pytest.fixture
def zmake_from_dir(zmake_factory_from_dir):
    """Creates module dirs and returns a Zmake object."""
    return zmake_factory_from_dir()


@pytest.fixture
def fake_checkout(tmp_path):
    """Creates a fake checkout dir and returns the path to zmake."""

    actual_zmake_src_path = pathlib.Path(__file__).parent.parent
    fake_zmake_path = pathlib.Path(tmp_path) / "src/platform/ec/zephyr/zmake"
    os.makedirs(fake_zmake_path.parent)
    os.symlink(actual_zmake_src_path, fake_zmake_path)
    return fake_zmake_path


@pytest.fixture
def zmake_from_checkout(tmp_path, fake_checkout):
    """Creates a fake checkout dir and returns a Zmake object."""

    return zm.Zmake(checkout=tmp_path)