From b2870416e94125b1c817fed82548c33ec9991d4a Mon Sep 17 00:00:00 2001 From: laistdomiciano Date: Mon, 28 Oct 2024 11:50:11 +0100 Subject: [PATCH 01/16] Adicitonando is_holiday --- CONTRIBUTING.md | 2 +- README.md | 34 ++++++++++++++++++++++++++++++++++ README_EN.md | 34 ++++++++++++++++++++++++++++++++++ brutils/__init__.py | 5 +++++ 4 files changed, 74 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 26c4b8da..756e0891 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -98,7 +98,7 @@ emulate bash -c '. .../bin/activate' Para testar se o ambiente virtual está ativo corretamente, execute o comando e verifique se a resposta é algo parecido com a seguinte: ```sh -$ poetry env inf +$ poetry env info Virtualenv Python: 3.x.y Implementation: CPython diff --git a/README.md b/README.md index 73769b04..4e766710 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,8 @@ False - [generate_voter_id](#generate_voter_id) - [IBGE](#ibge) - [convert_code_to_uf](#convert_code_to_uf) +- [Feriados](#feriados) + - [is_holiday](#is_holiday) ## CPF @@ -1109,6 +1111,38 @@ Exemplo: >>> ``` +## Feriados + +### is_holiday + +Verifica se uma determinada data é um feriado nacional ou estadual no Brasil. + +Esta função recebe um objeto `datetime` como a data e uma UF opcional (Unidade Federativa) para especificar feriados estaduais. Retorna `True` se a data for um feriado, `False` se não for, ou `None` se a data ou UF forem inválidas. Nota: a função não abrange feriados municipais. + +Argumentos: + +- `date (datetime)`: A data a ser verificada. +- `uf (str, opcional)`: A abreviação do estado (UF) para verificar feriados estaduais. Se não fornecido, apenas feriados nacionais são considerados. + +Retorna: + +- `bool | None`: `True` se a data for um feriado, `False` se não for, ou `None` se a data ou UF forem inválidas. + +Exemplo: + +```python +>>> from datetime import datetime +>>> from brutils import is_holiday + +>>> is_holiday(datetime(2024, 1, 1)) +True +>>> is_holiday(datetime(2024, 1, 2)) +False +>>> is_holiday(datetime(2024, 3, 2), uf="SP") +False +>>> is_holiday(datetime(2024, 12, 25), uf="RJ") +True +``` # Novos Utilitários e Reportar Bugs diff --git a/README_EN.md b/README_EN.md index 7917b673..60302eeb 100644 --- a/README_EN.md +++ b/README_EN.md @@ -89,6 +89,8 @@ False - [generate_voter_id](#generate_voter_id) - [IBGE](#ibge) - [convert_code_to_uf](#convert_code_to_uf) +- [Holidays](#holidays) + - [is_holiday](#is_holiday) ## CPF @@ -1112,6 +1114,38 @@ Exemplo: >>> ``` +## Holidays +### is_holiday + +Checks if a given date is a national or state holiday in Brazil. + +This function takes a `datetime` object as the date and an optional state abbreviation (UF) to specify state holidays. It returns `True` if the date is a holiday, `False` if it’s not, or `None` if the date or UF are invalid. Note that the function does not cover municipal holidays. + +Args: + +- `date (datetime)`: The date to be checked. +- `uf (str, optional)`: The state abbreviation (UF) to check for state holidays. If not provided, only national holidays are considered. + +Returns: + +- `bool | None`: `True` if the date is a holiday, `False` if it’s not, or `None` if the date or UF are invalid. + +Example: + +```python +>>> from datetime import datetime +>>> from brutils import is_holiday + +>>> is_holiday(datetime(2024, 1, 1)) +True +>>> is_holiday(datetime(2024, 1, 2)) +False +>>> is_holiday(datetime(2024, 3, 2), uf="SP") +False +>>> is_holiday(datetime(2024, 12, 25), uf="RJ") +True +``` + # Feature Request and Bug Report If you want to suggest new features or report bugs, simply create diff --git a/brutils/__init__.py b/brutils/__init__.py index 6959a0d0..9d300b80 100644 --- a/brutils/__init__.py +++ b/brutils/__init__.py @@ -121,6 +121,9 @@ from brutils.voter_id import ( is_valid as is_valid_voter_id, ) +from brutils.date import ( + is_holiday as is_holiday_date, is_holiday, +) # Defining __all__ to expose the public methods __all__ = [ @@ -172,4 +175,6 @@ "is_valid_voter_id", # IBGE "convert_code_to_uf", + # Date + "is_holiday", ] From 5dfcd515c945048b87a9839bc72c94765e2ab640 Mon Sep 17 00:00:00 2001 From: laistdomiciano Date: Mon, 28 Oct 2024 11:51:23 +0100 Subject: [PATCH 02/16] Adicitonando is_holiday --- tests/test_date.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/test_date.py diff --git a/tests/test_date.py b/tests/test_date.py new file mode 100644 index 00000000..c9751b50 --- /dev/null +++ b/tests/test_date.py @@ -0,0 +1,53 @@ +from unittest import TestCase +from datetime import datetime +from brutils.date import is_holiday + +class TestIsHoliday(TestCase): + def test_feriados_validos(self): + # Testes com feriados válidos + self.assertTrue(is_holiday(datetime(2024, 1, 1))) # Ano Novo + self.assertTrue(is_holiday(datetime(2024, 7, 9), uf="SP")) # Revolução Constitucionalista (SP) + self.assertTrue(is_holiday(datetime(2024, 9, 7))) # Independência do Brasil + self.assertTrue(is_holiday(datetime(2025, 1, 1))) # Ano Novo + + def test_dias_normais(self): + # Testes com dias normais + self.assertFalse(is_holiday(datetime(2024, 1, 2))) # Dia normal + self.assertFalse(is_holiday(datetime(2024, 7, 9), uf="RJ")) # Dia normal no RJ + + def test_data_invalida(self): + # Testes com data inválida + self.assertIsNone(is_holiday("2024-01-01")) # Formato incorreto + self.assertIsNone(is_holiday(None)) # Data None + + def test_uf_invalida(self): + # Testes com UF inválida + self.assertIsNone(is_holiday(datetime(2024, 1, 1), uf="XX")) # UF inválida + self.assertIsNone(is_holiday(datetime(2024, 1, 1), uf="SS")) # UF inválida + + def test_limite_de_datas(self): + # Testes com limite de datas + self.assertTrue(is_holiday(datetime(2024, 12, 25))) # Natal + self.assertTrue(is_holiday(datetime(2024, 11, 15))) # Proclamação da República + + def test_datas_depois_de_feriados(self): + # Test data after holidays + self.assertFalse(is_holiday(datetime(2024, 12, 26))) # Não é feriado + self.assertFalse(is_holiday(datetime(2025, 1, 2))) # Não é feriado + + def test_ano_bissexto(self): + # Teste ano bissexto + self.assertFalse(is_holiday(datetime(2024, 2, 29))) # Não é feriado, mas data válida + # Uncomment to test non-leap year invalid date + # self.assertIsNone(is_holiday(datetime(1900, 2, 29))) # Ano não bissexto, data inválida + + def test_data_passada_futura(self): + # Teste de data passada e futura + self.assertTrue(is_holiday(datetime(2023, 1, 1))) # Ano anterior + self.assertTrue(is_holiday(datetime(2150, 12, 25))) # Ano futuro + self.assertFalse(is_holiday(datetime(2250, 1, 2))) # Dia normal em ano futuro + + def test_data_sem_uf(self): + # Teste feriado nacional sem UF + self.assertTrue(is_holiday(datetime(2024, 12, 25))) # Natal, feriado nacional + self.assertFalse(is_holiday(datetime(2024, 7, 9))) # Data estadual de SP, sem UF \ No newline at end of file From 16b8448ec6690fc23c1e1c372d247949bf05e6c7 Mon Sep 17 00:00:00 2001 From: laistdomiciano Date: Mon, 28 Oct 2024 16:06:53 +0100 Subject: [PATCH 03/16] Adicionando is_holidays --- brutils/__init__.py | 9 ++++++--- tests/test_date.py | 44 +++++++++++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/brutils/__init__.py b/brutils/__init__.py index 9d300b80..aad91924 100644 --- a/brutils/__init__.py +++ b/brutils/__init__.py @@ -41,6 +41,12 @@ from brutils.cpf import ( remove_symbols as remove_symbols_cpf, ) +from brutils.date import ( + is_holiday, +) +from brutils.date import ( + is_holiday as is_holiday_date, +) # Email Import from brutils.email import is_valid as is_valid_email @@ -121,9 +127,6 @@ from brutils.voter_id import ( is_valid as is_valid_voter_id, ) -from brutils.date import ( - is_holiday as is_holiday_date, is_holiday, -) # Defining __all__ to expose the public methods __all__ = [ diff --git a/tests/test_date.py b/tests/test_date.py index c9751b50..2b81fc61 100644 --- a/tests/test_date.py +++ b/tests/test_date.py @@ -1,19 +1,27 @@ -from unittest import TestCase from datetime import datetime +from unittest import TestCase + from brutils.date import is_holiday + class TestIsHoliday(TestCase): def test_feriados_validos(self): # Testes com feriados válidos self.assertTrue(is_holiday(datetime(2024, 1, 1))) # Ano Novo - self.assertTrue(is_holiday(datetime(2024, 7, 9), uf="SP")) # Revolução Constitucionalista (SP) - self.assertTrue(is_holiday(datetime(2024, 9, 7))) # Independência do Brasil + self.assertTrue( + is_holiday(datetime(2024, 7, 9), uf="SP") + ) # Revolução Constitucionalista (SP) + self.assertTrue( + is_holiday(datetime(2024, 9, 7)) + ) # Independência do Brasil self.assertTrue(is_holiday(datetime(2025, 1, 1))) # Ano Novo def test_dias_normais(self): # Testes com dias normais self.assertFalse(is_holiday(datetime(2024, 1, 2))) # Dia normal - self.assertFalse(is_holiday(datetime(2024, 7, 9), uf="RJ")) # Dia normal no RJ + self.assertFalse( + is_holiday(datetime(2024, 7, 9), uf="RJ") + ) # Dia normal no RJ def test_data_invalida(self): # Testes com data inválida @@ -22,13 +30,19 @@ def test_data_invalida(self): def test_uf_invalida(self): # Testes com UF inválida - self.assertIsNone(is_holiday(datetime(2024, 1, 1), uf="XX")) # UF inválida - self.assertIsNone(is_holiday(datetime(2024, 1, 1), uf="SS")) # UF inválida + self.assertIsNone( + is_holiday(datetime(2024, 1, 1), uf="XX") + ) # UF inválida + self.assertIsNone( + is_holiday(datetime(2024, 1, 1), uf="SS") + ) # UF inválida def test_limite_de_datas(self): # Testes com limite de datas self.assertTrue(is_holiday(datetime(2024, 12, 25))) # Natal - self.assertTrue(is_holiday(datetime(2024, 11, 15))) # Proclamação da República + self.assertTrue( + is_holiday(datetime(2024, 11, 15)) + ) # Proclamação da República def test_datas_depois_de_feriados(self): # Test data after holidays @@ -37,7 +51,9 @@ def test_datas_depois_de_feriados(self): def test_ano_bissexto(self): # Teste ano bissexto - self.assertFalse(is_holiday(datetime(2024, 2, 29))) # Não é feriado, mas data válida + self.assertFalse( + is_holiday(datetime(2024, 2, 29)) + ) # Não é feriado, mas data válida # Uncomment to test non-leap year invalid date # self.assertIsNone(is_holiday(datetime(1900, 2, 29))) # Ano não bissexto, data inválida @@ -45,9 +61,15 @@ def test_data_passada_futura(self): # Teste de data passada e futura self.assertTrue(is_holiday(datetime(2023, 1, 1))) # Ano anterior self.assertTrue(is_holiday(datetime(2150, 12, 25))) # Ano futuro - self.assertFalse(is_holiday(datetime(2250, 1, 2))) # Dia normal em ano futuro + self.assertFalse( + is_holiday(datetime(2250, 1, 2)) + ) # Dia normal em ano futuro def test_data_sem_uf(self): # Teste feriado nacional sem UF - self.assertTrue(is_holiday(datetime(2024, 12, 25))) # Natal, feriado nacional - self.assertFalse(is_holiday(datetime(2024, 7, 9))) # Data estadual de SP, sem UF \ No newline at end of file + self.assertTrue( + is_holiday(datetime(2024, 12, 25)) + ) # Natal, feriado nacional + self.assertFalse( + is_holiday(datetime(2024, 7, 9)) + ) # Data estadual de SP, sem UF From 4e135dba84587e793cc736327a2dbf1cad5edc92 Mon Sep 17 00:00:00 2001 From: laistdomiciano Date: Mon, 28 Oct 2024 16:57:30 +0100 Subject: [PATCH 04/16] Atualizando Changelog --- CHANGELOG.md | 1 + brutils/date.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 brutils/date.py diff --git a/CHANGELOG.md b/CHANGELOG.md index b1546edc..88ffbc1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Utilitário `convert_code_to_uf` [#397](https://github.com/brazilian-utils/brutils-python/pull/410) +- Utilitário `is_holiday` [#446](https://github.com/brazilian-utils/brutils-python/pull/446) ## [2.2.0] - 2024-09-12 diff --git a/brutils/date.py b/brutils/date.py new file mode 100644 index 00000000..d66e9273 --- /dev/null +++ b/brutils/date.py @@ -0,0 +1,61 @@ +from datetime import datetime +from typing import Union + +import holidays + + +def is_holiday(date: datetime, uf: str = None) -> Union[bool, None]: + """ + Checks if the given date is a national or state holiday in Brazil. + + This function takes a date as a `datetime` object and an optional UF (Unidade Federativa), + returning a boolean value indicating whether the date is a holiday or `None` if the date or + UF are invalid. + + The method does not handle municipal holidays. + + Args: + date (datetime): The date to be checked. + uf (str, optional): The state abbreviation (UF) to check for state holidays. + If not provided, only national holidays will be considered. + + Returns: + bool | None: Returns `True` if the date is a holiday, `False` if it is not, + or `None` if the date or UF are invalid. + + Note: + The function logic should be implemented using the `holidays` library. + For more information, refer to the documentation at: https://pypi.org/project/holidays/ + + Usage Examples: + >>> from datetime import datetime + >>> is_holiday(datetime(2024, 1, 1)) + True + + >>> is_holiday(datetime(2024, 1, 2)) + False + + >>> is_holiday(datetime(2024, 3, 2), uf="SP") + False + + >>> is_holiday(datetime(2024, 12, 25), uf="RJ") + True + """ + + if not isinstance(date, datetime): + return None + + valid_ufs = holidays.Brazil().subdivisions + if uf is not None and uf not in valid_ufs: + return None + + national_holidays = holidays.Brazil(years=date.year) + + if date in national_holidays: + return True + + if uf is not None: + state_holidays = holidays.Brazil(prov=uf, years=date.year) + return date in state_holidays + + return False From 61873f90387d99a94b9075cf328e566d7ab17595 Mon Sep 17 00:00:00 2001 From: laistdomiciano Date: Wed, 30 Oct 2024 17:28:08 +0100 Subject: [PATCH 05/16] Lib Holidays adicionada --- poetry.lock | 41 ++++++++++++++++++++++++++++++++++++++++- pyproject.toml | 1 + 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index 16594c01..59e8e233 100644 --- a/poetry.lock +++ b/poetry.lock @@ -84,6 +84,34 @@ files = [ [package.extras] toml = ["tomli"] +[[package]] +name = "holidays" +version = "0.58" +description = "Generate and work with holidays in Python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "holidays-0.58-py3-none-any.whl", hash = "sha256:74eb0bd07db862c5b108d5e42cbd33c37ea066a2e8dc54f4858dd3cceef5ee8b"}, + {file = "holidays-0.58.tar.gz", hash = "sha256:cbe5f3b862474b8f6e5f7ee423f17f3ebd7836fcc74b38540f97b27a7f92dca7"}, +] + +[package.dependencies] +python-dateutil = "*" + +[[package]] +name = "python-dateutil" +version = "2.9.0.post0" +description = "Extensions to the standard Python datetime module" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" +files = [ + {file = "python-dateutil-2.9.0.post0.tar.gz", hash = "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3"}, + {file = "python_dateutil-2.9.0.post0-py2.py3-none-any.whl", hash = "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427"}, +] + +[package.dependencies] +six = ">=1.5" + [[package]] name = "ruff" version = "0.6.7" @@ -111,7 +139,18 @@ files = [ {file = "ruff-0.6.7.tar.gz", hash = "sha256:44e52129d82266fa59b587e2cd74def5637b730a69c4542525dfdecfaae38bd5"}, ] +[[package]] +name = "six" +version = "1.16.0" +description = "Python 2 and 3 compatibility utilities" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" +files = [ + {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, + {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, +] + [metadata] lock-version = "2.0" python-versions = "^3.8.1" -content-hash = "989d447f5ac999811a4e25ed6b1fc0749aa127fb45290a675b17e652d85b4123" +content-hash = "f38c6c11feb849e1688dd9d97b4c6913d516eb305c3727ef0e28c41dcd547380" diff --git a/pyproject.toml b/pyproject.toml index e70382e8..f0196651 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,7 @@ classifiers = [ [tool.poetry.dependencies] python = "^3.8.1" +holidays = "^0.58" [tool.poetry.group.test.dependencies] coverage = "^7.2.7" From 2290389d56783590c47abf63cb72d46ccf68a099 Mon Sep 17 00:00:00 2001 From: laistdomiciano Date: Wed, 30 Oct 2024 17:42:13 +0100 Subject: [PATCH 06/16] Adicionando instalacao de dependencias - run-tests.yml --- .github/workflows/run-tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index d8fce744..d392c321 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -16,6 +16,10 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + - name: Poetry Setup + uses: snok/install-poetry@v1 + - name: Install Dependencies + run: make install - name: Generate Report run: | pip install coverage From ece9daf54aa0de4501dc42a4fff6d2825cfd6d76 Mon Sep 17 00:00:00 2001 From: laistdomiciano Date: Wed, 30 Oct 2024 17:57:41 +0100 Subject: [PATCH 07/16] Mudanca de nome do arquivo date_utils Para evitar conflito com a nomenclatura date de python --- brutils/__init__.py | 4 ++-- brutils/{date.py => date_utils.py} | 14 +++++++------- tests/{test_date.py => test_date_utils.py} | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) rename brutils/{date.py => date_utils.py} (78%) rename tests/{test_date.py => test_date_utils.py} (98%) diff --git a/brutils/__init__.py b/brutils/__init__.py index aad91924..18353340 100644 --- a/brutils/__init__.py +++ b/brutils/__init__.py @@ -41,10 +41,10 @@ from brutils.cpf import ( remove_symbols as remove_symbols_cpf, ) -from brutils.date import ( +from brutils.date_utils import ( is_holiday, ) -from brutils.date import ( +from brutils.date_utils import ( is_holiday as is_holiday_date, ) diff --git a/brutils/date.py b/brutils/date_utils.py similarity index 78% rename from brutils/date.py rename to brutils/date_utils.py index d66e9273..aef9b9db 100644 --- a/brutils/date.py +++ b/brutils/date_utils.py @@ -4,7 +4,7 @@ import holidays -def is_holiday(date: datetime, uf: str = None) -> Union[bool, None]: +def is_holiday(target_date: datetime, uf: str = None) -> Union[bool, None]: """ Checks if the given date is a national or state holiday in Brazil. @@ -15,7 +15,7 @@ def is_holiday(date: datetime, uf: str = None) -> Union[bool, None]: The method does not handle municipal holidays. Args: - date (datetime): The date to be checked. + target_date (datetime): The date to be checked. uf (str, optional): The state abbreviation (UF) to check for state holidays. If not provided, only national holidays will be considered. @@ -42,20 +42,20 @@ def is_holiday(date: datetime, uf: str = None) -> Union[bool, None]: True """ - if not isinstance(date, datetime): + if not isinstance(target_date, datetime): return None valid_ufs = holidays.Brazil().subdivisions if uf is not None and uf not in valid_ufs: return None - national_holidays = holidays.Brazil(years=date.year) + national_holidays = holidays.Brazil(years=target_date.year) - if date in national_holidays: + if target_date in national_holidays: return True if uf is not None: - state_holidays = holidays.Brazil(prov=uf, years=date.year) - return date in state_holidays + state_holidays = holidays.Brazil(prov=uf, years=target_date.year) + return target_date in state_holidays return False diff --git a/tests/test_date.py b/tests/test_date_utils.py similarity index 98% rename from tests/test_date.py rename to tests/test_date_utils.py index 2b81fc61..b7350da2 100644 --- a/tests/test_date.py +++ b/tests/test_date_utils.py @@ -1,7 +1,7 @@ from datetime import datetime from unittest import TestCase -from brutils.date import is_holiday +from brutils.date_utils import is_holiday class TestIsHoliday(TestCase): From 7c749589c3e2f1136bd198ad3787dd47dab950a0 Mon Sep 17 00:00:00 2001 From: laistdomiciano Date: Wed, 30 Oct 2024 18:00:40 +0100 Subject: [PATCH 08/16] Removendo duplicada is_holiday no __init__ --- brutils/__init__.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/brutils/__init__.py b/brutils/__init__.py index 18353340..b41a12c5 100644 --- a/brutils/__init__.py +++ b/brutils/__init__.py @@ -42,12 +42,10 @@ remove_symbols as remove_symbols_cpf, ) from brutils.date_utils import ( - is_holiday, -) -from brutils.date_utils import ( - is_holiday as is_holiday_date, + is_holiday ) + # Email Import from brutils.email import is_valid as is_valid_email From 5a2d5292ac68e5435635c3f82c747a2d21f5b4db Mon Sep 17 00:00:00 2001 From: laistdomiciano Date: Wed, 30 Oct 2024 18:02:40 +0100 Subject: [PATCH 09/16] Removendo duplicada is_holiday no __init__ --- brutils/__init__.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/brutils/__init__.py b/brutils/__init__.py index b41a12c5..0f193129 100644 --- a/brutils/__init__.py +++ b/brutils/__init__.py @@ -41,10 +41,7 @@ from brutils.cpf import ( remove_symbols as remove_symbols_cpf, ) -from brutils.date_utils import ( - is_holiday -) - +from brutils.date_utils import is_holiday # Email Import from brutils.email import is_valid as is_valid_email From 5c898a4b513de802e185070cec0be3eeddea216a Mon Sep 17 00:00:00 2001 From: laistdomiciano Date: Wed, 30 Oct 2024 18:14:06 +0100 Subject: [PATCH 10/16] Movendo import holidays para dentro da funcao --- brutils/date_utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/brutils/date_utils.py b/brutils/date_utils.py index aef9b9db..8d852b90 100644 --- a/brutils/date_utils.py +++ b/brutils/date_utils.py @@ -1,10 +1,9 @@ from datetime import datetime from typing import Union -import holidays - def is_holiday(target_date: datetime, uf: str = None) -> Union[bool, None]: + import holidays """ Checks if the given date is a national or state holiday in Brazil. From b86af1f22b7dd9fa0e06efa52304145420c82d76 Mon Sep 17 00:00:00 2001 From: laistdomiciano Date: Wed, 30 Oct 2024 18:14:28 +0100 Subject: [PATCH 11/16] Movendo import holidays para dentro da funcao --- brutils/date_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/brutils/date_utils.py b/brutils/date_utils.py index 8d852b90..e480143f 100644 --- a/brutils/date_utils.py +++ b/brutils/date_utils.py @@ -4,6 +4,7 @@ def is_holiday(target_date: datetime, uf: str = None) -> Union[bool, None]: import holidays + """ Checks if the given date is a national or state holiday in Brazil. From 732759a62ec1df2a747d04293148c219c1a1a321 Mon Sep 17 00:00:00 2001 From: laistdomiciano Date: Wed, 30 Oct 2024 18:20:16 +0100 Subject: [PATCH 12/16] Adicionando __init__ na pasta de testes --- tests/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b From 4df178a24e14fee97c2aa65764fb23db27a50dfa Mon Sep 17 00:00:00 2001 From: laistdomiciano Date: Wed, 30 Oct 2024 18:32:16 +0100 Subject: [PATCH 13/16] Mudando o comando de rodar os testes na action --- .github/workflows/run-tests.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index d392c321..4d95e3df 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -19,11 +19,10 @@ jobs: - name: Poetry Setup uses: snok/install-poetry@v1 - name: Install Dependencies - run: make install + run: poetry install --no-root --with test - name: Generate Report run: | - pip install coverage - coverage run -m unittest discover tests/ + coverage run -m unittest discover -s tests - name: Upload Coverage to Codecov uses: codecov/codecov-action@v4 with: From a2e4743a948c83a193d8eedd6951ce896da91fb3 Mon Sep 17 00:00:00 2001 From: laistdomiciano Date: Wed, 30 Oct 2024 18:40:14 +0100 Subject: [PATCH 14/16] Adicionando working_directory a action run-tests.yml --- .github/workflows/run-tests.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 4d95e3df..cb6d615b 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -7,6 +7,8 @@ on: jobs: build: runs-on: ubuntu-latest + env: + working_directory: ~/brutils-python strategy: matrix: python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] From 10dbadafe55bfbbe696fa9c7aba76b30d38f6a09 Mon Sep 17 00:00:00 2001 From: laistdomiciano Date: Wed, 30 Oct 2024 18:44:27 +0100 Subject: [PATCH 15/16] Adicionando poetry run no generate report --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index cb6d615b..16e562cf 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -24,7 +24,7 @@ jobs: run: poetry install --no-root --with test - name: Generate Report run: | - coverage run -m unittest discover -s tests + poetry run coverage run -m unittest discover -s tests - name: Upload Coverage to Codecov uses: codecov/codecov-action@v4 with: From 200d32b2d22b9b82c0e935fcb8900b98510e718a Mon Sep 17 00:00:00 2001 From: laistdomiciano Date: Wed, 30 Oct 2024 18:49:29 +0100 Subject: [PATCH 16/16] Removendo mudancas desnecessarias Que foram feitas para debug --- .github/workflows/run-tests.yml | 2 -- brutils/__init__.py | 4 +++- brutils/date_utils.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 16e562cf..649e141c 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -7,8 +7,6 @@ on: jobs: build: runs-on: ubuntu-latest - env: - working_directory: ~/brutils-python strategy: matrix: python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] diff --git a/brutils/__init__.py b/brutils/__init__.py index 0f193129..b3c1850a 100644 --- a/brutils/__init__.py +++ b/brutils/__init__.py @@ -41,6 +41,8 @@ from brutils.cpf import ( remove_symbols as remove_symbols_cpf, ) + +# Date Utils Import from brutils.date_utils import is_holiday # Email Import @@ -173,6 +175,6 @@ "is_valid_voter_id", # IBGE "convert_code_to_uf", - # Date + # Date Utils "is_holiday", ] diff --git a/brutils/date_utils.py b/brutils/date_utils.py index e480143f..aef9b9db 100644 --- a/brutils/date_utils.py +++ b/brutils/date_utils.py @@ -1,10 +1,10 @@ from datetime import datetime from typing import Union +import holidays -def is_holiday(target_date: datetime, uf: str = None) -> Union[bool, None]: - import holidays +def is_holiday(target_date: datetime, uf: str = None) -> Union[bool, None]: """ Checks if the given date is a national or state holiday in Brazil.