Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

Commit

Permalink
Remove default min, max, and step for number data type (#75)
Browse files Browse the repository at this point in the history
* remove default range for number

* add test coverage for setting the step field in number type
  • Loading branch information
agermanidis committed Jul 26, 2019
1 parent b8304b2 commit 1c46d52
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
17 changes: 10 additions & 7 deletions runway/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,17 @@ def setup(opts):
:type description: string, optional
:param default: A default value for this number variable, defaults to 0
:type default: float, optional
:param min: The minimum allowed value of this number type, defaults to 0
:param min: The minimum allowed value of this number type
:type min: float, optional
:param max: The maximum allowed value of this number type, defaults to 1
:param max: The maximum allowed value of this number type
:type max: float, optional
:param step: The step size of this number type. This argument define the minimum change \
of value associated with this number type. E.g., a step size of `0.1` would allow this data \
type to take on the values ``[0.0, 0.1, 0.2, ..., 1.0]``. Defaults to 1.
type to take on the values ``[0.0, 0.1, 0.2, ..., 1.0]``.
:type step: float, optional
"""

def __init__(self, description=None, default=0, min=0, max=1, step=1):
def __init__(self, description=None, default=0, step=None, min=None, max=None):
super(number, self).__init__('number', description=description)
self.default = default
self.min = min
Expand All @@ -371,9 +371,12 @@ def serialize(self, value):
def to_dict(self):
ret = super(number, self).to_dict()
ret['default'] = self.default
ret['min'] = self.min
ret['max'] = self.max
ret['step'] = self.step
if self.min is not None:
ret['min'] = self.min
if self.max is not None:
ret['max'] = self.max
if self.step is not None:
ret['step'] = self.step
return ret


Expand Down
4 changes: 2 additions & 2 deletions tests/test_data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ def test_text_deserialize():
def test_number_to_dict():
default = 42
description = 'A description about this variable.'
num = number(default=default, description=description, min=10, max=100)
num = number(default=default, description=description, min=10, max=100, step=10)
obj = num.to_dict()
assert obj['type'] == 'number'
assert obj['default'] == default
assert obj['min'] == 10
assert obj['max'] == 100
assert obj['step'] == 1
assert obj['step'] == 10
assert obj['description'] == description

def test_number_serialization():
Expand Down
6 changes: 1 addition & 5 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ def test_model_setup_and_command():
'type': 'number',
'name': 'output',
'description': 'An output number.',
'default': 0,
'min': 0,
'max': 1,
'step': 1
'default': 0
}]
}]
}
Expand Down Expand Up @@ -334,7 +331,6 @@ def command_2(opts):
'min': 10,
'default': 0,
'max': 100,
'step': 1,
'type': 'number',
'description': None
},
Expand Down

0 comments on commit 1c46d52

Please sign in to comment.