-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adicionando utilitário convert_uf_to_text
- Loading branch information
Showing
5 changed files
with
81 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
def convert_uf_to_text(uf): # type: (str) -> str | None | ||
""" | ||
Converts a given Brazilian state code (UF) to its full state name. | ||
This function takes a 2-letter UF code and returns the corresponding full state name. | ||
It handles all Brazilian states and the Federal District. | ||
Args: | ||
uf (str): The 2-letter UF code to be converted. | ||
Returns: | ||
str or None: The full name of the state corresponding to the UF code, | ||
or None if the UF code is invalid. | ||
Example: | ||
>>> convert_uf_to_text('SP') | ||
"São Paulo" | ||
>>> convert_uf_to_text('RJ') | ||
"Rio de Janeiro" | ||
>>> convert_uf_to_text('XX') | ||
None | ||
""" | ||
|
||
from brutils.data.enums.uf import UF | ||
|
||
try: | ||
return UF[uf.upper()].value | ||
except KeyError: | ||
return None |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from unittest import TestCase | ||
|
||
from brutils.ibge.uf import convert_uf_to_text | ||
|
||
|
||
class TestUF(TestCase): | ||
def test_convert_uf_to_text(self): | ||
# Testes para códigos válidos | ||
self.assertEqual(convert_uf_to_text("SP"), "São Paulo") | ||
self.assertEqual(convert_uf_to_text("RJ"), "Rio de Janeiro") | ||
self.assertEqual(convert_uf_to_text("MG"), "Minas Gerais") | ||
self.assertEqual(convert_uf_to_text("DF"), "Distrito Federal") | ||
self.assertEqual(convert_uf_to_text("df"), "Distrito Federal") | ||
|
||
# Testes para códigos inválidos | ||
self.assertIsNone(convert_uf_to_text("XX")) # Código não existe | ||
self.assertIsNone(convert_uf_to_text("")) # Código vazio | ||
|
||
# Implementar mais casos de teste aqui | ||
# Testes com espaços em branco | ||
self.assertIsNone(convert_uf_to_text(" SP ")) # UF com espaços ao redor | ||
self.assertIsNone(convert_uf_to_text(" ")) # Apenas espaços | ||
self.assertIsNone(convert_uf_to_text("S")) # Apenas 1 letra | ||
self.assertIsNone(convert_uf_to_text("SPX")) # Mais de 2 letras |