<commit_before>""" Tests for the garbage collection of objects in mayavi package.
"""
# Authors: <NAME>, <NAME>
# Copyright (c) 2015, Enthought, Inc.
# License: BSD Style.

from pyface.api import GUI, ApplicationWindow
from traits.api import Instance
from tvtk.tests.common import TestGarbageCollection
from mayavi.core.ui.mayavi_scene import MayaviScene
from mayavi.core.engine import Engine
from mayavi.core.null_engine import NullEngine
from mayavi.tools.mlab_scene_model import MlabSceneModel



class TestMayaviGarbageCollection(TestGarbageCollection):
    """ See: tvtk.tests.common.TestGarbageCollection
    """
    def test_mlab_scene_model_with_gui(self):
        """ Tests if MlabSceneModel with GUI can be garbage collected."""

        class MlabSceneModelWindow(ApplicationWindow):
            scene = Instance(MlabSceneModel, ())

        gui = GUI()

        def close(win):
            win.close()

        def open(gui):
            window = MlabSceneModelWindow(size=(60, 60))
            window.open()
            return window

        def create_fn():
            return open(gui)

        def close_fn(o):
            # Start the GUI event loop!
            gui.invoke_after(500, close, o)
            gui.start_event_loop()

        self.check_object_garbage_collected(create_fn, close_fn)

    def test_mlab_scene_model(self):
        """ Tests if MlabSceneModel can be garbage collected."""

        def create_fn():
            return MlabSceneModel()

        def close_fn(o):
            o.closing = True

        self.check_object_garbage_collected(create_fn, close_fn)

    def test_scene(self):
        """ Tests if core Scene can be garbage collected."""
        def create_fn():
            e = NullEngine()
            e.start()
            scene = e.new_scene()
            return scene

        def close_fn(o):
            o.closing = True<commit_msg>Update mlab scene model gui test<commit_after>""" Tests for the garbage collection of objects in mayavi package.
"""
# Authors: <NAME>, <NAME>
# Copyright (c) 2015, Enthought, Inc.
# License: BSD Style.

from numpy import sqrt, sin, mgrid
from traits.api import Instance, HasTraits
from traitsui.api import View, Item
from tvtk.pyface.scene_editor import SceneEditor
from tvtk.tests.common import TestGarbageCollection
from mayavi.core.ui.mayavi_scene import MayaviScene
from mayavi.core.engine import Engine
from mayavi.core.null_engine import NullEngine
from mayavi.tools.mlab_scene_model import MlabSceneModel

class TestMayaviGarbageCollection(TestGarbageCollection):
    """ See: tvtk.tests.common.TestGarbageCollection
    """
    def test_mlab_scene_model_with_gui(self):
        """ Tests if MlabSceneModel with GUI can be garbage collected."""
        class MlabApp(HasTraits):

            # The scene model.
            scene = Instance(MlabSceneModel, ())

            view = View(Item(name='scene',
                             editor=SceneEditor(scene_class=MayaviScene),
                             show_label=False,
                             resizable=True,
                             height=500,
                             width=500),
                        resizable=True
                        )

            def __init__(self, **traits):
                self.generate_data()

            def generate_data(self):
                # Create some data
                X, Y = mgrid[-2:2:100j, -2:2:100j]
                R = 10*sqrt(X**2 + Y**2)
                Z = sin(R)/R
                self.scene.mlab.surf(X, Y, Z, colormap='gist_earth')

        def create_fn():
            app = MlabApp()
            return app.edit_traits()

        self.check_object_garbage_collected(create_fn)

    def test_mlab_scene_model(self):
        """ Tests if MlabSceneModel can be garbage collected."""

        def create_fn():
            return MlabSceneModel()

        def close_fn(o):
            o.closing = True

        self.check_object_garbage_collected(create_fn, close_fn)

    def test_scene(self):
        """ Tests if core Scene can be garbage collected."""
        def create_fn():
            e = NullEngine()
            e.start()
            scene = e.new_scene()
            return scene

        def close_fn(o):
            o.closing = True
{'fraction_non_alphanumeric': 0.08954524144397562, 'fraction_numerical': 0.008204406938584154, 'mean_word_length': 2.160740740740741, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4540618', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1170, 'n_words': 309}