Skip to content
This repository was archived by the owner on Feb 13, 2021. It is now read-only.

Commit d857cd9

Browse files
author
Thiago C. D'Ávila
authored
Merge pull request #161 from staticdev/fix-init
Fix init
2 parents 0b70813 + 0f3f70e commit d857cd9

4 files changed

Lines changed: 145 additions & 66 deletions

File tree

README.rst

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Humanizer Portugues
3636
Features
3737
--------
3838

39-
* This lib contains various humanization methods such as transforming a time difference in a human-readable duration 'três minutos atrás' (three minutes ago) or in a phrase.
39+
* This lib contains various humanization methods such as transforming a time difference in a human-readable duration "três minutos atrás" (three minutes ago) or in a phrase.
4040

4141

4242
Requirements
@@ -65,108 +65,109 @@ Import the lib with:
6565
import humanizer_portugues
6666
6767
68-
Humanization of dates and time:
68+
Humanization filesizes:
6969

7070
.. code-block:: python
7171
72-
import datetime
73-
humanizer_portugues.natural_period(datetime.time(5, 30, 0).hour)
74-
'manhã'
75-
76-
humanizer_portugues.natural_clock(datetime.time(0, 30, 0))
77-
'zero hora e trinta minutos'
78-
79-
humanizer_portugues.natural_clock(datetime.time(0, 30, 0), formal=False)
80-
'meia noite e meia'
81-
82-
humanizer_portugues.natural_day(datetime.datetime.now())
83-
'hoje'
84-
85-
humanizer_portugues.natural_delta(datetime.timedelta(seconds=1001))
86-
'16 minutos'
87-
88-
humanizer_portugues.natural_day(datetime.datetime.now() - datetime.timedelta(days=1))
89-
'ontem'
90-
91-
humanizer_portugues.natural_day(datetime.date(2007, 6, 5))
92-
'5 de junho'
93-
94-
humanizer_portugues.natural_date(datetime.date(2007, 6, 5))
95-
'5 de junho de 2007'
72+
humanizer_portugues.natural_size(1000000)
73+
"1.0 MB"
9674
97-
humanizer_portugues.natural_time(datetime.datetime.now() - datetime.timedelta(seconds=1))
98-
'há um segundo'
75+
humanizer_portugues.natural_size(1000000, binary=True)
76+
"976.6 KiB"
9977
100-
humanizer_portugues.natural_time(datetime.datetime.now() - datetime.timedelta(seconds=3600))
101-
'há uma hora'
78+
humanizer_portugues.natural_size(1000000, gnu=True)
79+
"976.6K"
10280
10381
104-
Humanization filesizes:
82+
Humanization of lists:
10583

10684
.. code-block:: python
10785
108-
humanizer_portugues.natural_size(1000000)
109-
'1.0 MB'
86+
humanizer_portugues.natural_list(["Cláudio", "Maria"], ",")
87+
"Cláudio, Maria"
11088
111-
humanizer_portugues.natural_size(1000000, binary=True)
112-
'976.6 KiB'
89+
humanizer_portugues.natural_list(["Cláudio", "Maria"], ",", "e")
90+
"Cláudio e Maria"
11391
114-
humanizer_portugues.natural_size(1000000, gnu=True)
115-
'976.6K'
92+
humanizer_portugues.natural_list(["Cláudio", "Maria", "José"], ";", "ou")
93+
"Cláudio; Maria ou José"
11694
11795
11896
Humanization of integers:
11997

12098
.. code-block:: python
12199
100+
humanizer_portugues.ap_number(4)
101+
"quatro"
102+
103+
humanizer_portugues.ap_number(41)
104+
"41"
105+
122106
humanizer_portugues.int_comma(12345)
123-
'12,345'
107+
"12,345"
124108
125109
humanizer_portugues.int_word(123455913)
126-
'123.5 milhão'
110+
"123.5 milhão"
127111
128112
humanizer_portugues.int_word(12345591313)
129-
'12.3 bilhão'
130-
131-
humanizer_portugues.ap_number(4)
132-
'quatro'
133-
134-
humanizer_portugues.ap_number(41)
135-
'41'
113+
"12.3 bilhão"
136114
137115
138116
Humanization of floating point numbers:
139117

140118
.. code-block:: python
141119
142120
humanizer_portugues.fractional(1/3)
143-
'1/3'
121+
"1/3"
144122
145123
humanizer_portugues.fractional(1.5)
146-
'1 1/2'
124+
"1 1/2"
147125
148126
humanizer_portugues.fractional(0.3)
149-
'3/10'
127+
"3/10"
150128
151129
humanizer_portugues.fractional(0.333)
152-
'333/1000'
130+
"333/1000"
153131
154132
humanizer_portugues.fractional(1)
155-
'1'
133+
"1"
156134
157135
158-
Humanization of lists:
136+
Humanization of dates and time:
159137

160138
.. code-block:: python
161139
162-
humanizer_portugues.natural_list(['Cláudio', 'Maria'], ',')
163-
'Cláudio, Maria'
140+
import datetime
141+
142+
humanizer_portugues.natural_clock(datetime.time(0, 30, 0))
143+
"zero hora e trinta minutos"
144+
145+
humanizer_portugues.natural_clock(datetime.time(0, 30, 0), formal=False)
146+
"meia noite e meia"
147+
148+
humanizer_portugues.natural_date(datetime.date(2007, 6, 5))
149+
"5 de junho de 2007"
150+
151+
humanizer_portugues.natural_day(datetime.datetime.now())
152+
"hoje"
153+
154+
humanizer_portugues.natural_day(datetime.datetime.now() - datetime.timedelta(days=1))
155+
"ontem"
156+
157+
humanizer_portugues.natural_day(datetime.date(2007, 6, 5))
158+
"5 de junho"
159+
160+
humanizer_portugues.natural_delta(datetime.timedelta(seconds=1001))
161+
"16 minutos"
164162
165-
humanizer_portugues.natural_list(['Cláudio', 'Maria'], ',', 'e')
166-
'Cláudio e Maria'
163+
humanizer_portugues.natural_period(datetime.time(5, 30, 0).hour)
164+
"manhã"
167165
168-
humanizer_portugues.natural_list(['Cláudio', 'Maria', 'José'], ';', 'ou')
169-
'Cláudio; Maria ou José'
166+
humanizer_portugues.natural_time(datetime.datetime.now() - datetime.timedelta(seconds=1))
167+
"há um segundo"
168+
169+
humanizer_portugues.natural_time(datetime.datetime.now() - datetime.timedelta(seconds=3600))
170+
"há uma hora"
170171
171172
172173
Contributing

src/humanizer_portugues/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
"""Humanizer portugues."""
22
from humanizer_portugues.filesize import natural_size
33
from humanizer_portugues.list import natural_list
4+
from humanizer_portugues.number import ap_number
45
from humanizer_portugues.number import fractional
56
from humanizer_portugues.number import int_comma
67
from humanizer_portugues.number import int_word
78
from humanizer_portugues.number import ordinal
9+
from humanizer_portugues.time import natural_clock
810
from humanizer_portugues.time import natural_date
911
from humanizer_portugues.time import natural_day
12+
from humanizer_portugues.time import natural_delta
1013
from humanizer_portugues.time import natural_period
1114
from humanizer_portugues.time import natural_time
1215
from humanizer_portugues.time import natural_year
@@ -16,6 +19,7 @@
1619
"fractional",
1720
"int_comma",
1821
"int_word",
22+
"natural_clock",
1923
"natural_date",
2024
"natural_day",
2125
"natural_delta",

src/humanizer_portugues/time.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def _informal_time(value: datetime.time, hour: int) -> str:
168168

169169

170170
def natural_clock(value: Any, formal: bool = True) -> Any:
171-
"""Returns human-readable time.
171+
"""Return human-readable time.
172172
173173
Compares time values to present time returns representing readable of time
174174
with the given day period.
@@ -205,7 +205,7 @@ def natural_clock(value: Any, formal: bool = True) -> Any:
205205

206206

207207
def abs_timedelta(delta: datetime.timedelta) -> datetime.timedelta:
208-
"""Returns an "absolute" value for a timedelta.
208+
"""Return an "absolute" value for a timedelta.
209209
210210
Args:
211211
delta (datetime.timedelta): relative timedelta.
@@ -220,7 +220,7 @@ def abs_timedelta(delta: datetime.timedelta) -> datetime.timedelta:
220220

221221

222222
def date_and_delta(value: Any) -> Tuple[Any, Any]:
223-
"""Returns date and timedelta.
223+
"""Return date and timedelta.
224224
225225
Turn a value into a date and a timedelta which represents how long ago
226226
it was. If that's not possible, return (None, value).
@@ -297,7 +297,7 @@ def more_than_one_year(years: int) -> str:
297297

298298

299299
def natural_delta(value: Any, use_months: bool = True) -> Any:
300-
"""Returns human-readable time difference.
300+
"""Return human-readable time difference.
301301
302302
Given a timedelta or a number of seconds, return a natural
303303
representation of the amount of time elapsed. This is similar to
@@ -332,7 +332,7 @@ def natural_delta(value: Any, use_months: bool = True) -> Any:
332332

333333

334334
def natural_time(value: Any, future: bool = False, use_months: bool = True) -> Any:
335-
"""Returns human-readable time.
335+
"""Return human-readable time.
336336
337337
Given a datetime or a number of seconds, return a natural representation
338338
of that time in a resolution that makes sense. This is more or less
@@ -367,7 +367,7 @@ def natural_time(value: Any, future: bool = False, use_months: bool = True) -> A
367367

368368

369369
def natural_day(value: Any, has_year: bool = False) -> Any:
370-
"""Returns human-readable day.
370+
"""Return human-readable day.
371371
372372
For date values that are tomorrow, today or yesterday compared to
373373
present day returns representing string. Otherwise, returns a string
@@ -400,7 +400,7 @@ def natural_day(value: Any, has_year: bool = False) -> Any:
400400

401401

402402
def natural_year(value: Any) -> Any:
403-
"""Returns human-readable year.
403+
"""Return human-readable year.
404404
405405
For date values that are last year, this year or next year compared to
406406
present year returns representing string. Otherwise, returns a string
@@ -428,7 +428,7 @@ def natural_year(value: Any) -> Any:
428428

429429

430430
def natural_date(value: Any) -> Any:
431-
"""Returns human-readable date.
431+
"""Return human-readable date.
432432
433433
Like natural_day, but will append a year for dates that are a year
434434
ago or more.

tests/test_init.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"""__init__ tests."""
2+
import datetime
3+
4+
import humanizer_portugues
5+
6+
7+
def test_natural_size() -> None:
8+
"""Call of natural_size from humanizer_portugues."""
9+
assert humanizer_portugues.natural_size(1000000) == "1.0 MB"
10+
11+
12+
def test_natural_list() -> None:
13+
"""Call of natural_list from humanizer_portugues."""
14+
assert (
15+
humanizer_portugues.natural_list(["Cláudio", "Maria"], ",") == "Cláudio, Maria"
16+
)
17+
18+
19+
def test_ap_number() -> None:
20+
"""Call of ap_number from humanizer_portugues."""
21+
assert humanizer_portugues.ap_number(4) == "quatro"
22+
23+
24+
def test_int_comma() -> None:
25+
"""Call of int_comma from humanizer_portugues."""
26+
assert humanizer_portugues.int_comma(12345) == "12,345"
27+
28+
29+
def test_int_word() -> None:
30+
"""Call of int_word from humanizer_portugues."""
31+
assert humanizer_portugues.int_word(123455913) == "123.5 milhão"
32+
33+
34+
def test_fractional() -> None:
35+
"""Call of fractional from humanizer_portugues."""
36+
assert humanizer_portugues.fractional(1 / 3) == "1/3"
37+
38+
39+
def test_natural_clock() -> None:
40+
"""Call of natural_clock from humanizer_portugues."""
41+
date = datetime.time(0, 30, 0)
42+
assert humanizer_portugues.natural_clock(date) == "zero hora e trinta minutos"
43+
44+
45+
def test_natural_date() -> None:
46+
"""Call of natural_date from humanizer_portugues."""
47+
date = datetime.date(2007, 6, 5)
48+
assert humanizer_portugues.natural_date(date) == "5 de junho de 2007"
49+
50+
51+
def test_natural_day() -> None:
52+
"""Call of natural_day from humanizer_portugues."""
53+
assert humanizer_portugues.natural_day(datetime.datetime.now()) == "hoje"
54+
55+
56+
def test_natural_delta() -> None:
57+
"""Call of natural_delta from humanizer_portugues."""
58+
delta = datetime.timedelta(seconds=1001)
59+
assert humanizer_portugues.natural_delta(delta) == "16 minutos"
60+
61+
62+
def test_natural_period() -> None:
63+
"""Call of natural_period from humanizer_portugues."""
64+
assert humanizer_portugues.natural_period(datetime.time(5, 30, 0).hour) == "manhã"
65+
66+
67+
def test_natural_time() -> None:
68+
"""Call of natural_time from humanizer_portugues."""
69+
assert (
70+
humanizer_portugues.natural_time(
71+
datetime.datetime.now() - datetime.timedelta(seconds=1)
72+
)
73+
== "há um segundo"
74+
)

0 commit comments

Comments
 (0)