This file contains hidden or 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
import logging | |
logger = logging.getLogger() | |
logger.setLevel(logging.DEBUG) | |
logger.debug('Isso é uma log de debug') | |
logger.info('Isso é uma log de info') | |
logger.warning('Isso é uma log de warning') | |
logger.error('Isso é uma log de erro') | |
This file contains hidden or 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
if isinstance(root_value, dict): | |
+ breakpoint() | |
flatten_item = flatten_dict(root_value) |
This file contains hidden or 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
$ pytest --pdb |
This file contains hidden or 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
? -> Lista todos os comando | |
b[reak] -> define um ponto de parada no programa | |
c[ontinue] -> continua ate uma excessão ou um ponto de parada | |
n[ext] -> continua ate a proxima linha, sem entrar dentro de funções | |
s[tep] -> continua ate a proxima instrução, entrando dentro de funções | |
p -> print, imprime o valor | |
pp -> pretty print, imprime dicionarios e listas com espaçamentos e quebras de linha | |
l[ist] -> mostra o codigo perto de onde está sendo executado |
This file contains hidden or 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
>>> import util_test | |
>>> import pdb | |
>>> pdb.run('util_test.test_flatten_dict_nivel_separador()') | |
> <string>(1)<module>() | |
(Pdb) continue | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "/home/guiss/.asdf/installs/python/3.10.0/lib/python3.10/pdb.py", line 1607, in run | |
Pdb().run(statement, globals, locals) | |
File "/home/guiss/.asdf/installs/python/3.10.0/lib/python3.10/bdb.py", line 597, in run |
This file contains hidden or 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
$ pytest | |
========================= test session starts ========================= | |
platform linux -- Python 3.9.7, pytest-6.2.5, py-1.10.0, pluggy-0.13.1 | |
rootdir: /home/guiss/Projetos/Turing/Talks/Logs | |
collected 4 items | |
util_test.py ...F [100%] | |
============================== FAILURES =============================== | |
__________________ test_flatten_dict_nivel_separador __________________ |
This file contains hidden or 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
- flatten_root_key = separator.join([root_key, item_key]) | |
+ flatten_root_key = '.'.join([root_key, item_key]) |
This file contains hidden or 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
$ pytest | |
========================= test session starts ========================= | |
platform linux -- Python 3.9.7, pytest-6.2.5, py-1.10.0, pluggy-0.13.1 | |
rootdir: /home/guiss/Projetos/Turing/Talks/Logs | |
collected 4 items | |
util_test.py .... [100%] | |
======================== 4 passed in 0.01s ============================ |
This file contains hidden or 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
from util import flatten_dict | |
def test_flatten_dict_nivel_1(): | |
assert flatten_dict({'a': 1, 'b': 2}) == {'a': 1, 'b': 2} | |
def test_flatten_dict_nivel_3(): | |
assert flatten_dict({'a': 1, 'b': {'c': 2, 'd': 3}}) == \ | |
{'a': 1, 'b.c': 2, 'b.d': 3} | |
def test_flatten_dict_nivel_4(): |
This file contains hidden or 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
from typing import Dict, Any | |
def flatten_dict(root: Dict[str, Any], separator: str = '.') -> Dict[str, Any]: | |
""" | |
Tranforma dicionarios aninhados em um dicionario plano | |
Exemplo: | |
>>> flatten_dict({'a': 1, 'b': {'c': 2, 'd': 3}}) | |
>>> {'a': 1, 'b.c': 2, 'b.d': 3} | |
""" | |
flatten_root = {} | |
for root_key, root_value in root.items(): |