@@ -38,6 +38,60 @@ def teardown_module():
3838 log .setLevel (original_logging_level [0 ])
3939
4040
41+ class TestDunder (unittest .TestCase ):
42+
43+ def test_dns_text_repr (self ):
44+ # There was an issue on Python 3 that prevented DNSText's repr
45+ # from working when the text was longer than 10 bytes
46+ text = DNSText ('irrelevant' , None , 0 , 0 , b'12345678901' )
47+ repr (text )
48+
49+ text = DNSText ('irrelevant' , None , 0 , 0 , b'123' )
50+ repr (text )
51+
52+ def test_dns_hinfo_repr_eq (self ):
53+ hinfo = DNSHinfo ('irrelevant' , r ._TYPE_HINFO , 0 , 0 , 'cpu' , 'os' )
54+ assert hinfo == hinfo
55+ repr (hinfo )
56+
57+ def test_dns_pointer_repr (self ):
58+ pointer = r .DNSPointer (
59+ 'irrelevant' , r ._TYPE_PTR , r ._CLASS_IN , r ._DNS_TTL , '123' )
60+ repr (pointer )
61+
62+ def test_dns_address_repr (self ):
63+ address = r .DNSAddress ('irrelevant' , r ._TYPE_SOA , r ._CLASS_IN , 1 , b'a' )
64+ repr (address )
65+
66+ def test_dns_question_repr (self ):
67+ question = r .DNSQuestion (
68+ 'irrelevant' , r ._TYPE_SRV , r ._CLASS_IN | r ._CLASS_UNIQUE )
69+ repr (question )
70+ assert not question != question
71+
72+ def test_dns_service_repr (self ):
73+ service = r .DNSService (
74+ 'irrelevant' , r ._TYPE_SRV , r ._CLASS_IN , r ._DNS_TTL , 0 , 0 , 80 , b'a' )
75+ repr (service )
76+
77+ def test_dns_record_abc (self ):
78+ record = r .DNSRecord ('irrelevant' , r ._TYPE_SRV , r ._CLASS_IN , r ._DNS_TTL )
79+ self .assertRaises (r .AbstractMethodException , record .__eq__ , record )
80+ self .assertRaises (r .AbstractMethodException , record .write , None )
81+
82+ def test_service_info_dunder (self ):
83+ type_ = "_test-srvc-type._tcp.local."
84+ name = "xxxyyy"
85+ registration_name = "%s.%s" % (name , type_ )
86+ info = ServiceInfo (
87+ type_ , registration_name ,
88+ socket .inet_aton ("10.0.1.2" ), 80 , 0 , 0 ,
89+ None , "ash-2.local." )
90+
91+ assert not info != info
92+ repr (info )
93+
94+
4195class PacketGeneration (unittest .TestCase ):
4296
4397 def test_parse_own_packet_simple (self ):
@@ -364,7 +418,6 @@ def test_integration_with_subtype_and_listener(self):
364418 try :
365419 service_types = ZeroconfServiceTypes .find (
366420 interfaces = ['127.0.0.1' ], timeout = 0.5 )
367- # print(service_types)
368421 assert discovery_type in service_types
369422 service_types = ZeroconfServiceTypes .find (
370423 zc = zeroconf_registrar , timeout = 0.5 )
@@ -395,8 +448,9 @@ def add_service(self, zeroconf, type, name):
395448 def remove_service (self , zeroconf , type , name ):
396449 service_removed .set ()
397450
451+ listener = MyListener ()
398452 zeroconf_browser = Zeroconf (interfaces = ['127.0.0.1' ])
399- zeroconf_browser .add_service_listener (subtype , MyListener () )
453+ zeroconf_browser .add_service_listener (subtype , listener )
400454
401455 properties = dict (
402456 prop_none = None ,
@@ -445,6 +499,7 @@ def remove_service(self, zeroconf, type, name):
445499 assert service_removed .is_set ()
446500 finally :
447501 zeroconf_registrar .close ()
502+ zeroconf_browser .remove_service_listener (listener )
448503 zeroconf_browser .close ()
449504
450505
@@ -482,10 +537,3 @@ def on_service_state_change(zeroconf, service_type, state_change, name):
482537 zeroconf_registrar .close ()
483538 browser .cancel ()
484539 zeroconf_browser .close ()
485-
486-
487- def test_dnstext_repr_works ():
488- # There was an issue on Python 3 that prevented DNSText's repr
489- # from working when the text was longer than 10 bytes
490- text = DNSText ('irrelevant' , None , 0 , 0 , b'12345678901' )
491- repr (text )
0 commit comments