Skip to content

Commit 0a0f7e0

Browse files
committed
Fix regression introduced with Python 3 compat
1 parent b8cfc79 commit 0a0f7e0

2 files changed

Lines changed: 49 additions & 5 deletions

File tree

test_zeroconf.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
""" Unit tests for zeroconf.py """
44

5-
import zeroconf as r
5+
import socket
66
import struct
77
import unittest
8+
from time import sleep
89

9-
from zeroconf import byte_ord, xrange
10+
import zeroconf as r
11+
from zeroconf import byte_ord, ServiceBrowser, ServiceInfo, xrange, Zeroconf
1012

1113

1214
class PacketGeneration(unittest.TestCase):
@@ -121,3 +123,45 @@ class Framework(unittest.TestCase):
121123
def testLaunchAndClose(self):
122124
rv = r.Zeroconf()
123125
rv.close()
126+
127+
128+
def test_integration():
129+
130+
services = set()
131+
132+
class Listener(object):
133+
134+
def removeService(self, zeroconf, type_, name):
135+
print('remove')
136+
services.remove((type_, name))
137+
138+
def addService(self, zeroconf, type_, name):
139+
print('add')
140+
services.add((type_, name))
141+
142+
type_ = "_http._tcp.local."
143+
144+
zeroconf_browser = Zeroconf()
145+
listener = Listener()
146+
browser = ServiceBrowser(zeroconf_browser, type_, listener)
147+
148+
zeroconf_registrar = Zeroconf()
149+
desc = {'path': '/~paulsm/'}
150+
name = "xxxyyy.%s" % type_
151+
info = ServiceInfo(
152+
type_, name,
153+
socket.inet_aton("10.0.1.2"), 80, 0, 0,
154+
desc, "ash-2.local.")
155+
zeroconf_registrar.registerService(info)
156+
157+
# TODO replace those blind sleeps with events
158+
sleep(2)
159+
try:
160+
assert (type_, name) in services, services
161+
zeroconf_registrar.unregisterService(info)
162+
sleep(2)
163+
assert (type_, name) not in services, services
164+
finally:
165+
zeroconf_registrar.close()
166+
browser.cancel()
167+
zeroconf_browser.close()

zeroconf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,9 @@ class DNSText(DNSRecord):
381381

382382
"""A DNS text record"""
383383

384-
def __init__(self, name, type, clazz, ttl, text):
385-
assert isinstance(text, bytes)
386-
DNSRecord.__init__(self, name, type, clazz, ttl)
384+
def __init__(self, name, type_, clazz, ttl, text):
385+
assert isinstance(text, (bytes, type(None)))
386+
DNSRecord.__init__(self, name, type_, clazz, ttl)
387387
self.text = text
388388

389389
def write(self, out):

0 commit comments

Comments
 (0)