From a604900d4311adb9824da78378c60bf8bdf5b2d5 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Tue, 12 May 2020 22:33:49 +0200 Subject: [PATCH] Add tests for deep copying watchers --- tests/API1/testwatch.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/tests/API1/testwatch.py b/tests/API1/testwatch.py index 34cb8fb59..6b0111729 100644 --- a/tests/API1/testwatch.py +++ b/tests/API1/testwatch.py @@ -1,14 +1,15 @@ """ Unit test for watch mechanism """ -from . import API1TestCase - -from .utils import MockLoggingHandler +import copy import param from param.parameterized import discard_events +from . import API1TestCase +from .utils import MockLoggingHandler + class Accumulator(object): @@ -37,6 +38,9 @@ class SimpleWatchExample(param.Parameterized): c = param.Parameter(default=0) d = param.Integer(default=0) + def method(self, event): + self.b = self.a * 2 + class SimpleWatchSubclass(SimpleWatchExample): pass @@ -466,6 +470,18 @@ def test_nested_batched_watch_not_onlychanged(self): self.assertEqual(args[1].new, 0) self.assertEqual(args[1].type, 'set') + def test_watch_deepcopy(self): + obj = SimpleWatchExample() + + obj.param.watch(obj.method, ['a']) + + copied = copy.deepcopy(obj) + + copied.a = 2 + + self.assertEqual(copied.b, 4) + self.assertEqual(obj.b, 0) + class TestWatchMethod(API1TestCase): @@ -523,6 +539,15 @@ def test_depends_with_watch_on_subclass(self): obj.b = 3 self.assertEqual(obj.c, 6) + def test_watcher_method_deepcopy(self): + obj = WatchMethodExample(b=5) + + copied = copy.deepcopy(obj) + + copied.b = 11 + self.assertEqual(copied.b, 10) + self.assertEqual(obj.b, 5) + class TestWatchValues(API1TestCase):