-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a3249d
commit 4cd0ed2
Showing
5 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from random import randint | ||
|
||
|
||
# FORMATTING | ||
############ | ||
|
||
|
||
# OPERATIONS | ||
############ | ||
|
||
|
||
def is_valid(cep): # type: (str) -> bool | ||
""" | ||
Returns when CEP is valid, input should be a digit | ||
string of proper length. Doesn't validate if it's real, | ||
'cause only the "Correios" Base does. | ||
Source: https://en.wikipedia.org/wiki/C%C3%B3digo_de_Endere%C3%A7amento_Postal | ||
""" | ||
|
||
return isinstance(cep, str) and len(cep) == 8 and cep.isdigit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from os import pardir | ||
from os.path import abspath, join, dirname | ||
from sys import path, version_info, dont_write_bytecode | ||
from inspect import getsourcefile | ||
from unittest.mock import patch | ||
|
||
dont_write_bytecode = True | ||
range = range if version_info.major >= 3 else xrange | ||
path.insert( | ||
1, abspath(join(dirname(abspath(getsourcefile(lambda: 0))), pardir)) | ||
) | ||
from brutils.cep import ( | ||
is_valid, | ||
) | ||
from unittest import TestCase, main | ||
|
||
|
||
class CEP(TestCase): | ||
def test_is_valid(self): | ||
# When CEP is not string, returns False | ||
assert not is_valid(1) | ||
|
||
# When CEP's len is different of 8, returns False | ||
assert not is_valid("1") | ||
|
||
# When CEP does not contain only digits, returns False | ||
assert not is_valid("1234567-") | ||
|
||
# When CEP is valid | ||
assert is_valid("99999999") | ||
assert is_valid("88390000") |