@@ -492,9 +492,9 @@ def patch_locale(self, monkeypatch: pytest.MonkeyPatch) -> None:
492
492
orig_getlocal = locale .getlocale
493
493
494
494
def fake_getlocale (category : int ) -> Tuple [Optional [str ], Optional [str ]]:
495
- """Fake getlocale() that always report zh_Hant."""
495
+ """Fake getlocale() that always reports zh_Hant for LC_MESSASGES ."""
496
496
result = orig_getlocal (category )
497
- if category == locale . LC_MESSAGES :
497
+ if category == getattr ( locale , " LC_MESSAGES" , None ) :
498
498
return "zh_Hant" , result [1 ]
499
499
return result
500
500
@@ -541,6 +541,10 @@ def test_config_without_key(
541
541
assert not caplog .records
542
542
assert str (exc .context ) == self .default_text
543
543
544
+ @pytest .mark .skipif (
545
+ sys .platform == "win32" ,
546
+ reason = "Localization disabled on Windows" ,
547
+ )
544
548
@pytest .mark .parametrize (
545
549
"config, expected" ,
546
550
[
@@ -594,3 +598,57 @@ def test_config_canonical(
594
598
exc = ExternallyManagedEnvironment .from_config (marker )
595
599
assert not caplog .records
596
600
assert str (exc .context ) == expected
601
+
602
+ @pytest .mark .skipif (
603
+ sys .platform != "win32" ,
604
+ reason = "Non-Windows should implement localization" ,
605
+ )
606
+ @pytest .mark .parametrize (
607
+ "config" ,
608
+ [
609
+ pytest .param (
610
+ """\
611
+ [externally-managed]
612
+ Error = 最後
613
+ Error-en = English
614
+ Error-zh = 中文
615
+ Error-zh_Hant = 繁體
616
+ Error-zh_Hans = 简体
617
+ """ ,
618
+ id = "full" ,
619
+ ),
620
+ pytest .param (
621
+ """\
622
+ [externally-managed]
623
+ Error = 最後
624
+ Error-en = English
625
+ Error-zh = 中文
626
+ Error-zh_Hans = 简体
627
+ """ ,
628
+ id = "no-variant" ,
629
+ ),
630
+ pytest .param (
631
+ """\
632
+ [externally-managed]
633
+ Error = 最後
634
+ Error-en = English
635
+ """ ,
636
+ id = "fallback" ,
637
+ ),
638
+ ],
639
+ )
640
+ def test_config_canonical_no_localization (
641
+ self ,
642
+ caplog : pytest .LogCaptureFixture ,
643
+ marker : pathlib .Path ,
644
+ config : str ,
645
+ ) -> None :
646
+ marker .write_text (
647
+ textwrap .dedent (config ),
648
+ encoding = "utf8" ,
649
+ )
650
+
651
+ with caplog .at_level (logging .WARNING , "pip._internal.exceptions" ):
652
+ exc = ExternallyManagedEnvironment .from_config (marker )
653
+ assert not caplog .records
654
+ assert str (exc .context ) == "最後"
0 commit comments