@@ -38,6 +38,60 @@ def teardown_module():
38
38
log .setLevel (original_logging_level [0 ])
39
39
40
40
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
+
41
95
class PacketGeneration (unittest .TestCase ):
42
96
43
97
def test_parse_own_packet_simple (self ):
@@ -364,7 +418,6 @@ def test_integration_with_subtype_and_listener(self):
364
418
try :
365
419
service_types = ZeroconfServiceTypes .find (
366
420
interfaces = ['127.0.0.1' ], timeout = 0.5 )
367
- # print(service_types)
368
421
assert discovery_type in service_types
369
422
service_types = ZeroconfServiceTypes .find (
370
423
zc = zeroconf_registrar , timeout = 0.5 )
@@ -395,8 +448,9 @@ def add_service(self, zeroconf, type, name):
395
448
def remove_service (self , zeroconf , type , name ):
396
449
service_removed .set ()
397
450
451
+ listener = MyListener ()
398
452
zeroconf_browser = Zeroconf (interfaces = ['127.0.0.1' ])
399
- zeroconf_browser .add_service_listener (subtype , MyListener () )
453
+ zeroconf_browser .add_service_listener (subtype , listener )
400
454
401
455
properties = dict (
402
456
prop_none = None ,
@@ -445,6 +499,7 @@ def remove_service(self, zeroconf, type, name):
445
499
assert service_removed .is_set ()
446
500
finally :
447
501
zeroconf_registrar .close ()
502
+ zeroconf_browser .remove_service_listener (listener )
448
503
zeroconf_browser .close ()
449
504
450
505
@@ -482,10 +537,3 @@ def on_service_state_change(zeroconf, service_type, state_change, name):
482
537
zeroconf_registrar .close ()
483
538
browser .cancel ()
484
539
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