Skip to content

Commit

Permalink
Fix and unit test for batch_watch context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 8, 2019
1 parent 5345311 commit dca2a62
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion param/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from .parameterized import Parameterized, Parameter, String, \
descendents, ParameterizedFunction, ParamOverrides
from .parameterized import (depends, output, logging_level, # noqa: api import
shared_parameters, instance_descriptor)
shared_parameters, instance_descriptor, batch_watch)

from collections import OrderedDict
from numbers import Real
Expand Down
2 changes: 1 addition & 1 deletion param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def batch_watch(parameterized, run=True):
finally:
parameterized.param._BATCH_WATCH = BATCH_WATCH
if run and not BATCH_WATCH:
obj.param._batch_call_watchers()
parameterized.param._batch_call_watchers()


def classlist(class_):
Expand Down
23 changes: 23 additions & 0 deletions tests/API1/testwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,29 @@ def test_simple_batched_watch_setattr(self):
self.assertEqual(args[0].new, 3)
self.assertEqual(args[0].type, 'changed')

def test_batched_watch_context_manager(self):

accumulator = Accumulator()

obj = SimpleWatchExample()
obj.param.watch(accumulator, ['a','b'])

with param.batch_watch(obj):
obj.a = 2
obj.b = 3

self.assertEqual(accumulator.call_count(), 1)
args = accumulator.args_for_call(0)

self.assertEqual(len(args), 2)
self.assertEqual(args[0].name, 'a')
self.assertEqual(args[0].old, 0)
self.assertEqual(args[0].new, 2)
self.assertEqual(args[0].type, 'changed')
self.assertEqual(args[1].name, 'b')
self.assertEqual(args[1].old, 0)
self.assertEqual(args[1].new, 3)
self.assertEqual(args[1].type, 'changed')

def test_nested_batched_watch_setattr(self):

Expand Down

0 comments on commit dca2a62

Please sign in to comment.