aboutsummaryrefslogtreecommitdiff
path: root/tests/test_target_tosa_reporters.py
diff options
context:
space:
mode:
authorRuomei Yan <ruomei.yan@arm.com>2022-12-13 22:02:21 +0000
committerRuomei Yan <ruomei.yan@arm.com>2023-01-16 16:31:23 +0000
commit4eb3fef8e5876c69dc6bac70fdc010805d5b97f2 (patch)
tree88beca8a30954f020b7f34c0a3f9df780b966244 /tests/test_target_tosa_reporters.py
parent5800fc990ed1e36ce7d06670f911fbb12a0ec771 (diff)
downloadmlia-4eb3fef8e5876c69dc6bac70fdc010805d5b97f2.tar.gz
MLIA-741/2 Report test results
- add version extraction function in compat.py - create Metadata, MLIAMetadata, TOSAMetadata and MetadataDisplay classes - update the reporting functions so tosa and mlia version will be displayed in output json - update unit test test_configure_and_get_tosa_advisor to mock the get_events function - update the copyright information of all changed/added files - handle exception and report to json when program crashes - write new context managers for capturing stderr and stdout - support reporting stderr to json output - support reporting model checksum and model name to json output - made changes in test_e2e.py handling {model_name} replacement in --output - add unit tests Change-Id: I6629fd1c5754378e6accd488217c83d87c7eb6f1
Diffstat (limited to 'tests/test_target_tosa_reporters.py')
-rw-r--r--tests/test_target_tosa_reporters.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/test_target_tosa_reporters.py b/tests/test_target_tosa_reporters.py
new file mode 100644
index 0000000..59da270
--- /dev/null
+++ b/tests/test_target_tosa_reporters.py
@@ -0,0 +1,52 @@
+# SPDX-FileCopyrightText: Copyright 2023, Arm Limited and/or its affiliates.
+# SPDX-License-Identifier: Apache-2.0
+"""Tests for tosa-checker reporters."""
+from pathlib import Path
+from unittest.mock import MagicMock
+
+import pytest
+
+from mlia.core.metadata import MLIAMetadata
+from mlia.core.metadata import ModelMetadata
+from mlia.core.reporting import Report
+from mlia.target.tosa.config import TOSAConfiguration
+from mlia.target.tosa.metadata import TOSAMetadata
+from mlia.target.tosa.reporters import MetadataDisplay
+from mlia.target.tosa.reporters import report_device
+from mlia.target.tosa.reporters import tosa_formatters
+
+
+def test_tosa_report_device() -> None:
+ """Test function report_device()."""
+ report = report_device(TOSAConfiguration("tosa"))
+ assert report.to_plain_text()
+
+
+def test_tosa_formatters(
+ monkeypatch: pytest.MonkeyPatch, test_tflite_model: Path
+) -> None:
+ """Test function tosa_formatters() with valid input."""
+ mock_version = MagicMock()
+ monkeypatch.setattr(
+ "mlia.core.metadata.get_pkg_version",
+ MagicMock(return_value=mock_version),
+ )
+
+ data = MetadataDisplay(
+ TOSAMetadata("tosa-checker"),
+ MLIAMetadata("mlia"),
+ ModelMetadata(test_tflite_model),
+ )
+ formatter = tosa_formatters(data)
+ report = formatter(data)
+ assert data.tosa_version == mock_version
+ assert isinstance(report, Report)
+
+
+def test_tosa_formatters_invalid_data() -> None:
+ """Test tosa_formatters() with invalid input."""
+ with pytest.raises(
+ Exception,
+ match=r"^Unable to find appropriate formatter for .*",
+ ):
+ tosa_formatters(12)