Skip to content

Commit 1d08b71

Browse files
committed
fully fixed all tests
1 parent d3dff6a commit 1d08b71

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

python_utils/converters.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
from __future__ import (absolute_import, division, print_function,
2-
unicode_literals)
1+
from __future__ import absolute_import
2+
from __future__ import division
3+
from __future__ import print_function
4+
from __future__ import unicode_literals
35

6+
import decimal
7+
import math
48
import re
9+
510
import six
6-
import math
7-
import decimal
811

912

1013
def to_int(input_, default=0, exception=(ValueError, TypeError), regexp=None):
@@ -263,22 +266,23 @@ def remap(value, old_min, old_max, new_min, new_max):
263266
>>> 0.1 + 0.1 + 0.1
264267
0.30000000000000004
265268
266-
If floating point remaps need to be done my suggstion is to pass at least one
267-
parameter as a `decimal.Decimal`. This will ensure that the output from this
268-
function is accurate. I left passing `floats` for backwards compatability and
269-
there is no conversion done from float to `decimal.Decimal` unless one of the passed
270-
parameters has a type of `decimal.Decimal`. This will ensure that any existing code
271-
that uses this funtion will work exactly how it has in the past.
269+
If floating point remaps need to be done my suggstion is to pass at least
270+
one parameter as a `decimal.Decimal`. This will ensure that the output
271+
from this function is accurate. I left passing `floats` for backwards
272+
compatability and there is no conversion done from float to
273+
`decimal.Decimal` unless one of the passed parameters has a type of
274+
`decimal.Decimal`. This will ensure that any existing code that uses this
275+
funtion will work exactly how it has in the past.
272276
273277
Some edge cases to test
274278
>>> remap(1, 0, 0, 1, 2)
275279
Traceback (most recent call last):
276-
...
280+
...
277281
ValueError: Input range (0-0) is empty
278282
279283
>>> remap(1, 1, 2, 0, 0)
280284
Traceback (most recent call last):
281-
...
285+
...
282286
ValueError: Output range (0-0) is empty
283287
284288
:param value: value to be converted
@@ -310,19 +314,19 @@ def remap(value, old_min, old_max, new_min, new_max):
310314
'''
311315

312316
if (
313-
isinstance(value, decimal.Decimal) or
314-
isinstance(old_min, decimal.Decimal) or
315-
isinstance(old_max, decimal.Decimal) or
316-
isinstance(new_min, decimal.Decimal) or
317-
isinstance(new_max, decimal.Decimal)
317+
isinstance(value, decimal.Decimal) or
318+
isinstance(old_min, decimal.Decimal) or
319+
isinstance(old_max, decimal.Decimal) or
320+
isinstance(new_min, decimal.Decimal) or
321+
isinstance(new_max, decimal.Decimal)
318322
):
319323
type_ = decimal.Decimal
320324
elif (
321-
isinstance(value, float) or
322-
isinstance(old_min, float) or
323-
isinstance(old_max, float) or
324-
isinstance(new_min, float) or
325-
isinstance(new_max, float)
325+
isinstance(value, float) or
326+
isinstance(old_min, float) or
327+
isinstance(old_max, float) or
328+
isinstance(new_min, float) or
329+
isinstance(new_max, float)
326330
):
327331
type_ = float
328332

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
tests_require=['pytest'],
3636
extras_require={
3737
'docs': [
38+
'six',
3839
'mock',
3940
'sphinx',
4041
'python-utils',

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ commands = py.test --basetemp="{envtmpdir}" --confcutdir=.. {posargs} python_uti
2020
[testenv:flake8]
2121
basepython = python3
2222
deps = flake8
23-
commands = flake8 --ignore=W391 python_utils {posargs}
23+
commands = flake8 python_utils {posargs}
2424

2525
[testenv:docs]
2626
basepython = python3

0 commit comments

Comments
 (0)