@@ -86,25 +86,10 @@ def test_base_container_replace_direct_call():
86
86
assert type (new_container ) is type (container ) # noqa: WPS516
87
87
88
88
89
- def test_base_container_replace_direct_call_invalid_args ():
90
- """Test direct call with invalid arguments."""
89
+ def test_replace_direct_call_invalid_args ():
90
+ """Ensures calling replace directly with invalid arguments raises error ."""
91
91
container = BaseContainer (1 ) # Create instance directly
92
- # Direct call with no args should fail
93
- with pytest .raises (TypeError ):
94
- container .__replace__ () # noqa: PLC2801
95
-
96
- # Direct call with keyword args matching the name is allowed by Python,
97
- # even with /.
98
- # If uncommented, it should pass as Python allows this.
99
- # Removing commented test case for
100
- # `container.__replace__(inner_value='new')`
101
-
102
- # Direct call with extra positional args should fail
103
- with pytest .raises (TypeError ):
104
- container .__replace__ ('new' , 'extra' ) # noqa: PLC2801
105
-
106
- # Direct call with unexpected keyword args should fail
107
- with pytest .raises (TypeError ):
92
+ with pytest .raises (TypeError , match = 'unexpected keyword argument' ):
108
93
container .__replace__ (other_kwarg = 'value' ) # type: ignore[attr-defined]
109
94
110
95
@@ -148,33 +133,27 @@ def test_copy_replace(container_value: Any) -> None:
148
133
sys .version_info < (3 , 13 ),
149
134
reason = 'copy.replace requires Python 3.13+' ,
150
135
)
151
- def test_base_container_replace_via_copy_no_changes (container_value ):
152
- """Test copy.replace with no actual change in value."""
153
- container = BaseContainer ( container_value )
136
+ def test_replace_copy_no_changes (container_value ):
137
+ """
138
+ Ensures calling copy.replace without changes yields a different container.
154
139
155
- # Test with no changes is not directly possible via copy.replace with this
156
- # __replace__ implementation.
157
- # The copy.replace function itself handles the no-change case if the
158
- # object supports it, but our __replace__ requires a value.
159
- # If copy.replace is called with the same value, it should work.
160
- new_container = copy .replace (container , inner_value = container_value )
140
+ With the same inner value.
141
+ """
142
+ container = BaseContainer (container_value )
143
+ original_value = container ._inner_value # noqa: SLF001
144
+ new_container = copy .replace (container , container_value )
161
145
162
- assert new_container is not container # A new instance should be created
146
+ assert new_container is not container
147
+ assert new_container ._inner_value == original_value # noqa: SLF001
163
148
164
149
165
150
@pytest .mark .skipif (
166
151
sys .version_info < (3 , 13 ),
167
152
reason = 'copy.replace requires Python 3.13+' ,
168
153
)
169
- def test_base_container_replace_via_copy_invalid_args (container ):
170
- """Test copy.replace with invalid arguments."""
171
- # copy.replace converts the keyword 'inner_value' to a positional arg
172
- # for __replace__(self, /, inner_value), so this is valid.
173
- # Removing commented out test case for copy.replace with inner_value kwarg
174
-
175
- # However, passing other keyword arguments will fail because __replace__
176
- # doesn't accept them.
177
- with pytest .raises (TypeError ):
154
+ def test_replace_copy_invalid_args (container ):
155
+ """Ensures calling copy.replace with invalid arguments raises error."""
156
+ with pytest .raises (TypeError , match = 'unexpected keyword argument' ):
178
157
copy .replace (container , other_kwarg = 'value' ) # type: ignore[attr-defined]
179
158
180
159
# copy.replace should raise TypeError if extra positional arguments
0 commit comments