Skip to content

Commit

Permalink
Altered gen_integer() to properly check for long() on Python 2.
Browse files Browse the repository at this point in the history
Added Jonathan Edwards to AUTHORS

Updated gen_integer() to not throw error on long sys.maxsize

Updated test to reflect changes in gen_integer()

Updated isinstance() test to match all integer types

Updated to reflect change in gen_integer()
  • Loading branch information
apense committed Dec 18, 2014
1 parent 99a11f7 commit 9dcf2e7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ Contributors
- Jacob Callahan `@JacobCallahan <https://github.com/JacobCallahan>`_
- Jefferson Fausto Vaz `@faustovaz <https://github.com/faustovaz/>`_
- Jeremy Audet `@Ichimonji10 <https://github.com/Ichimonji10/>`_
- Jonathan Edwards `@apense <https://github.com/apense/>`_
- Kedar Bidarkar `@kbidarkar <https://github.com/kbidarkar/>`_
- Sachin Ghai `@sghai <https://github.com/sghai/>`_
- Sachin Ghai `@sghai <https://github.com/sghai/>`_
9 changes: 7 additions & 2 deletions fauxfactory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,15 @@ def gen_integer(min_value=None, max_value=None):
if max_value is None:
max_value = _max_value

if sys.version < '3':
integer_types = (int, long,)
else:
integer_types = (int,)

# Perform some validations
if not isinstance(min_value, int) or min_value < _min_value:
if not isinstance(min_value, integer_types) or min_value < _min_value:
raise ValueError("\'%s\' is not a valid minimum." % min_value)
if not isinstance(max_value, int) or max_value > _max_value:
if not isinstance(max_value, integer_types) or max_value > _max_value:
raise ValueError("\'%s\' is not a valid maximum." % max_value)

value = random.randint(min_value, max_value)
Expand Down
6 changes: 5 additions & 1 deletion tests/test_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ def test_gen_integer_1(self):
@Assert: A random integer is created
"""

if sys.version < '3':
integer_types = (int, long,)
else:
integer_types = (int,)
result = gen_integer()
self.assertTrue(
isinstance(result, int), "A valid integer was not generated.")
isinstance(result, integer_types), "A valid integer was not generated.")

def test_gen_integer_2(self):
"""
Expand Down

0 comments on commit 9dcf2e7

Please sign in to comment.