File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 8181 - [ remove\_ symbols\_ pis] ( #remove_symbols_pis )
8282 - [ generate\_ pis] ( #generate_pis )
8383- [ Processo Jurídico] ( #processo-jurídico )
84- - [ is\_ valid\_ legal\_ process] ( #is_valid_legal_process )
84+ - [ is\_ valid\_ legal\_ process] ( #is_valid_legal_process )
8585 - [ format\_ legal\_ process] ( #format_legal_process )
8686 - [ remove\_ symbols\_ legal\_ process] ( #remove_symbols_legal_process )
8787 - [ generate\_ legal\_ process] ( #generate_legal_process )
9393 - [ get_code_by_municipality_name] ( #get_code_by_municipality_name )
9494 - [ convert_code_to_uf] ( #convert_code_to_uf )
9595 - [ get\_ municipality\_ by\_ code] ( #get_municipality_by_code )
96+ - [ convert_uf_to_name] ( #convert_uf_to_name )
9697- [ Feriados] ( #feriados )
9798 - [ is_holiday] ( #is_holiday )
9899- [ Monetário] ( #monetário )
@@ -1196,6 +1197,30 @@ None
11961197None
11971198```
11981199
1200+ ### convert_uf_to_name
1201+ Converte um código de UF brasileiro (por exemplo, 'SP') no nome completo do estado ('São Paulo').
1202+
1203+ A busca é case-insensitive (não diferencia maiúsculas de minúsculas) e ignora espaços em branco ao redor.
1204+
1205+ Argumentos:
1206+ * uf (str): Código de UF com duas letras.
1207+
1208+ Retorna:
1209+ * str: O nome completo do estado.
1210+
1211+ Lança:
1212+ * ValueError: Se ` uf ` for uma string vazia ou não for um código de UF válido.
1213+
1214+ Exemplo:
1215+
1216+ ``` python
1217+ >> > from brutils.ibge.uf import convert_uf_to_name
1218+ >> > convert_uf_to_name(' SP' )
1219+ ' São Paulo'
1220+ >> > convert_uf_to_name(' rj' )
1221+ ' Rio de Janeiro'
1222+ ```
1223+
11991224## Feriados
12001225
12011226### is_holiday
Original file line number Diff line number Diff line change 9393 - [ convert_code_to_uf] ( #convert_code_to_uf )
9494 - [ get\_ municipality\_ by\_ code] ( #get_municipality_by_code )
9595 - [ get_code_by_municipality_name] ( #get_code_by_municipality_name )
96+ - [ convert_uf_to_name] ( #convert_uf_to_name )
9697- [ Holidays] ( #holidays )
9798 - [ is_holiday] ( #is_holiday )
9899- [ Monetary] ( #monetary )
@@ -1200,6 +1201,30 @@ None
12001201None
12011202```
12021203
1204+ ### convert_uf_to_name
1205+ Converts a Brazilian UF code (e.g., 'SP') to the state's full name ('São Paulo').
1206+
1207+ The lookup is case-insensitive and ignores surrounding whitespace.
1208+
1209+ Args:
1210+ * uf (str): Two-letter UF code.
1211+
1212+ Returns:
1213+ * str: The state's full name.
1214+
1215+ Raises:
1216+ * ValueError: If ` uf ` is an empty string or is not a valid UF code.
1217+
1218+ Example:
1219+
1220+ ``` python
1221+ >> > from brutils.ibge.uf import convert_uf_to_name
1222+ >> > convert_uf_to_name(' SP' )
1223+ ' São Paulo'
1224+ >> > convert_uf_to_name(' rj' )
1225+ ' Rio de Janeiro'
1226+ ```
1227+
12031228## Holidays
12041229
12051230### is_holiday
Original file line number Diff line number Diff line change 3737 get_code_by_municipality_name ,
3838 get_municipality_by_code ,
3939)
40- from brutils .ibge .uf import convert_code_to_uf
40+ from brutils .ibge .uf import convert_code_to_uf , convert_uf_to_name
4141
4242# Legal Process Imports
4343from brutils .legal_process import format_legal_process
127127 "is_valid_voter_id" ,
128128 # IBGE
129129 "convert_code_to_uf" ,
130+ "convert_uf_to_name" ,
130131 "get_municipality_by_code" ,
131132 "get_code_by_municipality_name" ,
132133 # Date Utils
Original file line number Diff line number Diff line change 1- from brutils .data .enums .uf import CODE_TO_UF
1+ from brutils .data .enums .uf import CODE_TO_UF , UF
22
33
44def convert_code_to_uf (code ): # type: (str) -> str | None
@@ -30,3 +30,37 @@ def convert_code_to_uf(code): # type: (str) -> str | None
3030 result = CODE_TO_UF (code ).name
3131
3232 return result
33+
34+
35+ def convert_uf_to_name (uf : str ) -> str :
36+ """
37+ Convert a Brazilian UF code (e.g., 'SP') to its full state name ('São Paulo').
38+
39+ The lookup is case-insensitive and ignores surrounding whitespace.
40+
41+ Args:
42+ uf (str): Two-letter UF code.
43+
44+ Returns:
45+ str: The full state name.
46+
47+ Raises:
48+ ValueError: If `uf` is not a non-empty string or is not a valid UF code.
49+
50+ Examples:
51+ >>> convert_uf_to_name('SP')
52+ 'São Paulo'
53+ >>> convert_uf_to_name('rj')
54+ 'Rio de Janeiro'
55+ """
56+ if not uf or not isinstance (uf , str ):
57+ raise ValueError ('UF must be a non-empty string.' )
58+
59+ federal_unit = uf .strip ().upper ()
60+
61+ if federal_unit not in UF .__members__ :
62+ raise ValueError (f'Invalid UF: { uf } ' )
63+
64+ result = UF [federal_unit ].value
65+
66+ return result
Original file line number Diff line number Diff line change 11from unittest import TestCase
22
3- from brutils .ibge .uf import convert_code_to_uf
3+ from brutils .ibge .uf import convert_code_to_uf , convert_uf_to_name
44
55
66class TestUF (TestCase ):
@@ -16,3 +16,17 @@ def test_convert_code_to_uf(self):
1616 self .assertIsNone (convert_code_to_uf ("00" ))
1717 self .assertIsNone (convert_code_to_uf ("" ))
1818 self .assertIsNone (convert_code_to_uf ("AB" ))
19+
20+ def test_convert_uf_to_name (self ):
21+ # Testes para códigos válidos
22+ self .assertEqual (convert_uf_to_name ("SP" ), "São Paulo" )
23+ self .assertEqual (convert_uf_to_name ("RJ" ), "Rio de Janeiro" )
24+ self .assertEqual (convert_uf_to_name ("MG" ), "Minas Gerais" )
25+ self .assertEqual (convert_uf_to_name ("DF" ), "Distrito Federal" )
26+ self .assertEqual (convert_uf_to_name ("df" ), "Distrito Federal" )
27+
28+ # Testes para códigos inválidos
29+ with self .assertRaises (ValueError ):
30+ convert_uf_to_name ("XX" )
31+ with self .assertRaises (ValueError ):
32+ convert_uf_to_name ("" )
You can’t perform that action at this time.
0 commit comments