diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 70062d18..e79e7f42 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -12,15 +12,16 @@ ## Checklist de Revisão -- [ ] 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. -- [ ] 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). +- [] 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) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22981c4c..ff5a4a6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index d90e7166..69d48dd0 100644 --- a/README.md +++ b/README.md @@ -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/) + ### [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) - # Introdução diff --git a/README_EN.md b/README_EN.md index c9db64b2..cfbfb48f 100644 --- a/README_EN.md +++ b/README_EN.md @@ -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) @@ -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 diff --git a/brutils/phone.py b/brutils/phone.py index 3864fa6d..2b02ae27 100644 --- a/brutils/phone.py +++ b/brutils/phone.py @@ -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 @@ -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 diff --git a/old_versions_documentation/README.md b/old_versions_documentation/README.md new file mode 100644 index 00000000..87640576 --- /dev/null +++ b/old_versions_documentation/README.md @@ -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. diff --git a/documentation v1.0.1/ENGLISH_VERSION.md b/old_versions_documentation/v1.0.1/ENGLISH_VERSION.md similarity index 100% rename from documentation v1.0.1/ENGLISH_VERSION.md rename to old_versions_documentation/v1.0.1/ENGLISH_VERSION.md diff --git a/documentation v1.0.1/PORTUGUESE_VERSION.md b/old_versions_documentation/v1.0.1/PORTUGUESE_VERSION.md similarity index 100% rename from documentation v1.0.1/PORTUGUESE_VERSION.md rename to old_versions_documentation/v1.0.1/PORTUGUESE_VERSION.md diff --git a/tests/test_cep.py b/tests/test_cep.py index a86392b9..5e3544c3 100644 --- a/tests/test_cep.py +++ b/tests/test_cep.py @@ -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 diff --git a/tests/test_cnpj.py b/tests/test_cnpj.py index cc4d9411..09fea7ce 100644 --- a/tests/test_cnpj.py +++ b/tests/test_cnpj.py @@ -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): diff --git a/tests/test_cpf.py b/tests/test_cpf.py index 58db6fbf..37b2506f 100644 --- a/tests/test_cpf.py +++ b/tests/test_cpf.py @@ -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): diff --git a/tests/test_phone.py b/tests/test_phone.py index db39cc9a..78ba5ad5 100644 --- a/tests/test_phone.py +++ b/tests/test_phone.py @@ -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 @@ -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") @@ -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") @@ -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")