Skip to content

Commit 6ed70d2

Browse files
committed
add unit test for an example
Signed-off-by: xavier dupré <[email protected]>
1 parent 0ea9a15 commit 6ed70d2

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/test_example.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT license.
3+
4+
"""Test examples."""
5+
6+
import os
7+
import subprocess
8+
import unittest
9+
from common import check_opset_min_version, check_opset_max_version
10+
11+
12+
class TestExample(unittest.TestCase):
13+
"""test examples"""
14+
15+
def run_example(self, name, expected=None):
16+
full = os.path.join(
17+
os.path.abspath(os.path.dirname(__file__)),
18+
"..", "examples", name)
19+
if not os.path.exists(full):
20+
raise FileNotFoundError(full)
21+
proc = subprocess.run(('python %s' % full).split(),
22+
capture_output=True)
23+
self.assertEqual(0, proc.returncode)
24+
if expected is not None:
25+
out = proc.stdout.decode('ascii')
26+
for exp in expected:
27+
self.assertIn(exp, out)
28+
err = proc.stderr.decode('ascii')
29+
self.assertTrue(err is not None)
30+
31+
@check_tf_min_version("2.1", "use tf.keras")
32+
@check_opset_min_version(12)
33+
@check_opset_max_version(13)
34+
def test_end2end_tfkeras(self):
35+
self.run_example(
36+
"end2end_tfkeras.py",
37+
expected=["ONNX model is saved at simple_rnn.onnx",
38+
"Optimizing ONNX model",
39+
"Using opset <onnx, 12>"])
40+
41+
42+
if __name__ == '__main__':
43+
unittest.main()

0 commit comments

Comments
 (0)