test_cr_cpj.doctest - more detailed doctests for stdnum.cr.cpj module

Copyright (C) 2019 Leandro Regueiro

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA


This file contains more detailed doctests for the stdnum.cr.cpj module. It
tries to test more corner cases and detailed functionality that is not really
useful as module documentation.

>>> from stdnum.cr import cpj


Tests for some corner cases.

>>> cpj.validate('3-101-999999')
'3101999999'
>>> cpj.validate('3 010 179406')
'3010179406'
>>> cpj.validate('3-101-121231')
'3101121231'
>>> cpj.format('3101015462')
'3-101-015462'
>>> cpj.validate('3-102-10536')
Traceback (most recent call last):
    ...
InvalidLength: ...
>>> cpj.validate('3-102-ABCDEF')
Traceback (most recent call last):
    ...
InvalidFormat: ...
>>> cpj.validate('1-101-079297')  # Invalid class (first digit)
Traceback (most recent call last):
    ...
InvalidComponent: ...
>>> cpj.validate('2-511-079297')  # Invalid type (digits 2, 3, 4) for class 2
Traceback (most recent call last):
    ...
InvalidComponent: ...
>>> cpj.validate('3-121-176017')  # Invalid type for class 3
Traceback (most recent call last):
    ...
InvalidComponent: ...
>>> cpj.validate('4-001-123456')  # Invalid type for class 4
Traceback (most recent call last):
    ...
InvalidComponent: ...
>>> cpj.validate('5-000-123456')  # Invalid type for class 5
Traceback (most recent call last):
    ...
InvalidComponent: ...


These have been found online and should all be valid numbers.

>>> numbers = '''
...
... 2-100-042002
... 2-200-042153
... 2-300-042155
... 2-400-042156
... 3 010 179406
... 3-002-045556
... 3-002-670350
... 3-003-051878
... 3-003-066718
... 3-004-481707
... 3-005-045142
... 3-006-087315
... 3-006-227840
... 3-007-317912
... 3-007-655746
... 3-008-218945
... 3-009-045021
... 3-009-117444
... 3-010-045209
... 3-010-418099
... 3-011-051123
... 3-011-111229
... 3-012-000585
... 3-012-629125
... 3-012-631203
... 3-012-659212
... 3-012-682004
... 3-012-702749
... 3-013-337748
... 3-013-468741
... 3-014-042088
... 3-014-042116
... 3-101-000046
... 3-101-180014
... 3-101-230903
... 3-101-232523
... 3-101-232928
... 3-101-236840
... 3-101-237754
... 3-101-240266
... 3-101-240940
... 3-101-245331
... 3-101-245508
... 3-101-247096
... 3-101-247476
... 3-101-249874
... 3-101-250372
... 3-101-252630
... 3-101-256279
... 3-101-256760
... 3-101-259465
... 3-101-259663
... 3-101-259674
... 3-101-260767
... 3-101-262681
... 3-101-263222
... 3-101-263317
... 3-101-263799
... 3-101-263976
... 3-101-266555
... 3-101-267388
... 3-101-267648
... 3-101-274629
... 3-101-274881
... 3-101-275421
... 3-101-278412
... 3-101-279147
... 3-101-279791
... 3-101-280790
... 3-101-282414
... 3-101-282787
... 3-101-285061
... 3-101-287067
... 3-101-289334
... 3-101-290860
... 3-101-292498
... 3-101-293230
... 3-101-294732
... 3-101-295808
... 3-101-296082
... 3-101-296856
... 3-101-301495
... 3-101-304441
... 3-101-304550
... 3-101-305224
... 3-101-305227
... 3-101-306858
... 3-101-308183
... 3-101-316152
... 3-101-318274
... 3-101-319136
... 3-101-319175
... 3-101-319275
... 3-101-320716
... 3-101-321702
... 3-101-322639
... 3-101-323383
... 3-101-325528
... 3-101-328708
... 3-101-328989
... 3-101-329524
... 3-101-332402
... 3-101-332724
... 3-101-333084
... 3-101-333318
... 3-101-333545
... 3-101-334264
... 3-101-334668
... 3-101-334968
... 3-101-335191
... 3-101-335649
... 3-101-338742
... 3-101-338884
... 3-101-340184
... 3-101-340254
... 3-101-341854
... 3-101-341966
... 3-101-342669
... 3-101-344336
... 3-101-347395
... 3-101-349806
... 3-101-350808
... 3-101-351360
... 3-101-351794
... 3-101-351901
... 3-101-352094
... 3-101-355875
... 3-101-357417
... 3-101-357679
... 3-101-357705
... 3-101-358300
... 3-101-359999
... 3-101-360891
... 3-101-366653
... 3-101-368803
... 3-101-370997
... 3-101-372304
... 3-101-380046
... 3-101-380490
... 3-101-381068
... 3-101-381976
... 3-101-385240
... 3-101-386582
... 3-101-386705
... 3-101-387699
... 3-101-398343
... 3-101-398763
... 3-101-400625
... 3-101-405354
... 3-101-405407
... 3-101-756187
... 3-102-010536
... 3-102-231503
... 3-102-272341
... 3-102-295219
... 3-102-323641
... 3-102-331885
... 3-102-362027
... 3-102-379487
... 3-102-388142
... 3-102-400049
... 3-102-402340
... 3-102-435843
... 3-102-444529
... 3-102-465883
... 3-102-468787
... 3-102-488653
... 3-102-493190
... 3-102-494258
... 3-102-498080
... 3-102-498709
... 3-102-501440
... 3-102-502513
... 3-102-502518
... 3-102-512999
... 3-102-522409
... 3-102-534902
... 3-102-552393
... 3-102-553610
... 3-102-557234
... 3-102-590174
... 3-102-594362
... 3-102-596051
... 3-102-599561
... 3-102-601289
... 3-102-602493
... 3-102-604962
... 3-102-606587
... 3-102-644127
... 3-102-644839
... 3-102-655271
... 3-105-535891
... 3-105-637662
... 3-105-654822
... 3101265235
... 3101269160
... 3101317433
... 3102749784
... 4-000-000019
... 4-000-042152
...
... '''
>>> [x for x in numbers.splitlines() if x and not cpj.is_valid(x)]
[]