Skip to content

Commit

Permalink
Merge pull request #14 from Revolution1/fix/delete-event
Browse files Browse the repository at this point in the history
Fix/delete event
  • Loading branch information
Revolution1 committed Mar 20, 2018
2 parents 3f7cd72 + 8a698ca commit 5b56638
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 16 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ deploy:
on:
tags: true
branch: master
repo: Revolution1/etcd3-py
python:
- 3.6
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ Notice: The authentication header through gRPC-JSON-Gateway only supported in [e
$ pip install etcd3-py
```

---

**Sync Client**
```python
>>> from etcd3 import Client
Expand Down
11 changes: 9 additions & 2 deletions etcd3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .client import Client

AioClient = None
if six.PY3: # pragma: no cover
if six.PY3: # pragma: no cover
from .aio_client import AioClient

__all__.extend([
Expand All @@ -19,7 +19,14 @@
])

from .stateful import Txn
from .stateful import Watcher
from .stateful import Lease

from .stateful.watch import EventType

__all__.extend([
'Txn'
'Txn',
'Watcher',
'Lease',
'EventType'
])
4 changes: 2 additions & 2 deletions etcd3/stateful/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __repr__(self):
class Event(KeyValue):
def __init__(self, data):
super(Event, self).__init__(data.kv._data)
self.type = getattr(data, 'type', None)
self.type = getattr(data, 'type', EventType.PUT) # default is PUT
self._data['type'] = self.type
self.prev_kv = None
if 'prev_kv' in data:
Expand Down Expand Up @@ -154,7 +154,7 @@ def match_func(e):
return regex.match(key)
elif match is None:
match_func = lambda e: True
elif isinstance(match, EventType): # pragma: no cover
elif isinstance(match, EventType):
match_func = lambda e: e.type == match
else:
raise TypeError('expect match to be one of string, EventType, callable got %s' % type(match))
Expand Down
2 changes: 1 addition & 1 deletion etcd3/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__author__ = 'Renjie Cai'
__email__ = 'revol.cai@gmail.com'
__version__ = '0.1.1'
__version__ = '0.1.2'
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.1
current_version = 0.1.2
commit = False
tag = False

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

setup(
name='etcd3-py',
version='0.1.1',
version='0.1.2',
description="Python client for etcd v3 (Using gRPC-JSON-Gateway)",
long_description=readme + '\n\n' + history,
author="Renjie Cai",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lease_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_lease_util(client):
lease.grant()
lease.keepalive(keep_cb=keep_cb, cancel_cb=cancel_cb)
lease.cancel_keepalive()
time.sleep(TTL / 3.0)
time.sleep(TTL)
assert keep_cb.called
assert cancel_cb.called

Expand Down
14 changes: 9 additions & 5 deletions tests/test_watch_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from etcd3 import Client
from etcd3 import Client, EventType
from .envs import protocol, host, port
from .etcd_go_cli import etcdctl, NO_ETCD_SERVICE

Expand All @@ -25,11 +25,13 @@ def test_watcher(client):
foo_list = []
fizz_list = []
all_list = []
del_list = []
w.onEvent(lambda e: e.key == b'foo', lambda e: foo_list.append(e))
w.onEvent('fiz.', lambda e: fizz_list.append(e))
w.onEvent(EventType.DELETE, lambda e: del_list.append(e))
w.onEvent(lambda e: all_list.append(e))

assert len(w.callbacks) == 3
assert len(w.callbacks) == 4

w.runDaemon()
# with pytest.raises(RuntimeError):
Expand All @@ -42,6 +44,7 @@ def test_watcher(client):

etcdctl('put foo bar')
etcdctl('put foo bar')
etcdctl('del foo')
etcdctl('put fizz buzz')
etcdctl('put fizz buzz')
etcdctl('put fizz buzz')
Expand All @@ -53,9 +56,10 @@ def test_watcher(client):
assert not w.watching
assert not w._thread.is_alive()

assert len(foo_list) == 2
assert len(foo_list) == 3
assert len(fizz_list) == 3
assert len(all_list) == 5
assert len(del_list) == 1
assert len(all_list) == 6

etcdctl('put foo bar')
etcdctl('put fizz buzz')
Expand All @@ -69,7 +73,7 @@ def test_watcher(client):

assert len(foo_list) == 1
assert len(fizz_list) == 1
assert len(all_list) == 7
assert len(all_list) == 8

w.clear_callbacks()
assert len(w.callbacks) == 0
Expand Down

0 comments on commit 5b56638

Please sign in to comment.