def test_element_dynamic_with_param_method(self): curve = Curve([1, 2, 3]) inst = ParamClass(label='Test') applied = TestOperation(curve, label=inst.dynamic_label) self.assertEqual(len(applied.streams), 1) self.assertIsInstance(applied.streams[0], Params) self.assertEqual(applied.streams[0].parameters, ['label']) self.assertEqual(applied[()], curve.relabel('Test!')) inst.label = 'New label' self.assertEqual(applied[()], curve.relabel('New label!'))
def test_element_dynamic_with_param_method(self): curve = Curve([1, 2, 3]) inst = ParamClass(label='Test') applied = TestOperation(curve, label=inst.dynamic_label) self.assertEqual(len(applied.streams), 1) self.assertIsInstance(applied.streams[0], Params) self.assertEqual(applied.streams[0].parameters, ['label']) self.assertEqual(applied[()], curve.relabel('Test!')) inst.label = 'New label' self.assertEqual(applied[()], curve.relabel('New label!'))
def test_element_dynamic_with_instance_param(self): curve = Curve([1, 2, 3]) inst = ParamClass(label='Test') applied = ExampleOperation(curve, label=inst.param.label) self.assertEqual(len(applied.streams), 1) self.assertIsInstance(applied.streams[0], Params) self.assertEqual(applied.streams[0].parameters, [inst.param.label]) self.assertEqual(applied[()], curve.relabel('Test'))
class TestApplyElement(ComparisonTestCase): def setUp(self): self.element = Curve([1, 2, 3]) def test_element_apply_simple(self): applied = self.element.apply(lambda x: x.relabel('Test')) self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_with_kwarg(self): applied = self.element.apply(lambda x, label: x.relabel(label), label='Test') self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_not_dynamic_with_instance_param(self): pinst = ParamClass() applied = self.element.apply(lambda x, label: x.relabel(label), label=pinst.param.label, dynamic=False) self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_not_dynamic_element_method(self): pinst = ParamClass() applied = self.element.apply(self.element.relabel, dynamic=False, label=pinst.param.label) self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_not_dynamic_with_param_method(self): pinst = ParamClass() applied = self.element.apply(lambda x, label: x.relabel(label), label=pinst.dynamic_label, dynamic=False) self.assertEqual(applied, self.element.relabel('Test!')) def test_element_apply_dynamic(self): applied = self.element.apply(lambda x: x.relabel('Test'), dynamic=True) self.assertEqual(len(applied.streams), 0) self.assertEqual(applied[()], self.element.relabel('Test')) def test_element_apply_dynamic_with_kwarg(self): applied = self.element.apply(lambda x, label: x.relabel(label), dynamic=True, label='Test') self.assertEqual(len(applied.streams), 0) self.assertEqual(applied[()], self.element.relabel('Test')) def test_element_apply_dynamic_element_method(self): pinst = ParamClass() applied = self.element.apply(self.element.relabel, label=pinst.param.label) # Check stream self.assertEqual(len(applied.streams), 1) stream = applied.streams[0] self.assertIsInstance(stream, Params) self.assertEqual(stream.parameterized, pinst) self.assertEqual(stream.parameters, ['label']) # Check results self.assertEqual(applied[()], self.element.relabel('Test')) pinst.label = 'Another label' self.assertEqual(applied[()], self.element.relabel('Another label')) def test_element_apply_dynamic_with_instance_param(self): pinst = ParamClass() applied = self.element.apply(lambda x, label: x.relabel(label), label=pinst.param.label) # Check stream self.assertEqual(len(applied.streams), 1) stream = applied.streams[0] self.assertIsInstance(stream, Params) self.assertEqual(stream.parameterized, pinst) self.assertEqual(stream.parameters, ['label']) # Check results self.assertEqual(applied[()], self.element.relabel('Test')) pinst.label = 'Another label' self.assertEqual(applied[()], self.element.relabel('Another label')) def test_element_apply_param_method_with_dependencies(self): pinst = ParamClass() applied = self.element.apply(pinst.apply_label) # Check stream self.assertEqual(len(applied.streams), 1) stream = applied.streams[0] self.assertIsInstance(stream, ParamMethod) self.assertEqual(stream.parameterized, pinst) self.assertEqual(stream.parameters, ['label']) # Check results self.assertEqual(applied[()], self.element.relabel('Test')) pinst.label = 'Another label' self.assertEqual(applied[()], self.element.relabel('Another label')) def test_element_apply_dynamic_with_param_method(self): pinst = ParamClass() applied = self.element.apply(lambda x, label: x.relabel(label), label=pinst.dynamic_label) # Check stream self.assertEqual(len(applied.streams), 1) stream = applied.streams[0] self.assertIsInstance(stream, ParamMethod) self.assertEqual(stream.parameterized, pinst) self.assertEqual(stream.parameters, ['label']) # Check result self.assertEqual(applied[()], self.element.relabel('Test!')) pinst.label = 'Another label' self.assertEqual(applied[()], self.element.relabel('Another label!'))
class TestApplyElement(ComparisonTestCase): def setUp(self): self.element = Curve([1, 2, 3]) def test_element_apply_simple(self): applied = self.element.apply(lambda x: x.relabel('Test')) self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_method_as_string(self): applied = self.element.apply('relabel', label='Test') self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_with_kwarg(self): applied = self.element.apply(lambda x, label: x.relabel(label), label='Test') self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_not_dynamic_with_instance_param(self): pinst = ParamClass() applied = self.element.apply(lambda x, label: x.relabel(label), label=pinst.param.label, dynamic=False) self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_not_dynamic_with_method_string(self): pinst = ParamClass() applied = self.element.apply('relabel', dynamic=False, label=pinst.param.label) self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_not_dynamic_with_param_method(self): pinst = ParamClass() applied = self.element.apply(lambda x, label: x.relabel(label), label=pinst.dynamic_label, dynamic=False) self.assertEqual(applied, self.element.relabel('Test!')) def test_element_apply_dynamic(self): applied = self.element.apply(lambda x: x.relabel('Test'), dynamic=True) self.assertEqual(len(applied.streams), 0) self.assertEqual(applied[()], self.element.relabel('Test')) def test_element_apply_dynamic_with_kwarg(self): applied = self.element.apply(lambda x, label: x.relabel(label), dynamic=True, label='Test') self.assertEqual(len(applied.streams), 0) self.assertEqual(applied[()], self.element.relabel('Test')) def test_element_apply_dynamic_element_method(self): pinst = ParamClass() applied = self.element.apply(self.element.relabel, label=pinst.param.label) # Check stream self.assertEqual(len(applied.streams), 1) stream = applied.streams[0] self.assertIsInstance(stream, Params) self.assertEqual(stream.parameterized, pinst) self.assertEqual(stream.parameters, [pinst.param.label]) # Check results self.assertEqual(applied[()], self.element.relabel('Test')) pinst.label = 'Another label' self.assertEqual(applied[()], self.element.relabel('Another label')) def test_element_apply_dynamic_with_instance_param(self): pinst = ParamClass() applied = self.element.apply(lambda x, label: x.relabel(label), label=pinst.param.label) # Check stream self.assertEqual(len(applied.streams), 1) stream = applied.streams[0] self.assertIsInstance(stream, Params) self.assertEqual(stream.parameterized, pinst) self.assertEqual(stream.parameters, [pinst.param.label]) # Check results self.assertEqual(applied[()], self.element.relabel('Test')) pinst.label = 'Another label' self.assertEqual(applied[()], self.element.relabel('Another label')) def test_element_apply_param_method_with_dependencies(self): pinst = ParamClass() applied = self.element.apply(pinst.apply_label) # Check stream self.assertEqual(len(applied.streams), 1) stream = applied.streams[0] self.assertIsInstance(stream, ParamMethod) self.assertEqual(stream.parameterized, pinst) self.assertEqual(stream.parameters, [pinst.param.label]) # Check results self.assertEqual(applied[()], self.element.relabel('Test')) pinst.label = 'Another label' self.assertEqual(applied[()], self.element.relabel('Another label')) def test_element_apply_dynamic_with_param_method(self): pinst = ParamClass() applied = self.element.apply(lambda x, label: x.relabel(label), label=pinst.dynamic_label) # Check stream self.assertEqual(len(applied.streams), 1) stream = applied.streams[0] self.assertIsInstance(stream, ParamMethod) self.assertEqual(stream.parameterized, pinst) self.assertEqual(stream.parameters, [pinst.param.label]) # Check result self.assertEqual(applied[()], self.element.relabel('Test!')) pinst.label = 'Another label' self.assertEqual(applied[()], self.element.relabel('Another label!'))
class TestApplyElement(ComparisonTestCase): def setUp(self): self.element = Curve([1, 2, 3]) def test_element_apply_simple(self): applied = self.element.apply(lambda x: x.relabel('Test')) self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_method_as_string(self): applied = self.element.apply('relabel', label='Test') self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_with_kwarg(self): applied = self.element.apply(lambda x, label: x.relabel(label), label='Test') self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_not_dynamic_with_instance_param(self): pinst = ParamClass() applied = self.element.apply(lambda x, label: x.relabel(label), label=pinst.param.label, dynamic=False) self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_not_dynamic_with_method_string(self): pinst = ParamClass() applied = self.element.apply('relabel', dynamic=False, label=pinst.param.label) self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_not_dynamic_with_param_method(self): pinst = ParamClass() applied = self.element.apply(lambda x, label: x.relabel(label), label=pinst.dynamic_label, dynamic=False) self.assertEqual(applied, self.element.relabel('Test!')) def test_element_apply_dynamic(self): applied = self.element.apply(lambda x: x.relabel('Test'), dynamic=True) self.assertEqual(len(applied.streams), 0) self.assertEqual(applied[()], self.element.relabel('Test')) def test_element_apply_dynamic_with_widget_kwarg(self): text = TextInput() applied = self.element.apply(lambda x, label: x.relabel(label), label=text) self.assertEqual(len(applied.streams), 1) self.assertEqual(applied[()].label, '') text.value = 'Test' self.assertEqual(applied[()].label, 'Test') def test_element_apply_dynamic_with_kwarg(self): applied = self.element.apply(lambda x, label: x.relabel(label), dynamic=True, label='Test') self.assertEqual(len(applied.streams), 0) self.assertEqual(applied[()], self.element.relabel('Test')) def test_element_apply_dynamic_element_method(self): pinst = ParamClass() applied = self.element.apply(self.element.relabel, label=pinst.param.label) # Check stream self.assertEqual(len(applied.streams), 1) stream = applied.streams[0] self.assertIsInstance(stream, Params) self.assertEqual(stream.parameterized, pinst) self.assertEqual(stream.parameters, [pinst.param.label]) # Check results self.assertEqual(applied[()], self.element.relabel('Test')) pinst.label = 'Another label' self.assertEqual(applied[()], self.element.relabel('Another label')) def test_element_apply_dynamic_with_instance_param(self): pinst = ParamClass() applied = self.element.apply(lambda x, label: x.relabel(label), label=pinst.param.label) # Check stream self.assertEqual(len(applied.streams), 1) stream = applied.streams[0] self.assertIsInstance(stream, Params) self.assertEqual(stream.parameterized, pinst) self.assertEqual(stream.parameters, [pinst.param.label]) # Check results self.assertEqual(applied[()], self.element.relabel('Test')) pinst.label = 'Another label' self.assertEqual(applied[()], self.element.relabel('Another label')) def test_element_apply_param_method_with_dependencies(self): pinst = ParamClass() applied = self.element.apply(pinst.apply_label) # Check stream self.assertEqual(len(applied.streams), 1) stream = applied.streams[0] self.assertIsInstance(stream, ParamMethod) self.assertEqual(stream.parameterized, pinst) self.assertEqual(stream.parameters, [pinst.param.label]) # Check results self.assertEqual(applied[()], self.element.relabel('Test')) pinst.label = 'Another label' self.assertEqual(applied[()], self.element.relabel('Another label')) def test_element_apply_function_with_dependencies(self): pinst = ParamClass() @param.depends(pinst.param.label) def get_label(label): return label + '!' applied = self.element.apply('relabel', label=get_label) # Check stream self.assertEqual(len(applied.streams), 1) stream = applied.streams[0] self.assertIsInstance(stream, Params) self.assertEqual(stream.parameters, [pinst.param.label]) # Check results self.assertEqual(applied[()], self.element.relabel('Test!')) # Ensure subscriber gets called stream.add_subscriber(lambda **kwargs: applied[()]) pinst.label = 'Another label' self.assertEqual(applied.last, self.element.relabel('Another label!')) def test_element_apply_function_with_dependencies_non_dynamic(self): pinst = ParamClass() @param.depends(pinst.param.label) def get_label(label): return label + '!' applied = self.element.apply('relabel', dynamic=False, label=get_label) self.assertEqual(applied, self.element.relabel('Test!')) def test_element_apply_dynamic_with_param_method(self): pinst = ParamClass() applied = self.element.apply(lambda x, label: x.relabel(label), label=pinst.dynamic_label) # Check stream self.assertEqual(len(applied.streams), 1) stream = applied.streams[0] self.assertIsInstance(stream, ParamMethod) self.assertEqual(stream.parameterized, pinst) self.assertEqual(stream.parameters, [pinst.param.label]) # Check result self.assertEqual(applied[()], self.element.relabel('Test!')) pinst.label = 'Another label' self.assertEqual(applied[()], self.element.relabel('Another label!')) def test_holomap_apply_with_method(self): hmap = HoloMap( {i: Image(np.array([[i, 2], [3, 4]])) for i in range(3)}) reduced = hmap.apply.reduce(x=np.min) expected = HoloMap( {i: Curve([(-0.25, 3), (0.25, i)], 'y', 'z') for i in range(3)}) self.assertEqual(reduced, expected)
class TestApplyElement(ComparisonTestCase): def setUp(self): self.element = Curve([1, 2, 3]) def test_element_apply_simple(self): applied = self.element.apply(lambda x: x.relabel('Test')) self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_method_as_string(self): applied = self.element.apply('relabel', label='Test') self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_with_kwarg(self): applied = self.element.apply(lambda x, label: x.relabel(label), label='Test') self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_not_dynamic_with_instance_param(self): pinst = ParamClass() applied = self.element.apply(lambda x, label: x.relabel(label), label=pinst.param.label, dynamic=False) self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_not_dynamic_with_method_string(self): pinst = ParamClass() applied = self.element.apply('relabel', dynamic=False, label=pinst.param.label) self.assertEqual(applied, self.element.relabel('Test')) def test_element_apply_not_dynamic_with_param_method(self): pinst = ParamClass() applied = self.element.apply(lambda x, label: x.relabel(label), label=pinst.dynamic_label, dynamic=False) self.assertEqual(applied, self.element.relabel('Test!')) def test_element_apply_dynamic(self): applied = self.element.apply(lambda x: x.relabel('Test'), dynamic=True) self.assertEqual(len(applied.streams), 0) self.assertEqual(applied[()], self.element.relabel('Test')) def test_element_apply_dynamic_with_kwarg(self): applied = self.element.apply(lambda x, label: x.relabel(label), dynamic=True, label='Test') self.assertEqual(len(applied.streams), 0) self.assertEqual(applied[()], self.element.relabel('Test')) def test_element_apply_dynamic_element_method(self): pinst = ParamClass() applied = self.element.apply(self.element.relabel, label=pinst.param.label) # Check stream self.assertEqual(len(applied.streams), 1) stream = applied.streams[0] self.assertIsInstance(stream, Params) self.assertEqual(stream.parameterized, pinst) self.assertEqual(stream.parameters, [pinst.param.label]) # Check results self.assertEqual(applied[()], self.element.relabel('Test')) pinst.label = 'Another label' self.assertEqual(applied[()], self.element.relabel('Another label')) def test_element_apply_dynamic_with_instance_param(self): pinst = ParamClass() applied = self.element.apply(lambda x, label: x.relabel(label), label=pinst.param.label) # Check stream self.assertEqual(len(applied.streams), 1) stream = applied.streams[0] self.assertIsInstance(stream, Params) self.assertEqual(stream.parameterized, pinst) self.assertEqual(stream.parameters, [pinst.param.label]) # Check results self.assertEqual(applied[()], self.element.relabel('Test')) pinst.label = 'Another label' self.assertEqual(applied[()], self.element.relabel('Another label')) def test_element_apply_param_method_with_dependencies(self): pinst = ParamClass() applied = self.element.apply(pinst.apply_label) # Check stream self.assertEqual(len(applied.streams), 1) stream = applied.streams[0] self.assertIsInstance(stream, ParamMethod) self.assertEqual(stream.parameterized, pinst) self.assertEqual(stream.parameters, [pinst.param.label]) # Check results self.assertEqual(applied[()], self.element.relabel('Test')) pinst.label = 'Another label' self.assertEqual(applied[()], self.element.relabel('Another label')) def test_element_apply_function_with_dependencies(self): pinst = ParamClass() @param.depends(pinst.param.label) def get_label(label): return label + '!' applied = self.element.apply('relabel', label=get_label) # Check stream self.assertEqual(len(applied.streams), 1) stream = applied.streams[0] self.assertIsInstance(stream, Params) self.assertEqual(stream.parameters, [pinst.param.label]) # Check results self.assertEqual(applied[()], self.element.relabel('Test!')) # Ensure subscriber gets called stream.add_subscriber(lambda **kwargs: applied[()]) pinst.label = 'Another label' self.assertEqual(applied.last, self.element.relabel('Another label!')) def test_element_apply_function_with_dependencies_non_dynamic(self): pinst = ParamClass() @param.depends(pinst.param.label) def get_label(label): return label + '!' applied = self.element.apply('relabel', dynamic=False, label=get_label) self.assertEqual(applied, self.element.relabel('Test!')) def test_element_apply_dynamic_with_param_method(self): pinst = ParamClass() applied = self.element.apply(lambda x, label: x.relabel(label), label=pinst.dynamic_label) # Check stream self.assertEqual(len(applied.streams), 1) stream = applied.streams[0] self.assertIsInstance(stream, ParamMethod) self.assertEqual(stream.parameterized, pinst) self.assertEqual(stream.parameters, [pinst.param.label]) # Check result self.assertEqual(applied[()], self.element.relabel('Test!')) pinst.label = 'Another label' self.assertEqual(applied[()], self.element.relabel('Another label!'))
def test_element_not_dynamic_with_param_method(self): curve = Curve([1, 2, 3]) inst = ParamClass(label='Test') applied = TestOperation(curve, dynamic=False, label=inst.dynamic_label) self.assertEqual(applied, curve.relabel('Test!'))
def test_element_not_dynamic_with_param_method(self): curve = Curve([1, 2, 3]) inst = ParamClass(label='Test') applied = TestOperation(curve, dynamic=False, label=inst.dynamic_label) self.assertEqual(applied, curve.relabel('Test!'))
def test_element_not_dynamic_with_instance_param(self): curve = Curve([1, 2, 3]) inst = ParamClass(label='Test') applied = ExampleOperation(curve, dynamic=False, label=inst.param.label) self.assertEqual(applied, curve.relabel('Test'))