conftest.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env python3
  2. # type: ignore[attr-defined]
  3. #
  4. # Copyright (c) 2024, Arm Limited. All rights reserved.
  5. #
  6. # SPDX-License-Identifier: BSD-3-Clause
  7. #
  8. """ Common configurations and fixtures for test environment."""
  9. import pytest
  10. import yaml
  11. from click.testing import CliRunner
  12. from tlc.cli import cli
  13. @pytest.fixture
  14. def tmptlstr(tmpdir):
  15. return tmpdir.join("tl.bin").strpath
  16. @pytest.fixture
  17. def tmpyamlconfig(tmpdir):
  18. return tmpdir.join("config.yaml").strpath
  19. @pytest.fixture
  20. def tmpfdt(tmpdir):
  21. fdt = tmpdir.join("fdt.dtb")
  22. fdt.write_binary(b"\x00" * 100)
  23. return fdt
  24. @pytest.fixture(params=[1, 2, 3, 4, 5, 0x100, 0x101, 0x102, 0x104])
  25. def non_empty_tag_id(request):
  26. return request.param
  27. @pytest.fixture
  28. def tmpyamlconfig_blob_file(tmpdir, tmpfdt, non_empty_tag_id):
  29. config_path = tmpdir.join("config.yaml")
  30. config = {
  31. "has_checksum": True,
  32. "max_size": 0x1000,
  33. "entries": [
  34. {
  35. "tag_id": non_empty_tag_id,
  36. "blob_file_path": tmpfdt.strpath,
  37. },
  38. ],
  39. }
  40. with open(config_path, "w") as f:
  41. yaml.safe_dump(config, f)
  42. return config_path
  43. @pytest.fixture
  44. def tlcrunner(tmptlstr):
  45. runner = CliRunner()
  46. with runner.isolated_filesystem():
  47. runner.invoke(cli, ["create", tmptlstr])
  48. return runner
  49. @pytest.fixture
  50. def tlc_entries(tmpfdt):
  51. return [(0, "/dev/null"), (1, tmpfdt.strpath), (0x102, tmpfdt.strpath)]