Skip to content

Commit

Permalink
Add tests for deep copying watchers
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed May 12, 2020
1 parent 4ced6b1 commit a604900
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions tests/API1/testwatch.py
Original file line number Diff line number Diff line change
@@ -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):

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):

Expand Down Expand Up @@ -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):

Expand Down

0 comments on commit a604900

Please sign in to comment.