aboutsummaryrefslogtreecommitdiff
path: root/python/pytests/conftest.py
diff options
context:
space:
mode:
authorKaushik Varadharajan <kaushik.varadharajan@arm.com>2024-06-14 00:05:37 +0000
committerKaushik Varadharajan <kaushik.varadharajan@arm.com>2024-06-18 21:52:26 +0000
commit6e13113b5d1a1d8afe00c8a577a014db7df5b0a4 (patch)
tree5bcd4b2e917bd49fb00e77bf62b1ba4a6e05835a /python/pytests/conftest.py
parent895822576f97ca9470709378e7ff122ccbea5d00 (diff)
downloadserialization_lib-6e13113b5d1a1d8afe00c8a577a014db7df5b0a4.tar.gz
Add Pytest unit tests for serialization library
Tests run with `pytest` command in repository's root directory. Signed-off-by: Kaushik Varadharajan <kaushik.varadharajan@arm.com> Change-Id: I9d8a13b233ffafc9119ef503d46f7808461a194f
Diffstat (limited to 'python/pytests/conftest.py')
-rw-r--r--python/pytests/conftest.py51
1 files changed, 45 insertions, 6 deletions
diff --git a/python/pytests/conftest.py b/python/pytests/conftest.py
index b595a01..1cb0857 100644
--- a/python/pytests/conftest.py
+++ b/python/pytests/conftest.py
@@ -16,6 +16,8 @@
import pathlib
import shutil
+import subprocess
+import pytest
def pytest_sessionstart():
@@ -24,13 +26,50 @@ def pytest_sessionstart():
base_dir = (pathlib.Path(__file__).parent / "../..").resolve()
tmp_dir = base_dir / "python/pytests/tmp"
- tmp_dir.mkdir(exist_ok=True)
+ if tmp_dir.exists():
+ shutil.rmtree(tmp_dir)
+ tmp_dir.mkdir()
+ # Using flatc and flatbuffers' reflection feature to convert tosa.fbs to
+ # json for easier reading
+ flatbuffers_dir = base_dir / "third_party/flatbuffers"
+ flatc = flatbuffers_dir / "flatc"
+ reflection_fbs = flatbuffers_dir / "reflection/reflection.fbs"
+ tosa_fbs = base_dir / "schema/tosa.fbs"
-def pytest_sessionfinish():
- """Cleaning up temporary files."""
+ # Using flatbuffers reflection to serialize the TOSA flatbuffers schema
+ # into binary
+ _ = subprocess.run(
+ [flatc, "--binary", "--schema", "-o", tmp_dir, tosa_fbs], check=True
+ )
- base_dir = (pathlib.Path(__file__).parent / "../..").resolve()
- tmp_dir = base_dir / "python/pytests/tmp"
+ # This file is generated by the previous command
+ tosa_bfbs = tmp_dir / "tosa.bfbs"
+
+ # Deserializing the binary into JSON using the reflection schema
+ _ = subprocess.run(
+ [
+ flatc,
+ "--json",
+ "--strict-json",
+ "-o",
+ tmp_dir,
+ reflection_fbs,
+ "--",
+ tosa_bfbs,
+ ],
+ check=True,
+ )
+
+
+def pytest_addoption(parser: pytest.Parser):
+ parser.addoption("--leave-tmp", dest="leave_tmp", action="store_true")
+
+
+def pytest_sessionfinish(session: pytest.Session):
+ """Cleaning up temporary files, unless the --leave-tmp flag is set"""
- shutil.rmtree(tmp_dir)
+ if not session.config.option.leave_tmp:
+ base_dir = (pathlib.Path(__file__).parent / "../..").resolve()
+ tmp_dir = base_dir / "python/pytests/tmp"
+ shutil.rmtree(tmp_dir)