Example #1
0
    def test_copy(self):

        class HasProps2(properties.HasProperties):
            my_list = properties.List('my list', properties.Bool(''))
            five = properties.GettableProperty('five', default=5)
            my_array = properties.Vector3Array('my array')

        class HasProps1(properties.HasProperties):
            my_hp2 = properties.Instance('my HasProps2', HasProps2)
            my_union = properties.Union(
                'string or int',
                (properties.String(''), properties.Integer(''))
            )

        hp1 = HasProps1(
            my_hp2=HasProps2(
                my_list=[True, True, False],
                my_array=[[1., 2., 3.], [4., 5., 6.]],
            ),
            my_union=10,
        )
        hp1_copy = properties.copy(hp1)
        assert properties.equal(hp1, hp1_copy)
        assert hp1 is not hp1_copy
        assert hp1.my_hp2 is not hp1_copy.my_hp2
        assert hp1.my_hp2.my_list is not hp1_copy.my_hp2.my_list
        assert hp1.my_hp2.my_array is not hp1_copy.my_hp2.my_array
Example #2
0
def sanitize_data_colormaps(data):
    """Update data mappings to be well behaved with the web visualization

    For discrete and category data, web visualization expects
    the first mapping to be a color map. If this is not the case, it
    fails to load. This function re-orders the mappings or creates a
    stand-in mapping with random colors to meet this limitation.
    """
    if not data.mappings:
        data.mappings = []
        if not isinstance(data, spatial.DataCategory):
            return data
    elif is_color_mapping(data.mappings[0]):
        return data
    color_mapping_indices = [
        ind for ind, mapping in enumerate(data.mappings)
        if not isinstance(mapping, spatial.MappingContinuous)
        and is_color_mapping(mapping)
    ]
    if color_mapping_indices:
        index = color_mapping_indices[0]
        data.mappings = (
            [data.mappings[index]] + data.mappings[:index] +
            data.mappings[index + 1:]
        )
    elif hasattr(data, 'categories') and is_color_mapping(data.categories):
        data.mappings = [data.categories] + data.mappings
    else:
        new_mapping = properties.copy(data.mappings[0])
        new_mapping.values = ['random'] * len(new_mapping.values)
        data.mappings = [new_mapping] + data.mappings
    return data
Example #3
0
    def test_copy(self):

        class HasProps2(properties.HasProperties):
            my_list = properties.List('my list', properties.Bool(''))
            five = properties.GettableProperty('five', default=5)
            my_array = properties.Vector3Array('my array')

        class HasProps1(properties.HasProperties):
            my_hp2 = properties.Instance('my HasProps2', HasProps2)
            my_union = properties.Union(
                'string or int',
                (properties.String(''), properties.Integer(''))
            )

        hp1 = HasProps1(
            my_hp2=HasProps2(
                my_list=[True, True, False],
                my_array=[[1., 2., 3.], [4., 5., 6.]],
            ),
            my_union=10,
        )
        hp1_copy = properties.copy(hp1)
        assert properties.equal(hp1, hp1_copy)
        assert hp1 is not hp1_copy
        assert hp1.my_hp2 is not hp1_copy.my_hp2
        assert hp1.my_hp2.my_list is not hp1_copy.my_hp2.my_list
        assert hp1.my_hp2.my_array is not hp1_copy.my_hp2.my_array
Example #4
0
    def test_prop_singleton(self):

        class Stringleton(Singleton):

            name = properties.String('')

        with self.assertRaises(properties.ValidationError):
            Stringleton(5)

        a = Stringleton('z')
        b = Stringleton('z')

        assert a is b

        a.name = 'b'
        assert b.name == 'b'
        c = Stringleton('z')
        assert c.name == 'b'

        d = properties.copy(c)
        assert d.name is 'b'

        with self.assertRaises(ValueError):
            Stringleton.deserialize(10)

        d_ser = d.serialize()
        assert Stringleton.deserialize(d_ser.copy()) is c
        d_ser.pop('_singleton_id')
        assert Stringleton.deserialize(d_ser) is not c

        e_ser = {'_singleton_id': 'm', 'name': 'hi'}
        e = Stringleton.deserialize(e_ser)

        assert e.name == 'hi'
        f = Stringleton('m')
        assert f.name == 'hi'


        g_ser = {'name': 'blah'}
        g = Stringleton.deserialize(g_ser)
        assert g.name == 'blah'
        assert g._singleton_id == 'blah'
Example #5
0
    def test_singleton(self):

        a = Singleton('a')
        b = Singleton('a')
        c = Singleton('c')

        assert a is b
        assert a is not c

        d = properties.copy(c)

        assert d is c

        e = Singleton.deserialize(d.serialize())
        assert e is d

        class AnotherSingleton(Singleton):
            pass

        assert AnotherSingleton('a') is a
        assert AnotherSingleton('a').__class__ is Singleton
Example #6
0
    def test_singleton(self):

        a = Singleton('a')
        b = Singleton('a')
        c = Singleton('c')

        assert a is b
        assert a is not c

        d = properties.copy(c)

        assert d is c

        e = Singleton.deserialize(d.serialize())
        assert e is d

        class AnotherSingleton(Singleton):
            pass

        assert AnotherSingleton('a') is a
        assert AnotherSingleton('a').__class__ is Singleton
Example #7
0
    def test_prop_singleton(self):
        class Stringleton(Singleton):

            name = properties.String('')

        with self.assertRaises(properties.ValidationError):
            Stringleton(5)

        a = Stringleton('z')
        b = Stringleton('z')

        assert a is b

        a.name = 'b'
        assert b.name == 'b'
        c = Stringleton('z')
        assert c.name == 'b'

        d = properties.copy(c)
        assert d.name is 'b'

        with self.assertRaises(ValueError):
            Stringleton.deserialize(10)

        d_ser = d.serialize()
        assert Stringleton.deserialize(d_ser.copy()) is c
        d_ser.pop('_singleton_id')
        assert Stringleton.deserialize(d_ser) is not c

        e_ser = {'_singleton_id': 'm', 'name': 'hi'}
        e = Stringleton.deserialize(e_ser)

        assert e.name == 'hi'
        f = Stringleton('m')
        assert f.name == 'hi'

        g_ser = {'name': 'blah'}
        g = Stringleton.deserialize(g_ser)
        assert g.name == 'blah'
        assert g._singleton_id == 'blah'
Example #8
0
 def copy(self):
     """
     Make a copy of the current casing object
     """
     return properties.copy(self)
Example #9
0
 def copy(self):
     """
     Make a copy of the current mesh
     """
     return properties.copy(self)