<commit_before>#    Copyright 2015-2015 ARM Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


import unittest
import matplotlib
from test_sched import BaseTestSched
from trappy.base import Base
import trappy


class DynamicEvent(Base):

    """Test the ability to register
       specific classes to trappy"""

    unique_word = "dynamic_test_key"
    name = "dynamic_event"

    def __init__(self):
        super(DynamicEvent, self).__init__(
            unique_word=self.unique_word,
        )


class TestDynamicEvents(BaseTestSched):

    def __init__(self, *args, **kwargs):
        super(TestDynamicEvents, self).__init__(*args, **kwargs)

    def test_dynamic_data_frame(self):
        """
           Test if the dynamic events are populated
           in the data frame
        """
        trappy.register_dynamic("DynamicEvent", "dynamic_test_key")
        r = trappy.Run(name="first")
        self.assertTrue(len(r.dynamic_event.data_frame) == 1)

    def test_dynamic_class_attr(self):
        """
           Test the attibutes of the dynamically
           generated class
        """
        cls = trappy.register_dynamic("DynamicEvent", "dynamic_test_key",
              pivot="test_pivot")
        self.assertEquals(cls.__name__, "DynamicEvent")
        self.assertEquals(cls.name, "dynamic_event")
        self.assertEquals(cls.unique_word, "dynamic_test_key")
        self.assertEquals(cls.pivot, "test_pivot")

    def test_dynamic_event_plot(self):
        """Test if plotter can accept a dynamic class
            for a template argument"""

        cls = trappy.register_dynamic("DynamicEvent", "dynamic_test_key")
        r = trappy.Run(name="first")
        l = trappy.LinePlot(r, cls, column="load")
        l.view(test=True)

    def test_dynamic_event_scope(self):
	"""Test the case when an "all" scope class is
	registered. it should appear in both thermal and sched
	run class definitions when scoped run objects are created
	"""
        cls = trappy.register_dynamic("DynamicEvent", "dynamic_test_key")
        r1 = trappy.Run(name="first")
	print r1.class_definitions
	self.assertTrue(r1.class_definitions.has_key(cls.name))

    def test_register_class(self):
        trappy.register_class(DynamicEvent)
        r = trappy.Run(name="first")
        self.assertTrue(len(r.dynamic_event.data_frame) == 1)<commit_msg>tests: Remove unnecessary print statement<commit_after>#    Copyright 2015-2015 ARM Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


import unittest
import matplotlib
from test_sched import BaseTestSched
from trappy.base import Base
import trappy


class DynamicEvent(Base):

    """Test the ability to register
       specific classes to trappy"""

    unique_word = "dynamic_test_key"
    name = "dynamic_event"

    def __init__(self):
        super(DynamicEvent, self).__init__(
            unique_word=self.unique_word,
        )


class TestDynamicEvents(BaseTestSched):

    def __init__(self, *args, **kwargs):
        super(TestDynamicEvents, self).__init__(*args, **kwargs)

    def test_dynamic_data_frame(self):
        """
           Test if the dynamic events are populated
           in the data frame
        """
        trappy.register_dynamic("DynamicEvent", "dynamic_test_key")
        r = trappy.Run(name="first")
        self.assertTrue(len(r.dynamic_event.data_frame) == 1)

    def test_dynamic_class_attr(self):
        """
           Test the attibutes of the dynamically
           generated class
        """
        cls = trappy.register_dynamic("DynamicEvent", "dynamic_test_key",
              pivot="test_pivot")
        self.assertEquals(cls.__name__, "DynamicEvent")
        self.assertEquals(cls.name, "dynamic_event")
        self.assertEquals(cls.unique_word, "dynamic_test_key")
        self.assertEquals(cls.pivot, "test_pivot")

    def test_dynamic_event_plot(self):
        """Test if plotter can accept a dynamic class
            for a template argument"""

        cls = trappy.register_dynamic("DynamicEvent", "dynamic_test_key")
        r = trappy.Run(name="first")
        l = trappy.LinePlot(r, cls, column="load")
        l.view(test=True)

    def test_dynamic_event_scope(self):
	"""Test the case when an "all" scope class is
	registered. it should appear in both thermal and sched
	run class definitions when scoped run objects are created
	"""
        cls = trappy.register_dynamic("DynamicEvent", "dynamic_test_key")
        r1 = trappy.Run(name="first")
	self.assertTrue(r1.class_definitions.has_key(cls.name))

    def test_register_class(self):
        trappy.register_class(DynamicEvent)
        r = trappy.Run(name="first")
        self.assertTrue(len(r.dynamic_event.data_frame) == 1)
{'fraction_non_alphanumeric': 0.09498773221170698, 'fraction_numerical': 0.0057833859095688745, 'mean_word_length': 3.2494415487714075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5964968', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1588, 'n_words': 471}