blob: ee9a51e8442fa5835ca1dbb6907347ca23107c0a [file] [log] [blame]
Louis Verhaard7db78962020-05-25 15:05:26 +02001# Copyright (C) 2020 Arm Limited or its affiliates. All rights reserved.
2#
3# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the License); you may
6# not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an AS IS BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16# Description:
17# Unit tests for model_reader.
18import pytest
19from ethosu.vela import model_reader
20from ethosu.vela.errors import InputFileError
21
22
23def test_read_model_incorrect_extension(tmpdir):
24 # Tests read_model with a file name that does not end with .tflite
25 with pytest.raises(InputFileError):
26 model_reader.read_model("no_tflite_file.txt", model_reader.ModelReaderOptions())
27
28
29def test_read_model_corrupt_contents(tmpdir):
30 # Tests read_model with a corrupt .tflite file
31 fname = tmpdir.join("corrupt.tflite")
32 fname.write("abcde1234")
33 with pytest.raises(InputFileError):
34 model_reader.read_model(fname.strpath, model_reader.ModelReaderOptions())
35
36
37def test_read_model_file_not_found(tmpdir):
38 # Tests read_model with a .tflite file that does not exist
39 with pytest.raises(InputFileError):
40 model_reader.read_model("non_existing.tflite", model_reader.ModelReaderOptions())