Skip to content

Commit

Permalink
Merge branch 'main' of github.com:giovannism20/brutils-python
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannism20 committed Oct 4, 2023
2 parents a4ad71e + b5b1edb commit 10d1ee3
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 82 deletions.
19 changes: 10 additions & 9 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
## Checklist de Revisão
<!--- Marque as caixas que se aplicam. Você pode deixar caixas desmarcadas se elas não se aplicarem.-->

- [ ] Os testes foram adicionados ou atualizados para refletir as mudanças (se aplicável).
- [ ] Foi adicionada uma entrada no changelog / Meu PR não necessita de uma nova entrada no changelog.
- [ ] A documentação em português foi atualizada ou criada, se necessário.
- [ ] Se feita a documentação, a atualização do arquivo em inglês. <!---Permitido uso de Google Tradutor/ChatGPT. -->
- [ ] Eu documentei as minhas mudanças no código, adicionando docstrings e comentários. [Instruções](https://github.com/brazilian-utils/brutils-python/blob/main/CONTRIBUTING.md#8-fa%C3%A7a-as-suas-altera%C3%A7%C3%B5es)
- [ ] O código segue as diretrizes de estilo e padrões de codificação do projeto.
- [ ] Todos os testes passam. [Instruções](https://github.com/brazilian-utils/brutils-python/blob/main/CONTRIBUTING.md#testes)
- [ ] O Pull Request foi testado localmente. [Instruções](https://github.com/brazilian-utils/brutils-python/blob/main/CONTRIBUTING.md#7-execute-o-brutils-localmente)
- [ ] Não há conflitos de mesclagem.
- [] Eu li o [Contributing.md](https://github.com/brazilian-utils/brutils-python/blob/main/CONTRIBUTING.md)
- [] Os testes foram adicionados ou atualizados para refletir as mudanças (se aplicável).
- [] Foi adicionada uma entrada no changelog / Meu PR não necessita de uma nova entrada no changelog.
- [] A [documentação](https://github.com/brazilian-utils/brutils-python/blob/main/README.md) em português foi atualizada ou criada, se necessário.
- [] Se feita a documentação, a atualização do [arquivo em inglês](https://github.com/brazilian-utils/brutils-python/blob/main/README_EN.md). <!---Permitido uso de Google Tradutor/ChatGPT. -->
- [] Eu documentei as minhas mudanças no código, adicionando docstrings e comentários. [Instruções](https://github.com/brazilian-utils/brutils-python/blob/main/CONTRIBUTING.md#8-fa%C3%A7a-as-suas-altera%C3%A7%C3%B5es)
- [] O código segue as diretrizes de estilo e padrões de codificação do projeto.
- [] Todos os testes passam. [Instruções](https://github.com/brazilian-utils/brutils-python/blob/main/CONTRIBUTING.md#testes)
- [] O Pull Request foi testado localmente. [Instruções](https://github.com/brazilian-utils/brutils-python/blob/main/CONTRIBUTING.md#7-execute-o-brutils-localmente)
- [] Não há conflitos de mesclagem.


## Comentários Adicionais (opcional)
Expand Down
25 changes: 15 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,28 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Utilitário `is_valid_phone` [#147](https://github.com/brazilian-utils/brutils-python/pull/147)
- Utilitário `is_valid_mobile_phone` [#146](https://github.com/brazilian-utils/brutils-python/pull/146)
- Utilitário `is_valid_landline_phone` [#143](https://github.com/brazilian-utils/brutils-python/pull/143)
- Utilitário `remove_symbols_phone` [#188](https://github.com/brazilian-utils/brutils-python/pull/188)

## [2.0.0] - 2023-07-23

### Added

- Utilitário `is_valid_cep` (#123)
- Utilitário `format_cep` (#125)
- Utilitário `remove_symbols_cep` (#126)
- Utilitário `generate_cep` (#124)
- Utilitário `is_valid_cpf` (#34)
- Utilitário `format_cpf` (#54)
- Utilitário `remove_symbols_cpf` (#57)
- Utilitário `is_valid_cnpj` (#36)
- Utilitário `format_cnpj` (#52)
- Utilitário `remove_symbols_cnpj` (#58)
- Utilitário `is_valid_cep` [123](https://github.com/brazilian-utils/brutils-python/pull/123)
- Utilitário `format_cep` [125](https://github.com/brazilian-utils/brutils-python/pull/125)
- Utilitário `remove_symbols_cep` [126](https://github.com/brazilian-utils/brutils-python/pull/126)
- Utilitário `generate_cep` [124](https://github.com/brazilian-utils/brutils-python/pull/124)
- Utilitário `is_valid_cpf` [34](https://github.com/brazilian-utils/brutils-python/pull/34)
- Utilitário `format_cpf` [54](https://github.com/brazilian-utils/brutils-python/pull/54)
- Utilitário `remove_symbols_cpf` [57](https://github.com/brazilian-utils/brutils-python/pull/57)
- Utilitário `is_valid_cnpj` [36](https://github.com/brazilian-utils/brutils-python/pull/36)
- Utilitário `format_cnpj` [52](https://github.com/brazilian-utils/brutils-python/pull/52)
- Utilitário `remove_symbols_cnpj` [58](https://github.com/brazilian-utils/brutils-python/pull/58)

### Deprecated

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
[![codecov](https://codecov.io/gh/brazilian-utils/brutils-python/branch/main/graph/badge.svg?token=5KNECS8JYF)](https://codecov.io/gh/brazilian-utils/brutils-python)
[![Downloads per Month](https://shields.io/pypi/dm/brutils)](https://pypistats.org/packages/brutils)
[![Package version](https://shields.io/pypi/v/brutils)](https://pypi.org/project/brutils/)
</div>

### [Looking for the english version?](README_EN.md)
### [Procurando a documentação da versão 1.0.1?](/documentation%20v1.0.1/PORTUGUESE_VERSION.md)
</div>

# Introdução

Expand Down
3 changes: 1 addition & 2 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
[![Downloads per Month](https://shields.io/pypi/dm/brutils)](https://pypistats.org/packages/brutils)
[![Package version](https://shields.io/pypi/v/brutils)](https://pypi.org/project/brutils/)
### [Procurando pela versão em português?](README.md)
### [Looking for 1.0.1 version documentation?](/documentation%20v1.0.1/ENGLISH_VERSION.md)

</div>

Expand Down Expand Up @@ -231,7 +230,7 @@ True

### remove_symbols_phone

Remove symbols from phone number. ***Exemplo: +55 (21) 2569-6969 ficaria '552125696969'.***
Remove symbols from phone number. ***Example: +55 (21) 2569-6969 will return '552125696969'.***

```python
>>> from brutils import remove_symbols_phone
Expand Down
10 changes: 8 additions & 2 deletions brutils/phone.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def is_valid_landline(phone_number): # type: (str) -> bool
"""
pattern = re.compile(r"^[1-9][1-9][2-5]\d{7}$")
return isinstance(phone_number, str) and re.match(pattern, phone_number)
return (
isinstance(phone_number, str)
and re.match(pattern, phone_number) is not None
)


def is_valid_mobile(phone_number): # type: (str) -> bool
Expand All @@ -29,7 +32,10 @@ def is_valid_mobile(phone_number): # type: (str) -> bool
"""
pattern = re.compile(r"^[1-9][1-9][9]\d{8}$")
return isinstance(phone_number, str) and re.match(pattern, phone_number)
return (
isinstance(phone_number, str)
and re.match(pattern, phone_number) is not None
)


def is_valid(phone_number): # type: (str) -> bool
Expand Down
13 changes: 13 additions & 0 deletions old_versions_documentation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Documentação Antiga

Aqui você vai encontrar a documentação de versões já descontinuadas.

A documentação das versões que ainda estão sendo mantidas está disponível nos
arquivos README.md/README_EN.md.

# Old Documentation

Here you will find documentation for discontinued versions.

Documentation for versions that are still being maintained is available on
README.md/README_EN.md.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions tests/test_cep.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ def test_format_cep(self):

def test_is_valid(self):
# When CEP is not string, returns False
self.assertFalse(is_valid(1))
self.assertIs(is_valid(1), False)

# When CEP's len is different of 8, returns False
self.assertFalse(is_valid("1"))
self.assertIs(is_valid("1"), False)

# When CEP does not contain only digits, returns False
self.assertFalse(is_valid("1234567-"))
self.assertIs(is_valid("1234567-"), False)

# When CEP is valid
self.assertTrue(is_valid("99999999"))
self.assertTrue(is_valid("88390000"))
self.assertIs(is_valid("99999999"), True)
self.assertIs(is_valid("88390000"), True)

def test_generate(self):
for _ in range(10_000):
self.assertTrue(is_valid(generate()))
self.assertIs(is_valid(generate()), True)
# assert format(generate()) is not None
28 changes: 14 additions & 14 deletions tests/test_cnpj.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,42 +63,42 @@ def test_format_cnpj(self):
self.assertIsNone(format_cnpj("01838723000127"))

def test_validate(self):
self.assertTrue(validate("34665388000161"))
self.assertFalse(validate("52599927000100"))
self.assertFalse(validate("00000000000"))
self.assertIs(validate("34665388000161"), True)
self.assertIs(validate("52599927000100"), False)
self.assertIs(validate("00000000000"), False)

def test_is_valid(self):
# When CNPJ is not string, returns False
self.assertFalse(is_valid(1))
self.assertIs(is_valid(1), False)

# When CNPJ's len is different of 14, returns False
self.assertFalse(is_valid("1"))
self.assertIs(is_valid("1"), False)

# When CNPJ does not contain only digits, returns False
self.assertFalse(is_valid("1112223334445-"))
self.assertIs(is_valid("1112223334445-"), False)

# When CNPJ has only the same digit, returns false
self.assertFalse(is_valid("11111111111111"))
self.assertIs(is_valid("11111111111111"), False)

# When rest_1 is lt 2 and the 13th digit is not 0, returns False
self.assertFalse(is_valid("1111111111315"))
self.assertIs(is_valid("1111111111315"), False)

# When rest_1 is gte 2 and the 13th digit is not (11 - rest), returns False
self.assertFalse(is_valid("1111111111115"))
self.assertIs(is_valid("1111111111115"), False)

# When rest_2 is lt 2 and the 14th digit is not 0, returns False
self.assertFalse(is_valid("11111111121205"))
self.assertIs(is_valid("11111111121205"), False)

# When rest_2 is gte 2 and the 14th digit is not (11 - rest), returns False
self.assertFalse(is_valid("11111111113105"))
self.assertIs(is_valid("11111111113105"), False)

# When CNPJ is valid
self.assertTrue(is_valid("34665388000161"))
self.assertTrue(is_valid("01838723000127"))
self.assertIs(is_valid("34665388000161"), True)
self.assertIs(is_valid("01838723000127"), True)

def test_generate(self):
for _ in range(10_000):
self.assertTrue(validate(generate()))
self.assertIs(validate(generate()), True)
self.assertIsNotNone(display(generate()))

def test__hashdigit(self):
Expand Down
28 changes: 14 additions & 14 deletions tests/test_cpf.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,42 +59,42 @@ def test_format_cpf(self):
self.assertIsNone(format_cpf("11144477735"))

def test_validate(self):
self.assertTrue(validate("52513127765"))
self.assertTrue(validate("52599927765"))
self.assertFalse(validate("00000000000"))
self.assertIs(validate("52513127765"), True)
self.assertIs(validate("52599927765"), True)
self.assertIs(validate("00000000000"), False)

def test_is_valid(self):
# When cpf is not string, returns False
self.assertFalse(is_valid(1))
self.assertIs(is_valid(1), False)

# When cpf's len is different of 11, returns False
self.assertFalse(is_valid("1"))
self.assertIs(is_valid("1"), False)

# When cpf does not contain only digits, returns False
self.assertFalse(is_valid("1112223334-"))
self.assertIs(is_valid("1112223334-"), False)

# When CPF has only the same digit, returns false
self.assertFalse(is_valid("11111111111"))
self.assertIs(is_valid("11111111111"), False)

# When rest_1 is lt 2 and the 10th digit is not 0, returns False
self.assertFalse(is_valid("11111111215"))
self.assertIs(is_valid("11111111215"), False)

# When rest_1 is gte 2 and the 10th digit is not (11 - rest), returns False
self.assertFalse(is_valid("11144477705"))
self.assertIs(is_valid("11144477705"), False)

# When rest_2 is lt 2 and the 11th digit is not 0, returns False
self.assertFalse(is_valid("11111111204"))
self.assertIs(is_valid("11111111204"), False)

# When rest_2 is gte 2 and the 11th digit is not (11 - rest), returns False
self.assertFalse(is_valid("11144477732"))
self.assertIs(is_valid("11144477732"), False)

# When cpf is valid
self.assertTrue(is_valid("11144477735"))
self.assertTrue(is_valid("11111111200"))
self.assertIs(is_valid("11144477735"), True)
self.assertIs(is_valid("11111111200"), True)

def test_generate(self):
for _ in range(10_000):
self.assertTrue(validate(generate()))
self.assertIs(validate(generate()), True)
self.assertIsNotNone(display(generate()))

def test__hashdigit(self):
Expand Down
46 changes: 23 additions & 23 deletions tests/test_phone.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,55 @@ def test_is_valid_landline(self):
self.assertIs(is_valid_landline(1938814933), False)

# When landline phone doesn't contain only digits, returns False
self.assertFalse(is_valid_landline("(19)388149"))
self.assertIs(is_valid_landline("(19)388149"), False)

# When landline phone is an empty string, returns False
self.assertFalse(is_valid_landline(""))
self.assertIs(is_valid_landline(""), False)

# When landline phone's len is different of 10, returns False
self.assertFalse(is_valid_landline("193881"))
self.assertIs(is_valid_landline("193881"), False)

# When landline phone's first digit is 0, returns False
self.assertFalse(is_valid_landline("0938814933"))
self.assertIs(is_valid_landline("0938814933"), False)

# When landline phone's second digit is 0, returns False
self.assertFalse(is_valid_landline("1038814933"))
self.assertIs(is_valid_landline("1038814933"), False)

# When landline phone's third digit is different of 2,3,4 or 5, returns False
self.assertFalse(is_valid_landline("1998814933"))
self.assertIs(is_valid_landline("1998814933"), False)

# When landline phone is valid
self.assertTrue(is_valid_landline("1928814933"))
self.assertTrue(is_valid_landline("1938814933"))
self.assertTrue(is_valid_landline("1948814933"))
self.assertTrue(is_valid_landline("1958814933"))
self.assertTrue(is_valid_landline("3333333333"))
self.assertIs(is_valid_landline("1928814933"), True)
self.assertIs(is_valid_landline("1938814933"), True)
self.assertIs(is_valid_landline("1948814933"), True)
self.assertIs(is_valid_landline("1958814933"), True)
self.assertIs(is_valid_landline("3333333333"), True)

def test_is_valid_mobile(self):
# When mobile is not string, returns False
self.assertFalse(is_valid_mobile(1))
self.assertIs(is_valid_mobile(1), False)

# When mobile doesn't contain only digits, returns False
self.assertFalse(is_valid_mobile(119940 - 2927))
self.assertIs(is_valid_mobile(119940 - 2927), False)

# When mobile is an empty string, returns False
self.assertFalse(is_valid_mobile(""))
self.assertIs(is_valid_mobile(""), False)

# When mobile's len is different of 11, returns False
self.assertFalse(is_valid_mobile("119940"))
self.assertIs(is_valid_mobile("119940"), False)

# When mobile's first digit is 0, returns False
self.assertFalse(is_valid_mobile("01994029275"))
self.assertIs(is_valid_mobile("01994029275"), False)

# When mobile's second digit is 0, returns False
self.assertFalse(is_valid_mobile("90994029275"))
self.assertIs(is_valid_mobile("90994029275"), False)

# When mobile's third digit is different of 9, returns False
self.assertFalse(is_valid_mobile("11594029275"))
self.assertIs(is_valid_mobile("11594029275"), False)

# When mobile is valid
self.assertTrue(is_valid_mobile("99999999999"))
self.assertTrue(is_valid_mobile("11994029275"))
self.assertIs(is_valid_mobile("99999999999"), True)
self.assertIs(is_valid_mobile("11994029275"), True)

def test_is_valid(self):
# Mock is_valid_landline to return True
Expand All @@ -73,7 +73,7 @@ def test_is_valid(self):
) as mock_is_valid_landline:
with patch("brutils.phone.is_valid_mobile") as mock_is_valid_mobile:
# When landline phone is_valid, returns True
self.assertTrue(is_valid("1958814933"))
self.assertIs(is_valid("1958814933"), True)

# Checks if function is_valid_landline is called with the correct argument
mock_is_valid_landline.assert_called_once_with("1958814933")
Expand All @@ -88,7 +88,7 @@ def test_is_valid(self):
"brutils.phone.is_valid_mobile", return_value=True
) as mock_is_valid_mobile:
# When mobile phone is_valid, returns True
self.assertTrue(is_valid("11994029275"))
self.assertIs(is_valid("11994029275"), True)

# Checks if function is_valid_landline is called with the correct argument
mock_is_valid_landline.assert_called_once_with("11994029275")
Expand All @@ -103,7 +103,7 @@ def test_is_valid(self):
"brutils.phone.is_valid_mobile", return_value=False
) as mock_is_valid_mobile:
# When landline phone isn't valid, returns False
self.assertFalse(is_valid("11994029275"))
self.assertIs(is_valid("11994029275"), False)

# Checks if function is_valid_landline is called with the correct argument
mock_is_valid_landline.assert_called_once_with("11994029275")
Expand Down

0 comments on commit 10d1ee3

Please sign in to comment.