Exemplo n.º 1
0
 def test_subclasses_weakref(self):
     """ Make sure that dynamically created subclasses are not held
     strongly by HasTraits.
     """
     previous_subclasses = HasTraits.__subclasses__()
     _create_subclass()
     _create_subclass()
     _create_subclass()
     _create_subclass()
     gc.collect()
     self.assertEqual(previous_subclasses, HasTraits.__subclasses__())
Exemplo n.º 2
0
 def test_subclasses_weakref(self):
     """ Make sure that dynamically created subclasses are not held
     strongly by HasTraits.
     """
     previous_subclasses = HasTraits.__subclasses__()
     _create_subclass()
     _create_subclass()
     _create_subclass()
     _create_subclass()
     gc.collect()
     self.assertEqual(previous_subclasses, HasTraits.__subclasses__())
Exemplo n.º 3
0
    def __init__(self, query_object, **kwargs):
        '''
        Creates a dialog window for selecting date period, source classes and event severity levels/types.
        :param query_object:
        :return:
        '''
        assert isinstance(query_object, EventSelectionQuery)

        self.shown_event_names_list = "\n".join(
            list(query_object.list_of_event_names))
        self.query_object = query_object
        self.query_start_date = query_object.period_start_date
        self.query_end_date = query_object.period_end_date

        HasTraits.__init__(self, **kwargs)
Exemplo n.º 4
0
    def test_subclasses_weakref(self):
        """ Make sure that dynamically created subclasses are not held
        strongly by HasTraits.
        """
        previous_subclasses = HasTraits.__subclasses__()
        _create_subclass()
        _create_subclass()
        _create_subclass()
        _create_subclass()
        gc.collect()

        # In Python < 3.6, we can end up seeing the same subclasses but in
        # a different order, so use assertCountEqual rather than assertEqual.
        # Ref: enthought/traits#1282.
        self.assertCountEqual(previous_subclasses, HasTraits.__subclasses__())
Exemplo n.º 5
0
    def test_validate(self):
        """ Check the validation method.

        """
        foo = Dict()

        # invalid value
        with self.assertRaises(TraitError):
            foo.validate(object=HasTraits(), name="bar", value=None)

        # valid value
        result = foo.validate(object=HasTraits(), name="bar", value={})
        self.assertIsInstance(result, TraitDictObject)

        # object is None (check for issue #71)
        result = foo.validate(object=None, name="bar", value={})
        self.assertEqual(result, {})
Exemplo n.º 6
0
    def test__trait_set_inited(self):
        foo = HasTraits.__new__(HasTraits)

        self.assertFalse(foo.traits_inited())

        foo._trait_set_inited()

        self.assertTrue(foo.traits_inited())
Exemplo n.º 7
0
    def __init__(self, obj=None, **kw ):
        "ClassModel Constructor, accepting the initialization object (or dictionary)"
    #--------------------------------------------------------------------------------------------------
        HasTraits.__init__(self, **kw)

        if self._templates:
            self.add_trait( "Templates", Enum( "", self._templates.keys(), private=True, visible=True ) )

        if obj is not None:
            try:
                v = vars(obj)
            except TypeError:
                #Maybe its aready a dictionary -> not the most intended way
                self.set_init( obj ) #we leave this one to raise exception in case element cant be "iterized"
            else:
                self.set_init( v )
                self.__orig_obj = obj
Exemplo n.º 8
0
def main():
    """ Entry point for standalone testing/debugging. """

    from pyanno.modelBt_loopdesign import ModelBtLoopDesign
    model = ModelBtLoopDesign.create_initial_state(5)
    annotations = model.generate_annotations(2)

    anno = AnnotationsContainer.from_array(annotations, name='blah')
    model_view = AnnotationsView(annotations_container=anno, model=HasTraits())
    model_view.configure_traits()
    return model, annotations, model_view
Exemplo n.º 9
0
    def set_annotations(self, annotations_container):
        """Update window with a new set of annotations."""
        self.annotations_view = AnnotationsView(
            annotations_container=annotations_container,
            nclasses=self.model.nclasses,
            application=self.application,
            model=HasTraits())
        self.annotations_stats_view = AnnotationsStatisticsView(
            annotations=self.annotations, nclasses=self.nclasses)

        self.annotations_are_defined = True
        self.annotations_updated = True
Exemplo n.º 10
0
 def __init__(self, obj, as_list=False ):
     """Contructor for a generic trait. Accepts an object, used for initialization.
     "as_list" flag shall be set to True in case the object is effectivelly a list but shall be
     rendered as an object, which is useful for mixed type lists"""
 #--------------------------------------------------------------------------------------------------
     HasTraits.__init__(self)
     self.__is_list = as_list
     
     #Get object properties or generate from list
     if as_list:
         obj_props = dict( ('pos'+str(i), value) for i, value in enumerate(obj) )
     else:
         try:
             obj_props = vars(obj)
             self.__orig_obj = obj
         except TypeError:
             #Maybe not the most intended way
             obj_props = obj
             self.__is_dict = True
     
     new_traits = self._create_get_traits( self.add_trait, obj_props )
     self.set( **new_traits )
Exemplo n.º 11
0
    def test_hastraits_deepcopy(self):
        # Regression test for enthought/traits#2 and enthought/traits#16
        from copy import deepcopy

        a = HasTraits()
        a.add_trait("foo", Int)
        a.foo = 1
        with self.assertRaises(TraitError):
            a.foo = "a"
        copied_a = deepcopy(a)
        with self.assertRaises(TraitError):
            copied_a.foo = "a"
Exemplo n.º 12
0
    def test_hastraits_pickle(self):
        # Regression test for enthought/traits#2 and enthought/traits#16
        from pickle import dumps, loads

        a = HasTraits()
        a.add_trait("foo", Int)
        a.foo = 1
        with self.assertRaises(TraitError):
            a.foo = "a"
        pickled_a = dumps(a)
        unpickled_a = loads(pickled_a)
        with self.assertRaises(TraitError):
            unpickled_a.foo = "a"
Exemplo n.º 13
0
    def test_traits_inited(self):
        foo = HasTraits()

        self.assertTrue(foo.traits_inited())
Exemplo n.º 14
0
 def _annotations_view_default(self):
     anno = AnnotationsContainer.from_array([[0]], name='<undefined>')
     return AnnotationsView(annotations_container=anno,
                            nclasses=self.model.nclasses,
                            application=self.application,
                            model=HasTraits())
Exemplo n.º 15
0
 def f():
     obj = HasTraits()
     obj.on_trait_change(handler)
Exemplo n.º 16
0
 def f():
     obj = HasTraits()
     obj.on_trait_change(handler)