From 05caf5690457be9b5e9ea2d64243bf2067738899 Mon Sep 17 00:00:00 2001 From: Cedric Conday Date: Wed, 1 Jul 2026 19:07:54 +0000 Subject: [PATCH 1/4] fix(no_NO): compute Norwegian MOD11 check digit so iban() passes stdnum validation --- faker/providers/bank/no_NO/__init__.py | 12 ++++++++++++ tests/providers/test_bank.py | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/faker/providers/bank/no_NO/__init__.py b/faker/providers/bank/no_NO/__init__.py index 7e5ff16690..7609c7ab47 100644 --- a/faker/providers/bank/no_NO/__init__.py +++ b/faker/providers/bank/no_NO/__init__.py @@ -1,3 +1,5 @@ +import re + from .. import Provider as BankProvider @@ -6,3 +8,13 @@ class Provider(BankProvider): bban_format = "###########" country_code = "NO" + + def bban(self) -> str: + """Generate a valid BBAN with correct MOD11 check digit.""" + for _ in range(100): + first_10 = self.numerify("##########") + weights = (6, 7, 8, 9, 4, 5, 6, 7, 8, 9) + check = sum(w * int(d) for w, d in zip(weights, first_10)) % 11 + if check != 10: + return first_10 + str(check) + return first_10 + "0" diff --git a/tests/providers/test_bank.py b/tests/providers/test_bank.py index 20c018271e..4ae132c1f3 100644 --- a/tests/providers/test_bank.py +++ b/tests/providers/test_bank.py @@ -409,6 +409,14 @@ def test_iban(self, faker, num_samples): assert iban[:2] == NoNoBankProvider.country_code assert re.fullmatch(r"\d{2}\d{11}", iban[2:]) + def test_iban_stdnum(self, faker, num_samples): + try: + from stdnum import iban as iban_validator + except ImportError: + pytest.skip("stdnum not available") + for _ in range(num_samples): + iban_validator.validate(faker.iban()) + class TestPlPl: """Test pl_PL bank provider""" From e9323743e3eead0876bbd1390faba113a250ed2c Mon Sep 17 00:00:00 2001 From: Cedric Conday <277679649+CedricConday@users.noreply.github.com> Date: Thu, 16 Jul 2026 07:17:30 +0000 Subject: [PATCH 2/4] fix(no_NO): remove unused `re` import (flake8 F401) --- faker/providers/bank/no_NO/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/faker/providers/bank/no_NO/__init__.py b/faker/providers/bank/no_NO/__init__.py index 7609c7ab47..3ef6295f15 100644 --- a/faker/providers/bank/no_NO/__init__.py +++ b/faker/providers/bank/no_NO/__init__.py @@ -1,5 +1,3 @@ -import re - from .. import Provider as BankProvider From 7c7df46db2e0396578dc98517505d469e07409bf Mon Sep 17 00:00:00 2001 From: Cedric Conday <277679649+CedricConday@users.noreply.github.com> Date: Sun, 2 Aug 2026 16:25:01 +0000 Subject: [PATCH 3/4] test(no_NO): require python-stdnum instead of skipping when absent Adds python-stdnum to dev-requirements and hoists the import, so the IBAN validation test always runs rather than silently skipping on machines without it. Per review feedback on #2415. Co-Authored-By: Claude Assisted-by: Claude Opus 5 --- dev-requirements.txt | 1 + tests/providers/test_bank.py | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index a4784a4ee9..3a6c5c0606 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -10,6 +10,7 @@ mypy-extensions>=1.0.0 mypy>=1.15.0,<2 packaging>=25.0 pytest>=6.0.1 +python-stdnum>=1.20 setuptools>=80.9.0 tox>=4.24.1 twine>=6.2.0 diff --git a/tests/providers/test_bank.py b/tests/providers/test_bank.py index 4ae132c1f3..d2f37bb57b 100644 --- a/tests/providers/test_bank.py +++ b/tests/providers/test_bank.py @@ -2,6 +2,8 @@ import pytest +from stdnum import iban as iban_validator + from faker.providers.bank import Provider as BankProvider from faker.providers.bank.az_AZ import Provider as AzAzBankProvider from faker.providers.bank.cs_CZ import Provider as CsCZBankProvider @@ -410,10 +412,6 @@ def test_iban(self, faker, num_samples): assert re.fullmatch(r"\d{2}\d{11}", iban[2:]) def test_iban_stdnum(self, faker, num_samples): - try: - from stdnum import iban as iban_validator - except ImportError: - pytest.skip("stdnum not available") for _ in range(num_samples): iban_validator.validate(faker.iban()) From 5ec2f289ac31c01713c323871ea718397f178b6d Mon Sep 17 00:00:00 2001 From: Cedric Conday <277679649+CedricConday@users.noreply.github.com> Date: Sun, 2 Aug 2026 16:51:50 +0000 Subject: [PATCH 4/4] test: add python-stdnum to tox deps so CI can import it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dev-requirements.txt is not what CI installs — the workflow runs tox, and [testenv] carries its own deps list. Without this the module-level stdnum import fails collection for the whole test_bank.py module. Co-Authored-By: Claude Assisted-by: Claude Opus 5 --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index c228883d37..0a21beb6d3 100644 --- a/tox.ini +++ b/tox.ini @@ -7,6 +7,7 @@ deps = coverage>=5.2 freezegun pytest>=6.0.1 + python-stdnum>=1.20 ukpostcodeparser>=1.1.1 validators>=0.13.0 sphinx>=2.4,<3.0