@@ -123,10 +123,12 @@ def test_basic_ref(self):
123
123
def test_ref_repr (self ):
124
124
obj = C ()
125
125
ref = weakref .ref (obj )
126
- self .assertRegex (repr (ref ),
127
- rf"<weakref at 0x[0-9a-fA-F]+; "
128
- rf"to '{ C .__module__ } .{ C .__qualname__ } ' "
129
- rf"at 0x[0-9a-fA-F]+>" )
126
+ regex = (
127
+ rf"<weakref at 0x[0-9a-fA-F]+; "
128
+ rf"to '{ '' if __name__ == '__main__' else C .__module__ + '.' } { C .__qualname__ } ' "
129
+ rf"at 0x[0-9a-fA-F]+>"
130
+ )
131
+ self .assertRegex (repr (ref ), regex )
130
132
131
133
obj = None
132
134
gc_collect ()
@@ -141,10 +143,13 @@ def __name__(self):
141
143
142
144
obj2 = WithName ()
143
145
ref2 = weakref .ref (obj2 )
144
- self .assertRegex (repr (ref2 ),
145
- rf"<weakref at 0x[0-9a-fA-F]+; "
146
- rf"to '{ WithName .__module__ } .{ WithName .__qualname__ } ' "
147
- rf"at 0x[0-9a-fA-F]+ \(custom_name\)>" )
146
+ regex = (
147
+ rf"<weakref at 0x[0-9a-fA-F]+; "
148
+ rf"to '{ '' if __name__ == '__main__' else WithName .__module__ + '.' } "
149
+ rf"{ WithName .__qualname__ } ' "
150
+ rf"at 0x[0-9a-fA-F]+ +\(custom_name\)>"
151
+ )
152
+ self .assertRegex (repr (ref2 ), regex )
148
153
149
154
def test_repr_failure_gh99184 (self ):
150
155
class MyConfig (dict ):
@@ -229,10 +234,12 @@ def check(proxy):
229
234
def test_proxy_repr (self ):
230
235
obj = C ()
231
236
ref = weakref .proxy (obj , self .callback )
232
- self .assertRegex (repr (ref ),
233
- rf"<weakproxy at 0x[0-9a-fA-F]+; "
234
- rf"to '{ C .__module__ } .{ C .__qualname__ } ' "
235
- rf"at 0x[0-9a-fA-F]+>" )
237
+ regex = (
238
+ rf"<weakproxy at 0x[0-9a-fA-F]+; "
239
+ rf"to '{ '' if __name__ == '__main__' else C .__module__ + '.' } { C .__qualname__ } ' "
240
+ rf"at 0x[0-9a-fA-F]+>"
241
+ )
242
+ self .assertRegex (repr (ref ), regex )
236
243
237
244
obj = None
238
245
gc_collect ()
0 commit comments