Skip to content

Commit

Permalink
Feature: implementando a função
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniamaia committed Jul 23, 2023
1 parent ea2de2d commit 8f248fe
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ False
- [CEP](#cep)
- [is_valid_cep](#is_valid_cep)
- [format_cep](#format_cep)
- [remove_symbols_cep](#remove_symbols_cep)
- [generate_cep](#generate_cep)

## CPF
Expand Down Expand Up @@ -80,6 +81,7 @@ Remove os símbolos de formatação do CPF e retorna somente números. Filtra ap
>>> remove_symbols_cpf('000.111.222-33')
'00011122233'
```

### generate_cpf

Gera um CPF válido aleatório.
Expand Down Expand Up @@ -154,6 +156,16 @@ Formata o CEP. Retorna None se o CEP for inválido.
'01310-200'
```

### remove_symbols_cep

Remove os símbolos de formatação do CEP e retorna somente números. Filtra apenas os símbolos utilizados para a validação do CEP. Propositalmente não remove outros símbolos.

```python
>>> from brutils import remove_symbols_cep
>>> remove_symbols_cep('01310-200')
'01310200'
```

### generate_cep

Gera um CEP válido aleatório.
Expand Down
15 changes: 14 additions & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ False
- [generate_cnpj](#generate_cnpj)
- [CEP](#cep)
- [is_valid_cep](#is_valid_cep)
- [format_cep](#format_cep)
- [format_cep](#format_cep)
- [remove_symbols_cep](#remove_symbols_cep)
- [generate_cep](#generate_cep)

## CPF
Expand Down Expand Up @@ -159,6 +160,18 @@ Format CEP. Returns None if CEP is invalid.
'01310-200'
```

### remove_symbols_cep

Remove formatting symbols from CEP and return only digits.
It only filters out the symbols used for CEP validation.
It purposefully doesn't remove other symbols.

```python
>>> from brutils import remove_symbols_cep
>>> remove_symbols_cep('01310-200')
'01310200'
```

### generate_cep

Generate a valid random CEP.
Expand Down
1 change: 1 addition & 0 deletions brutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
is_valid as is_valid_cep,
format_cep,
generate as generate_cep,
remove_symbols as remove_symbols_cep,
)
10 changes: 10 additions & 0 deletions brutils/cep.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
############


def remove_symbols(dirty): # type: (str) -> str
"""
Filters out CEP formatting symbols. Symbols that are not used
in the CEP formatting are left unfiltered on purpose so that
if fails other tests, because their presence indicate that the
input was somehow corrupted.
"""
return "".join(filter(lambda char: char not in ".-", dirty))


def format_cep(cep): # type: (str) -> str
"""
Will format an adequately formatted numbers-only CEP string,
Expand Down
11 changes: 11 additions & 0 deletions tests/test_cep.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@
is_valid,
format_cep,
generate,
remove_symbols,
)
from unittest import TestCase, main


class CEP(TestCase):
def test_remove_symbols(self):
assert remove_symbols("00000000") == "00000000"
assert remove_symbols("01310-200") == "01310200"
assert remove_symbols("01..310.-200.-") == "01310200"
assert remove_symbols("abc01310200*!*&#") == "abc01310200*!*&#"
assert (
remove_symbols("ab.c1.--.3-102.-0-.0-.*.-!*&#") == "abc1310200*!*&#"
)
assert remove_symbols("...---...") == ""

def test_format_cep(self):
with patch("brutils.cep.is_valid", return_value=True) as mock_is_valid:
# When cep is_valid, returns formatted cep
Expand Down

0 comments on commit 8f248fe

Please sign in to comment.