|
2 | 2 | import pickle |
3 | 3 | import re |
4 | 4 | import timeit |
| 5 | +import warnings |
5 | 6 | from typing import Any |
6 | 7 |
|
7 | 8 | import pytest |
@@ -332,10 +333,61 @@ def test_none_empty_attribute_string_formatting(self) -> None: |
332 | 333 | self.assertEqual('', str(hn), hn) |
333 | 334 |
|
334 | 335 | def test_add_constant_with_explicit_encoding(self) -> None: |
| 336 | + # bytes input is deprecated (#245), still supported until 2.0 |
335 | 337 | c = Constants() |
336 | | - c.titles.add_with_encoding(b'b\351ck', encoding='latin_1') |
| 338 | + with pytest.deprecated_call(): |
| 339 | + c.titles.add_with_encoding(b'b\351ck', encoding='latin_1') |
337 | 340 | self.assertIn('béck', c.titles) |
338 | 341 |
|
| 342 | + def test_set_manager_add_bytes_emits_deprecation_warning(self) -> None: |
| 343 | + # bytes elements are removed in 2.0 (#245); the caller should decode |
| 344 | + sm = SetManager(['dr']) |
| 345 | + with pytest.deprecated_call(match="decode"): |
| 346 | + sm.add(b'esq') # type: ignore[arg-type] # deliberately deprecated input |
| 347 | + self.assertIn('esq', sm) |
| 348 | + |
| 349 | + def test_set_manager_add_str_does_not_warn(self) -> None: |
| 350 | + sm = SetManager(['dr']) |
| 351 | + with warnings.catch_warnings(): |
| 352 | + warnings.simplefilter("error") |
| 353 | + sm.add('esq') |
| 354 | + self.assertIn('esq', sm) |
| 355 | + |
| 356 | + def test_set_manager_call_emits_deprecation_warning(self) -> None: |
| 357 | + # __call__ hands out the raw underlying set, bypassing normalization |
| 358 | + # and cache invalidation; removed in 2.0 (#243) |
| 359 | + sm = SetManager(['dr']) |
| 360 | + with pytest.deprecated_call(match="set"): |
| 361 | + elements = sm() |
| 362 | + self.assertEqual(elements, {'dr'}) |
| 363 | + |
| 364 | + def test_set_manager_discard_ignores_missing_without_warning(self) -> None: |
| 365 | + sm = SetManager(['dr', 'mr']) |
| 366 | + with warnings.catch_warnings(): |
| 367 | + warnings.simplefilter("error") |
| 368 | + result = sm.discard('nope').discard('Dr.') # normalizes like remove() |
| 369 | + self.assertIs(result, sm) |
| 370 | + self.assertEqual(set(sm), {'mr'}) |
| 371 | + |
| 372 | + def test_set_manager_discard_invalidates_cached_union(self) -> None: |
| 373 | + c = Constants() |
| 374 | + self.assertIn('hon', c.suffixes_prefixes_titles) # prime the cache |
| 375 | + c.titles.discard('hon') |
| 376 | + self.assertNotIn('hon', c.suffixes_prefixes_titles) |
| 377 | + |
| 378 | + def test_set_manager_remove_missing_member_emits_deprecation_warning(self) -> None: |
| 379 | + # ignore-missing remove() becomes KeyError in 2.0 (#243); discard() |
| 380 | + # is the intentional ignore-missing spelling |
| 381 | + sm = SetManager(['dr']) |
| 382 | + with pytest.deprecated_call(match="discard"): |
| 383 | + sm.remove('nope') |
| 384 | + self.assertEqual(set(sm), {'dr'}) |
| 385 | + # removing a present member stays silent |
| 386 | + with warnings.catch_warnings(): |
| 387 | + warnings.simplefilter("error") |
| 388 | + sm.remove('dr') |
| 389 | + self.assertEqual(len(sm), 0) |
| 390 | + |
339 | 391 | def test_pickle_roundtrip_preserves_customizations(self) -> None: |
340 | 392 | """A pickled Constants must restore its customized collections. |
341 | 393 |
|
@@ -622,7 +674,8 @@ def test_suffixes_prefixes_titles_reflects_add_with_encoding(self) -> None: |
622 | 674 | """add_with_encoding must invalidate the cache like add()/remove() do.""" |
623 | 675 | c = Constants() |
624 | 676 | _ = c.suffixes_prefixes_titles # prime the cache |
625 | | - c.titles.add_with_encoding(b'b\351ck', encoding='latin_1') |
| 677 | + with pytest.deprecated_call(): # bytes input deprecated (#245) |
| 678 | + c.titles.add_with_encoding(b'b\351ck', encoding='latin_1') |
626 | 679 | self.assertIn('béck', c.suffixes_prefixes_titles) |
627 | 680 |
|
628 | 681 | def test_suffixes_prefixes_titles_reflects_replaced_manager(self) -> None: |
|
0 commit comments