Skip to content

Commit

Permalink
Merge branch 'brazilian-utils:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniamaia committed Jul 17, 2023
2 parents 3bedb58 + 9046eed commit 5c842fc
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ False
- [remove_symbols_cnpj](#remove_symbols_cnpj)
- [generate_cnpj](#generate_cnpj)
- [CEP](#cep)
- [is_valid_cep](#is_valid_cep)
- [is_valid_cep](#is_valid_cep)
- [generate_cep](#generate_cep)

## CPF

Expand Down Expand Up @@ -142,6 +143,17 @@ Verifica se o CEP é valido. Apenas números, formatados como string. Não verif
True
```

### generate_cep

Gera um CEP válido aleatório.

```python
>>> from brutils import generate_cep
>>> generate_cep()
'77520503'
```


## Contributing

Sua colaboração é sempre bem-vinda! Preparamos o [arquivo contributing][contributing] pra te ajudar nos primeiros passos. Toda ajuda conta! Sinta-se livre para criar novas [GitHub issues][github-issues] e interagir aqui.
Expand Down
11 changes: 11 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ False
- [generate_cnpj](#generate_cnpj)
- [CEP](#cep)
- [is_valid_cep](#is_valid_cep)
- [generate_cep](#generate_cep)

## CPF

Expand Down Expand Up @@ -147,6 +148,16 @@ Check if CEP is valid. Numbers only, formatted as strings. Does not check if CEP
True
```

### generate_cep

Generate a valid random CEP.

```python
>>> from brutils import generate_cep
>>> generate_cep()
'77520503'
```

## Contributing

Collaboration is super welcome! We prepared the [contributing file][contributing] to help you in the first steps. Every little bit of help counts! Feel free to create new [GitHub issues][github-issues] and interact here.
Expand Down
1 change: 1 addition & 0 deletions brutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
)
from brutils.cep import (
is_valid as is_valid_cep,
generate as generate_cep,
)
13 changes: 13 additions & 0 deletions brutils/cep.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,16 @@ def is_valid(cep): # type: (str) -> bool
"""

return isinstance(cep, str) and len(cep) == 8 and cep.isdigit()


def generate(): # type: () -> str
"""
Generates a random valid CEP digit string. An optional branch
number parameter can be given, it defaults to 1.
"""
generated_number = ""

for _ in range(0, 8):
generated_number = generated_number + str(randint(0, 9))

return generated_number
6 changes: 6 additions & 0 deletions tests/test_cep.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
)
from brutils.cep import (
is_valid,
generate,
)
from unittest import TestCase, main

Expand All @@ -29,3 +30,8 @@ def test_is_valid(self):
# When CEP is valid
assert is_valid("99999999")
assert is_valid("88390000")

def test_generate(self):
for _ in range(10_000):
assert is_valid(generate())
# assert format(generate()) is not None

0 comments on commit 5c842fc

Please sign in to comment.