示例#1
0
 def _coerce(self, value):
     if value is not None and not isinstance(value, NumberRange):
         if (isinstance(value, six.string_types)
                 or isinstance(value, six.integer_types)):
             value = NumberRange(value)
         else:
             raise TypeError('Could not coerce value to NumberRange.')
     return value
示例#2
0
 def test_eq_operator(self):
     assert NumberRange(1, 3) == NumberRange(1, 3)
     assert not NumberRange(1, 3) == NumberRange(1, 4)
示例#3
0
 def test_supports_integers(self):
     num_range = NumberRange(3)
     assert num_range.lower == 3
     assert num_range.upper == 3
示例#4
0
 def test_supports_exact_ranges_as_strings(self):
     num_range = NumberRange('3')
     assert num_range.lower == 3
     assert num_range.upper == 3
示例#5
0
 def process_result_value(self, value, dialect):
     if value:
         return NumberRange(value)
     return value
示例#6
0
def test_str_representation():
    assert str(NumberRange(1, 3)) == '1 - 3'
    assert str(NumberRange(1, 1)) == '1'
示例#7
0
 def test_le_operator(self):
     assert NumberRange(0, 2) <= NumberRange(1, 3)
     assert NumberRange(1, 3) >= NumberRange(1, 3)
示例#8
0
 def test_support_range_object(self):
     num_range = NumberRange(NumberRange(1, 3))
     assert num_range.lower == 1
     assert num_range.upper == 3
示例#9
0
 def test_isub_operator(self):
     range_ = NumberRange(1, 3)
     range_ -= NumberRange(1, 2)
     assert range_ == NumberRange(-1, 2)
示例#10
0
 def test_sub_operator(self):
     assert NumberRange(1, 3) - NumberRange(1, 2) == NumberRange(-1, 2)
示例#11
0
 def test_add_operator(self):
     assert NumberRange(1, 2) + NumberRange(1, 2) == NumberRange(2, 4)
示例#12
0
 def test_supports_multiple_args(self):
     num_range = NumberRange(1, 3)
     assert num_range.lower == 1
     assert num_range.upper == 3
示例#13
0
def test_closed(number_range, is_closed):
    assert NumberRange(number_range).closed == is_closed
示例#14
0
def test_open(number_range, is_open):
    assert NumberRange(number_range).open == is_open
示例#15
0
 def _coerce(self, value):
     if value is not None:
         value = NumberRange(value)
     return value
示例#16
0
 def test_ne_operator(self):
     assert not NumberRange(1, 3) != NumberRange(1, 3)
     assert NumberRange(1, 3) != NumberRange(1, 4)
示例#17
0
 def test_gt_operator(self):
     assert NumberRange(1, 3) > NumberRange(0, 2)
     assert not NumberRange(2, 3) > NumberRange(2, 3)
示例#18
0
 def test_iadd_operator(self):
     range_ = NumberRange(1, 2)
     range_ += NumberRange(1, 2)
     assert range_ == NumberRange(2, 4)
示例#19
0
 def test_lt_operator(self):
     assert NumberRange(0, 2) < NumberRange(1, 3)
     assert not NumberRange(2, 3) < NumberRange(2, 3)
示例#20
0
 def test_supports_strings_with_spaces(self):
     num_range = NumberRange('1 - 3')
     assert num_range.lower == 1
     assert num_range.upper == 3
示例#21
0
 def test_integer_comparison(self):
     assert NumberRange(2, 2) <= 3
     assert NumberRange(1, 3) >= 0
     assert NumberRange(2, 2) == 2
     assert NumberRange(2, 2) != 3
示例#22
0
 def test_supports_strings_with_bounds(self):
     num_range = NumberRange('[1, 3]')
     assert num_range.lower == 1
     assert num_range.upper == 3
示例#23
0
def test_raises_exception_for_badly_constructed_range(number_range):
    with raises(RangeBoundsException):
        NumberRange(number_range)
示例#24
0
 def test_empty_string_as_upper_bound(self):
     num_range = NumberRange('[1,)')
     assert num_range.lower == 1
     assert num_range.upper == float('inf')