diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2016-07-25 16:23:54 +0200 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2016-07-25 16:23:57 +0200 |
commit | fd9f9538c362aacf50e4ae32ae51b15ecaf79184 (patch) | |
tree | 4626178b28a4af13bf179ed7247388a6e5844e00 /stdnum/fr/siret.py | |
parent | 5ba3a8796fccc44136d325f466ee99f6e1dfd96d (diff) |
Add extra tests for SIREN and SIRET
This adds tests for a few numbers that have been found online and allows
the dot as a seprator because those numbers were found.
It also ensures that the SIREN validation is also called for SIRET and
adds a SIRET formatting function.
Diffstat (limited to 'stdnum/fr/siret.py')
-rw-r--r-- | stdnum/fr/siret.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/stdnum/fr/siret.py b/stdnum/fr/siret.py index ab7d59f..22efe20 100644 --- a/stdnum/fr/siret.py +++ b/stdnum/fr/siret.py @@ -38,6 +38,8 @@ InvalidChecksum: ... '44 732 829 320' >>> to_tva('73282932000074') '44732829320' +>>> format('73282932000074') +'732 829 320 00074' """ from stdnum import luhn @@ -49,7 +51,7 @@ from stdnum.util import clean def compact(number): """Convert the number to the minimal representation. This strips the number of any valid separators and removes surrounding whitespace.""" - return clean(number, ' ').strip() + return clean(number, ' .').strip() def validate(number): @@ -61,6 +63,7 @@ def validate(number): if len(number) != 14: raise InvalidLength() luhn.validate(number) + siren.validate(number[:9]) return number @@ -95,3 +98,9 @@ def to_tva(number): error checking digits. """ return siren.to_tva(to_siren(number)) + + +def format(number, separator=' '): + """Reformat the passed number to the standard format.""" + number = compact(number) + return separator.join((number[0:3], number[3:6], number[6:9], number[9:])) |