X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Fbindings%2Fpython%2Fbt2%2Ftest_event_class.py;h=beab05cb95096febe7a95bd29692d9fa0c51c8c0;hb=d2d857a8c492de2cde82d191a20c50b43842bdd7;hp=891cc95b8b176bbc522232e64c8cdb0889679c5f;hpb=976c241df475c9d99161a1100517c3c308074d7f;p=babeltrace.git diff --git a/tests/bindings/python/bt2/test_event_class.py b/tests/bindings/python/bt2/test_event_class.py index 891cc95b..beab05cb 100644 --- a/tests/bindings/python/bt2/test_event_class.py +++ b/tests/bindings/python/bt2/test_event_class.py @@ -1,217 +1,96 @@ -from bt2 import values +# +# Copyright (C) 2019 EfficiOS Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; only version 2 +# of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + import unittest -import copy import bt2 +from utils import get_default_trace_class -@unittest.skip("this is broken") class EventClassTestCase(unittest.TestCase): def setUp(self): - self._context_ft = bt2.StructureFieldType() - self._context_ft.append_field('allo', bt2.StringFieldType()) - self._context_ft.append_field('zola', bt2.IntegerFieldType(18)) - self._payload_ft = bt2.StructureFieldType() - self._payload_ft.append_field('zoom', bt2.StringFieldType()) - self._ec = bt2.EventClass('my_event') - self._ec.id = 18 - self._ec.emf_uri = 'yes' - self._ec.log_level = bt2.EventClassLogLevel.INFO - self._ec.context_field_type = self._context_ft - self._ec.payload_field_type = self._payload_ft - - def tearDown(self): - del self._context_ft - del self._payload_ft - del self._ec - - def test_create(self): - self.assertEqual(self._ec.name, 'my_event') - self.assertEqual(self._ec.id, 18) - self.assertEqual(self._ec.context_field_type, self._context_ft) - self.assertEqual(self._ec.payload_field_type, self._payload_ft) - self.assertEqual(self._ec.emf_uri, 'yes') - self.assertEqual(self._ec.log_level, bt2.EventClassLogLevel.INFO) - - def test_create_invalid_no_name(self): - with self.assertRaises(TypeError): - bt2.EventClass() - - def test_create_full(self): - ec = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, - emf_uri='my URI', - log_level=bt2.EventClassLogLevel.WARNING) - self.assertEqual(ec.name, 'name') - self.assertEqual(ec.id, 23) - self.assertEqual(ec.context_field_type, self._context_ft) - self.assertEqual(ec.payload_field_type, self._payload_ft) - self.assertEqual(ec.emf_uri, 'my URI') - self.assertEqual(ec.log_level, bt2.EventClassLogLevel.WARNING) - - def test_assign_id(self): - self._ec.id = 1717 - self.assertEqual(self._ec.id, 1717) - - def test_assign_invalid_id(self): - with self.assertRaises(TypeError): - self._ec.id = 'lel' + self._tc = get_default_trace_class() + + self._context_fc = self._tc.create_structure_field_class() + self._context_fc.append_member('allo', self._tc.create_string_field_class()) + self._context_fc.append_member('zola', self._tc.create_signed_integer_field_class(18)) + + self._payload_fc = self._tc.create_structure_field_class() + self._payload_fc.append_member('zoom', self._tc.create_string_field_class()) + + self._stream_class = self._tc.create_stream_class(assigns_automatic_event_class_id=True) + + def test_create_default(self): + ec = self._stream_class.create_event_class() - def test_assign_context_field_type(self): - self._ec.context_field_type = self._payload_ft - self.assertEqual(self._ec.context_field_type, self._payload_ft) + self.assertIsNone(ec.name, 'my_event') + self.assertTrue(type(ec.id), int) + self.assertIsNone(ec.specific_context_field_class) + self.assertIsNone(ec.payload_field_class) + self.assertIsNone(ec.emf_uri) + self.assertIsNone(ec.log_level) - def test_assign_no_context_field_type(self): - self._ec.context_field_type = None - self.assertIsNone(self._ec.context_field_type) + def test_create_invalid_id(self): + sc = self._tc.create_stream_class(assigns_automatic_event_class_id=False) + with self.assertRaises(TypeError): + sc.create_event_class(id='lel') + + def test_create_specific_context_field_class(self): + fc = self._tc.create_structure_field_class() + ec = self._stream_class.create_event_class(specific_context_field_class=fc) + self.assertEqual(ec.specific_context_field_class.addr, fc.addr) - def test_assign_invalid_context_field_type(self): + def test_create_invalid_specific_context_field_class(self): with self.assertRaises(TypeError): - self._ec.context_field_type = 'lel' + self._stream_class.create_event_class(specific_context_field_class='lel') - def test_assign_payload_field_type(self): - self._ec.payload_field_type = self._payload_ft - self.assertEqual(self._ec.payload_field_type, self._payload_ft) + def test_create_payload_field_class(self): + fc = self._tc.create_structure_field_class() + ec = self._stream_class.create_event_class(payload_field_class=fc) + self.assertEqual(ec.payload_field_class.addr, fc.addr) + + def test_create_invalid_payload_field_class(self): + with self.assertRaises(TypeError): + self._stream_class.create_event_class(payload_field_class='lel') - def test_assign_no_payload_field_type(self): - self._ec.payload_field_type = None - self.assertIsNone(self._ec.payload_field_type) + def test_create_name(self): + ec = self._stream_class.create_event_class(name='viande à chien') + self.assertEqual(ec.name, 'viande à chien') - def test_assign_invalid_payload_field_type(self): + def test_create_invalid_name(self): with self.assertRaises(TypeError): - self._ec.payload_field_type = 'lel' - - def test_stream_class_prop_no_sc(self): - self.assertIsNone(self._ec.stream_class) - - def test_stream_class_prop(self): - sc = bt2.StreamClass() - sc.add_event_class(self._ec) - self.assertEqual(self._ec.stream_class.addr, sc.addr) - - def _test_copy(self, cpy): - self.assertIsNot(cpy, self._ec) - self.assertNotEqual(cpy.addr, self._ec.addr) - self.assertEqual(cpy, self._ec) - - def test_copy(self): - cpy = copy.copy(self._ec) - self._test_copy(cpy) - self.assertEqual(self._ec.context_field_type.addr, cpy.context_field_type.addr) - self.assertEqual(self._ec.payload_field_type.addr, cpy.payload_field_type.addr) - - def test_deepcopy(self): - cpy = copy.deepcopy(self._ec) - self._test_copy(cpy) - self.assertNotEqual(self._ec.context_field_type.addr, cpy.context_field_type.addr) - self.assertNotEqual(self._ec.payload_field_type.addr, cpy.payload_field_type.addr) - - def test_assign_emf_uri(self): - self._ec.emf_uri = 'salut' - self.assertEqual(self._ec.emf_uri, 'salut') - - def test_assign_invalid_emf_uri(self): + self._stream_class.create_event_class(name=2) + + def test_emf_uri(self): + ec = self._stream_class.create_event_class(emf_uri='salut') + self.assertEqual(ec.emf_uri, 'salut') + + def test_create_invalid_emf_uri(self): with self.assertRaises(TypeError): - self._ec.emf_uri = 23 + self._stream_class.create_event_class(emf_uri=23) - def test_assign_log_level(self): - self._ec.log_level = bt2.EventClassLogLevel.EMERGENCY - self.assertEqual(self._ec.log_level, bt2.EventClassLogLevel.EMERGENCY) + def test_create_log_level(self): + ec = self._stream_class.create_event_class(log_level=bt2.EventClassLogLevel.EMERGENCY) + self.assertEqual(ec.log_level, bt2.EventClassLogLevel.EMERGENCY) - def test_assign_invalid_log_level(self): + def test_create_invalid_log_level(self): with self.assertRaises(ValueError): - self._ec.log_level = 'zoom' - - def test_eq(self): - ec1 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, - emf_uri='my URI', - log_level=bt2.EventClassLogLevel.WARNING) - ec2 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, - emf_uri='my URI', - log_level=bt2.EventClassLogLevel.WARNING) - self.assertEqual(ec1, ec2) - - def test_ne_name(self): - ec1 = bt2.EventClass(name='name1', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, - emf_uri='my URI', - log_level=bt2.EventClassLogLevel.WARNING) - ec2 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, - emf_uri='my URI', - log_level=bt2.EventClassLogLevel.WARNING) - self.assertNotEqual(ec1, ec2) - - def test_ne_id(self): - ec1 = bt2.EventClass(name='name', id=24, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, - emf_uri='my URI', - log_level=bt2.EventClassLogLevel.WARNING) - ec2 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, - emf_uri='my URI', - log_level=bt2.EventClassLogLevel.WARNING) - self.assertNotEqual(ec1, ec2) - - def test_ne_context_field_type(self): - ec1 = bt2.EventClass(name='name', id=23, - context_field_type=self._payload_ft, - payload_field_type=self._payload_ft, - emf_uri='my URI', - log_level=bt2.EventClassLogLevel.WARNING) - ec2 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, - emf_uri='my URI', - log_level=bt2.EventClassLogLevel.WARNING) - self.assertNotEqual(ec1, ec2) - - def test_ne_payload_field_type(self): - ec1 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._context_ft, - emf_uri='my URI', - log_level=bt2.EventClassLogLevel.WARNING) - ec2 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, - emf_uri='my URI', - log_level=bt2.EventClassLogLevel.WARNING) - self.assertNotEqual(ec1, ec2) - - def test_ne_emf_uri(self): - ec1 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, - emf_uri='my URI', - log_level=bt2.EventClassLogLevel.WARNING) - ec2 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, - emf_uri='my UR', - log_level=bt2.EventClassLogLevel.WARNING) - self.assertNotEqual(ec1, ec2) - - def test_ne_log_level(self): - ec1 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, - emf_uri='my URI', - log_level=bt2.EventClassLogLevel.WARNING) - ec2 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, - emf_uri='my URI', - log_level=bt2.EventClassLogLevel.ERROR) - self.assertNotEqual(ec1, ec2) - - def test_eq_invalid(self): - self.assertFalse(self._ec == 23) + self._stream_class.create_event_class(log_level='zoom') + + def test_stream_class(self): + ec = self._stream_class.create_event_class() + self.assertEqual(ec.stream_class.addr, self._stream_class.addr)