From 78703ddefbbf93dda8ecb173f14086880bb9f82f Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Wed, 8 Jul 2015 17:47:12 +0200 Subject: [PATCH] BaseObjectTestCase: rename test_class into _test_class It seems that testtools are trying to load that class as if it's a test case (for it considers everything inside a test class named as test_* as a test case). Change-Id: Ic4342cc0637d659191f084467ccdb9c90e89a023 --- neutron/tests/unit/objects/qos/test_policy.py | 2 +- neutron/tests/unit/objects/qos/test_rule.py | 20 +++++------ neutron/tests/unit/objects/test_base.py | 34 +++++++++---------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/neutron/tests/unit/objects/qos/test_policy.py b/neutron/tests/unit/objects/qos/test_policy.py index 5b7d79076..8997482df 100644 --- a/neutron/tests/unit/objects/qos/test_policy.py +++ b/neutron/tests/unit/objects/qos/test_policy.py @@ -16,4 +16,4 @@ from neutron.tests.unit.objects import test_base class QosPolicyObjectTestCase(test_base.BaseObjectTestCase): - test_class = policy.QosPolicy + _test_class = policy.QosPolicy diff --git a/neutron/tests/unit/objects/qos/test_rule.py b/neutron/tests/unit/objects/qos/test_rule.py index dc0ca200d..e7656e871 100644 --- a/neutron/tests/unit/objects/qos/test_rule.py +++ b/neutron/tests/unit/objects/qos/test_rule.py @@ -19,27 +19,27 @@ from neutron.tests.unit.objects import test_base class QosBandwidthLimitPolicyObjectTestCase(test_base.BaseObjectTestCase): - test_class = rule.QosBandwidthLimitRule + _test_class = rule.QosBandwidthLimitRule def _filter_db_object(self, func): return { field: self.db_obj[field] - for field in self.test_class.fields + for field in self._test_class.fields if func(field) } def _get_core_db_obj(self): return self._filter_db_object( - lambda field: self.test_class._is_core_field(field)) + lambda field: self._test_class._is_core_field(field)) def _get_addn_db_obj(self): return self._filter_db_object( - lambda field: self.test_class._is_addn_field(field)) + lambda field: self._test_class._is_addn_field(field)) def test_create(self): with mock.patch.object(db_api, 'create_object', return_value=self.db_obj) as create_mock: - test_class = self.test_class + test_class = self._test_class obj = test_class(self.context, **self.db_obj) self._check_equal(obj, self.db_obj) obj.create() @@ -47,27 +47,27 @@ class QosBandwidthLimitPolicyObjectTestCase(test_base.BaseObjectTestCase): core_db_obj = self._get_core_db_obj() create_mock.assert_any_call( - self.context, self.test_class.base_db_model, core_db_obj) + self.context, self._test_class.base_db_model, core_db_obj) addn_db_obj = self._get_addn_db_obj() create_mock.assert_any_call( - self.context, self.test_class.db_model, + self.context, self._test_class.db_model, addn_db_obj) def test_update_changes(self): with mock.patch.object(db_api, 'update_object', return_value=self.db_obj) as update_mock: - obj = self.test_class(self.context, **self.db_obj) + obj = self._test_class(self.context, **self.db_obj) self._check_equal(obj, self.db_obj) obj.update() self._check_equal(obj, self.db_obj) core_db_obj = self._get_core_db_obj() update_mock.assert_any_call( - self.context, self.test_class.base_db_model, obj.id, + self.context, self._test_class.base_db_model, obj.id, core_db_obj) addn_db_obj = self._get_addn_db_obj() update_mock.assert_any_call( - self.context, self.test_class.db_model, obj.id, + self.context, self._test_class.db_model, obj.id, addn_db_obj) diff --git a/neutron/tests/unit/objects/test_base.py b/neutron/tests/unit/objects/test_base.py index 5738e8ba1..f0378cff1 100644 --- a/neutron/tests/unit/objects/test_base.py +++ b/neutron/tests/unit/objects/test_base.py @@ -61,7 +61,7 @@ def get_obj_fields(obj): class BaseObjectTestCase(test_base.BaseTestCase): - test_class = FakeNeutronObject + _test_class = FakeNeutronObject def setUp(self): super(BaseObjectTestCase, self).setUp() @@ -72,35 +72,35 @@ class BaseObjectTestCase(test_base.BaseTestCase): @classmethod def _get_random_fields(cls): fields = {} - for field in cls.test_class.fields: - field_obj = cls.test_class.fields[field] + for field in cls._test_class.fields: + field_obj = cls._test_class.fields[field] fields[field] = FIELD_TYPE_VALUE_GENERATOR_MAP[type(field_obj)]() return fields @classmethod def _is_test_class(cls, obj): - return isinstance(obj, cls.test_class) + return isinstance(obj, cls._test_class) def test_get_by_id(self): with mock.patch.object(db_api, 'get_object', return_value=self.db_obj) as get_object_mock: - obj = self.test_class.get_by_id(self.context, id='fake_id') + obj = self._test_class.get_by_id(self.context, id='fake_id') self.assertTrue(self._is_test_class(obj)) self.assertEqual(self.db_obj, get_obj_fields(obj)) get_object_mock.assert_called_once_with( - self.context, self.test_class.db_model, 'fake_id') + self.context, self._test_class.db_model, 'fake_id') def test_get_objects(self): with mock.patch.object(db_api, 'get_objects', return_value=self.db_objs) as get_objects_mock: - objs = self.test_class.get_objects(self.context) + objs = self._test_class.get_objects(self.context) self.assertFalse( filter(lambda obj: not self._is_test_class(obj), objs)) self.assertEqual( sorted(self.db_objs), sorted(get_obj_fields(obj) for obj in objs)) get_objects_mock.assert_called_once_with( - self.context, self.test_class.db_model) + self.context, self._test_class.db_model) def _check_equal(self, obj, db_obj): self.assertEqual( @@ -110,17 +110,17 @@ class BaseObjectTestCase(test_base.BaseTestCase): def test_create(self): with mock.patch.object(db_api, 'create_object', return_value=self.db_obj) as create_mock: - obj = self.test_class(self.context, **self.db_obj) + obj = self._test_class(self.context, **self.db_obj) self._check_equal(obj, self.db_obj) obj.create() self._check_equal(obj, self.db_obj) create_mock.assert_called_once_with( - self.context, self.test_class.db_model, self.db_obj) + self.context, self._test_class.db_model, self.db_obj) def test_create_updates_from_db_object(self): with mock.patch.object(db_api, 'create_object', return_value=self.db_obj): - obj = self.test_class(self.context, **self.db_objs[1]) + obj = self._test_class(self.context, **self.db_objs[1]) self._check_equal(obj, self.db_objs[1]) obj.create() self._check_equal(obj, self.db_obj) @@ -128,7 +128,7 @@ class BaseObjectTestCase(test_base.BaseTestCase): def test_update_no_changes(self): with mock.patch.object(db_api, 'update_object', return_value=self.db_obj) as update_mock: - obj = self.test_class(self.context, **self.db_obj) + obj = self._test_class(self.context, **self.db_obj) self._check_equal(obj, self.db_obj) obj.update() self.assertTrue(update_mock.called) @@ -142,27 +142,27 @@ class BaseObjectTestCase(test_base.BaseTestCase): def test_update_changes(self): with mock.patch.object(db_api, 'update_object', return_value=self.db_obj) as update_mock: - obj = self.test_class(self.context, **self.db_obj) + obj = self._test_class(self.context, **self.db_obj) self._check_equal(obj, self.db_obj) obj.update() self._check_equal(obj, self.db_obj) update_mock.assert_called_once_with( - self.context, self.test_class.db_model, + self.context, self._test_class.db_model, self.db_obj['id'], self.db_obj) def test_update_updates_from_db_object(self): with mock.patch.object(db_api, 'update_object', return_value=self.db_obj): - obj = self.test_class(self.context, **self.db_objs[1]) + obj = self._test_class(self.context, **self.db_objs[1]) self._check_equal(obj, self.db_objs[1]) obj.update() self._check_equal(obj, self.db_obj) @mock.patch.object(db_api, 'delete_object') def test_delete(self, delete_mock): - obj = self.test_class(self.context, **self.db_obj) + obj = self._test_class(self.context, **self.db_obj) self._check_equal(obj, self.db_obj) obj.delete() self._check_equal(obj, self.db_obj) delete_mock.assert_called_once_with( - self.context, self.test_class.db_model, self.db_obj['id']) + self.context, self._test_class.db_model, self.db_obj['id']) -- 2.45.2