]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Use `pytest.raises(match=...)` (#1166)
authorAarni Koskela <akx@iki.fi>
Thu, 9 Jan 2025 12:44:36 +0000 (14:44 +0200)
committerGitHub <noreply@github.com>
Thu, 9 Jan 2025 12:44:36 +0000 (12:44 +0000)
tests/messages/test_pofile.py
tests/test_core.py
tests/test_numbers.py
tests/test_support.py

index ed9da78f62d0057feceebbf27a15735b0cfb76b1..ab7c7f4b4958dd095f6b45ca47cc14b40aa94e41 100644 (file)
@@ -1088,9 +1088,8 @@ def test_issue_1134(case: str, abort_invalid: bool):
 
     if abort_invalid:
         # Catalog not created, aborted with PoFileError
-        with pytest.raises(pofile.PoFileError) as excinfo:
+        with pytest.raises(pofile.PoFileError, match="missing msgstr for msgid 'foo' on 0"):
             pofile.read_po(buf, abort_invalid=True)
-        assert str(excinfo.value) == "missing msgstr for msgid 'foo' on 0"
     else:
         # Catalog is created with warning, no abort
         output = pofile.read_po(buf)
index 2dc571f5da1173d8c8add222402cc8ea405bf5bb..8aa21b4cc464e92c89f2b1a14546b6a1bdf92051 100644 (file)
@@ -296,10 +296,8 @@ def test_parse_locale():
     assert core.parse_locale('zh_Hans_CN') == ('zh', 'CN', 'Hans', None)
     assert core.parse_locale('zh-CN', sep='-') == ('zh', 'CN', None, None)
 
-    with pytest.raises(ValueError) as excinfo:
+    with pytest.raises(ValueError, match="'not_a_LOCALE_String' is not a valid locale identifier"):
         core.parse_locale('not_a_LOCALE_String')
-    assert (excinfo.value.args[0] ==
-            "'not_a_LOCALE_String' is not a valid locale identifier")
 
     assert core.parse_locale('it_IT@euro') == ('it', 'IT', None, None, 'euro')
     assert core.parse_locale('it_IT@something') == ('it', 'IT', None, None, 'something')
index 9787afd165dfb9ff6aeb13020f8d1a82eb482f6f..f3e2dec79f6b4e23f7200d2a8949b664cf7ffedf 100644 (file)
@@ -244,9 +244,8 @@ def test_list_currencies():
     assert isinstance(list_currencies(locale='fr'), set)
     assert list_currencies('fr').issuperset(['BAD', 'BAM', 'KRO'])
 
-    with pytest.raises(ValueError) as excinfo:
+    with pytest.raises(ValueError, match="expected only letters, got 'yo!'"):
         list_currencies('yo!')
-    assert excinfo.value.args[0] == "expected only letters, got 'yo!'"
 
     assert list_currencies(locale='pa_Arab') == {'PKR', 'INR', 'EUR'}
 
@@ -256,9 +255,8 @@ def test_list_currencies():
 def test_validate_currency():
     validate_currency('EUR')
 
-    with pytest.raises(UnknownCurrencyError) as excinfo:
+    with pytest.raises(UnknownCurrencyError, match="Unknown currency 'FUU'."):
         validate_currency('FUU')
-    assert excinfo.value.args[0] == "Unknown currency 'FUU'."
 
 
 def test_is_currency():
@@ -514,10 +512,8 @@ def test_format_currency_format_type():
                                     format_type="accounting")
             == '$0.00')
 
-    with pytest.raises(numbers.UnknownCurrencyFormatError) as excinfo:
-        numbers.format_currency(1099.98, 'USD', locale='en_US',
-                                format_type='unknown')
-    assert excinfo.value.args[0] == "'unknown' is not a known currency format type"
+    with pytest.raises(numbers.UnknownCurrencyFormatError, match="'unknown' is not a known currency format type"):
+        numbers.format_currency(1099.98, 'USD', locale='en_US', format_type='unknown')
 
     assert (numbers.format_currency(1099.98, 'JPY', locale='en_US')
             == '\xa51,100')
@@ -757,9 +753,8 @@ def test_parse_number():
     assert numbers.parse_number('1.099', locale='de_DE') == 1099
     assert numbers.parse_number('1٬099', locale='ar_EG', numbering_system="default") == 1099
 
-    with pytest.raises(numbers.NumberFormatError) as excinfo:
+    with pytest.raises(numbers.NumberFormatError, match="'1.099,98' is not a valid number"):
         numbers.parse_number('1.099,98', locale='de')
-    assert excinfo.value.args[0] == "'1.099,98' is not a valid number"
 
     with pytest.raises(numbers.UnsupportedNumberingSystemError):
         numbers.parse_number('1.099,98', locale='en', numbering_system="unsupported")
@@ -778,9 +773,8 @@ def test_parse_decimal():
             == decimal.Decimal('1099.98'))
     assert numbers.parse_decimal('1.099,98', locale='de') == decimal.Decimal('1099.98')
 
-    with pytest.raises(numbers.NumberFormatError) as excinfo:
+    with pytest.raises(numbers.NumberFormatError, match="'2,109,998' is not a valid decimal number"):
         numbers.parse_decimal('2,109,998', locale='de')
-    assert excinfo.value.args[0] == "'2,109,998' is not a valid decimal number"
 
 
 @pytest.mark.parametrize('string', [
index a102ae66b48a876ae6c553482a7f31d776a23c16..65147210b58c95595828570d3b619caa4bff8368 100644 (file)
@@ -299,11 +299,9 @@ class LazyProxyTestCase(unittest.TestCase):
             raise AttributeError('message')
 
         proxy = support.LazyProxy(raise_attribute_error)
-        with pytest.raises(AttributeError) as exception:
+        with pytest.raises(AttributeError, match='message'):
             _ = proxy.value
 
-        assert str(exception.value) == 'message'
-
 
 class TestFormat:
     def test_format_datetime(self, timezone_getter):