Skip to content

Commit

Permalink
Add a couple of usage tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Koshkin committed Sep 30, 2018
1 parent 72ff503 commit 40a2a9a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
4 changes: 2 additions & 2 deletions benchmarks/overhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def pivot_bench_set():


# Check with validation enabled
WatchMe.is_active = True
WatchMe.keep_eye_on_me = True
runner.bench_func("set: validation enabled", bench_set)

# Check with validation disabled
WatchMe.is_active = False
WatchMe.keep_eye_on_me = False
runner.bench_func("set: validation disabled", bench_set)

# Check with a plain type with no watch at all
Expand Down
33 changes: 33 additions & 0 deletions tests/test_usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import py.test


import watch


def test_pridicated_bind_to_watchme():
"""Tests, that using a watch's validators inside a class, that not being
inherited from WatchMe base class generates an error.
"""

with py.test.raises(TypeError):

class SomeClass:
foo = watch.builtins.Whatever

s = SomeClass()
s.foo = 10


def test_pridicated_bind_to_watchme():
"""Tests, that AttributeError is not broken by introducing watch lib.
"""

with py.test.raises(AttributeError):

class SomeClass(watch.WatchMe):
foo = watch.builtins.Whatever

s = SomeClass()
s.foo


2 changes: 1 addition & 1 deletion watch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __get__(self, passed_instance, passed_type=None):
attribute_error = AttributeError(
"%s object has no attribute '%s'." %
(
type(passed_instance).__qualname__, repr(self.field_name)
type(passed_instance).__qualname__, self.field_name
)
)
raise attribute_error from key_error
Expand Down

0 comments on commit 40a2a9a

Please sign in to comment.