Caffe2 - Python API
A deep learning, cross platform ML framework
test_utils.py
1 ## @package onnx
2 # Module caffe2.python.onnx.tests.test_utils
3 
4 from __future__ import absolute_import
5 from __future__ import division
6 from __future__ import print_function
7 from __future__ import unicode_literals
8 
9 import unittest
10 
11 import numpy as np
12 
13 
14 class TestCase(unittest.TestCase):
15  def setUp(self):
16  np.random.seed(seed=0)
17 
18  def assertSameOutputs(self, outputs1, outputs2, decimal=7):
19  self.assertEqual(len(outputs1), len(outputs2))
20  for o1, o2 in zip(outputs1, outputs2):
21  np.testing.assert_almost_equal(o1, o2, decimal=decimal)
22 
23  def add_test_case(name, test_func):
24  if not name.startswith('test_'):
25  raise ValueError('Test name must start with test_: {}'.format(name))
26  if hasattr(self, name):
27  raise ValueError('Duplicated test name: {}'.format(name))
28  setattr(self, name, test_func)