Exemple #1
0
    def test_has_set_get(self):
        name = 'array_param'
        shape = (3, )
        with self.assertRaises(AttributeError):
            ArrayParameter(name, shape)

        p = SimpleArrayParam([1, 2, 3], name, shape)

        self.assertTrue(hasattr(p, 'get'))
        self.assertFalse(hasattr(p, 'set'))

        with self.assertRaises(AttributeError):
            SettableArray([1, 2, 3], name, shape)
    def test_has_set_get(self):
        name = 'array_param'
        shape = (3, )
        with self.assertRaises(AttributeError):
            ArrayParameter(name, shape)

        p = SimpleArrayParam([1, 2, 3], name, shape)

        self.assertTrue(hasattr(p, 'get'))
        self.assertTrue(p.gettable)
        self.assertFalse(hasattr(p, 'set'))
        self.assertFalse(p.settable)

        # Yet, it's possible to set the cached value
        p.cache.set([6, 7, 8])
        self.assertListEqual(p.get_latest(), [6, 7, 8])
        # However, due to the implementation of this ``SimpleArrayParam``
        # test parameter it's ``get`` call will return the originally passed
        # list
        self.assertListEqual(p.get(), [1, 2, 3])
        self.assertListEqual(p.get_latest(), [1, 2, 3])

        with self.assertRaises(AttributeError):
            SettableArray([1, 2, 3], name, shape)
Exemple #3
0
def test_has_set_get():
    name = 'array_param'
    shape = (3,)
    with pytest.raises(AttributeError):
        ArrayParameter(name, shape)

    p = SimpleArrayParam([1, 2, 3], name, shape)

    assert hasattr(p, 'get')
    assert p.gettable
    assert not hasattr(p, 'set')
    assert not p.settable

    # Yet, it's possible to set the cached value
    p.cache.set([6, 7, 8])
    assert p.get_latest() == [6, 7, 8]
    # However, due to the implementation of this ``SimpleArrayParam``
    # test parameter it's ``get`` call will return the originally passed
    # list
    assert p.get() == [1, 2, 3]
    assert p.get_latest() == [1, 2, 3]

    with pytest.raises(AttributeError):
        SettableArray([1, 2, 3], name, shape)