|
| 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