Skip to content

Commit

Permalink
Added dod_print method. Coverage is now 85% (#74)
Browse files Browse the repository at this point in the history
* Added dod_print method. Coverage is now 85%

* Added dod documentation

* Added dod documentation
  • Loading branch information
turulomio committed Mar 22, 2024
1 parent 1525535 commit 1f7fdf2
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
1 change: 1 addition & 0 deletions jupyter/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ format: jb-book
root: intro
chapters:
- file: casts
- file: dod
- file: lod
- file: lod_xyv
- file: lod_ymv
Expand Down
30 changes: 30 additions & 0 deletions jupyter/dod.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
jupytext:
formats: md:myst
text_representation:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.5
kernelspec:
display_name: Python 3
language: python
name: python3
---

# DOD

## dod_print

Prints in console a dictionary of nested dictionaries nicely

```{code-cell}
from pydicts import dod
from datetime import date, datetime
from decimal import Decimal
d={"a": datetime.now(), "b": date.today(), "c": Decimal('12.32'), "d": None, "e": int(12), "f":None, "g":True, "h":False, "nested": {"x":1, "y":2, "z":{"n":4, "m":5, "o":6}}}
dod_={}
dod_["first"]=d
dod_["second"]=d
dod.dod_print(dod_)
```
6 changes: 4 additions & 2 deletions pydicts.epj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"header": {
"comment": "eric project file for project pydicts",
"copyright": "Copyright (C) 2024 , ",
"saved": "2024-03-21, 07:01:17"
"saved": "2024-03-22, 05:56:31"
},
"project": {
"AUTHOR": "",
Expand Down Expand Up @@ -63,6 +63,7 @@
"jupyter/casts.md",
"jupyter/changelog.md",
"jupyter/currency.md",
"jupyter/dod.md",
"jupyter/intro.md",
"jupyter/lod.md",
"jupyter/lod_xyv.md",
Expand All @@ -71,7 +72,6 @@
"jupyter/myjsonencoder.md",
"jupyter/percentage.md",
"jupyter/pylatex.md",
"jupyter/requirements.txt",
"pydicts.epj",
"pydicts/currencies.json",
"pyproject.toml"
Expand All @@ -93,6 +93,7 @@
"pydicts/casts.py",
"pydicts/classes.py",
"pydicts/currency.py",
"pydicts/dod.py",
"pydicts/exceptions.py",
"pydicts/lod.py",
"pydicts/lod_xyv.py",
Expand All @@ -105,6 +106,7 @@
"pydicts/tests/__init__.py",
"pydicts/tests/test_casts.py",
"pydicts/tests/test_currency.py",
"pydicts/tests/test_dod.py",
"pydicts/tests/test_lod.py",
"pydicts/tests/test_lod_ymv.py",
"pydicts/tests/test_lol.py",
Expand Down
17 changes: 17 additions & 0 deletions pydicts/dod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from gettext import translation
from importlib.resources import files
from pprint import PrettyPrinter

try:
t=translation('pydicts', files("pydicts") / 'locale')
_=t.gettext
except:
_=str

def dod_print(dod_, indent=4, depth=None, width=80, sort_dicts=True):
"""
Make a nice print of a dictionary of nested dictionaries
"""
pp=PrettyPrinter(indent=4, compact=False, depth=None, width=width, sort_dicts=sort_dicts)
pp.pprint(dod_)

18 changes: 18 additions & 0 deletions pydicts/tests/test_dod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from datetime import datetime, date
from decimal import Decimal
from pydicts import dod
from pytest import fixture

empty_lod=[]

@fixture(autouse=True)
def reload_lod_():
d={"a": datetime.now(), "b": date.today(), "c": Decimal('12.32'), "d": None, "e": int(12), "f":None, "g":True, "h":False, "nested": {"x":1, "y":2, "z":{"n":4, "m":5, "o":6}}}
global dod_
dod_={}
dod_["first"]=d
dod_["second"]=d


def test_dod_print():
dod.dod_print(dod_)

0 comments on commit 1f7fdf2

Please sign in to comment.