Exemplo n.º 1
0
 def test_infinite_lower_bound(self):
     building = self.Building(
         persons_at_night=NumberRange(-float('inf'), 1))
     self.session.add(building)
     self.session.commit()
     building = self.session.query(self.Building).first()
     assert building.persons_at_night.lower == -float('inf')
     assert building.persons_at_night.upper == 1
Exemplo n.º 2
0
 def process_formdata(self, valuelist):
     if valuelist:
         if valuelist[0] == u'' or valuelist[0] == '':
             self.data = None
         else:
             try:
                 self.data = NumberRange.from_str(valuelist[0])
             except NumberRangeException:
                 self.data = None
                 raise ValueError(self.gettext(self.error_msg))
Exemplo n.º 3
0
    def test_save_number_range(self):
        building = self.Building(
            persons_at_night=NumberRange(1, 3)
        )

        self.session.add(building)
        self.session.commit()
        building = self.session.query(self.Building).first()
        assert building.persons_at_night.min_value == 1
        assert building.persons_at_night.max_value == 3
Exemplo n.º 4
0
 def process_formdata(self, valuelist):
     if valuelist:
         if valuelist[0] == u'' or valuelist[0] == '':
             self.data = None
         else:
             try:
                 self.data = NumberRange.from_str(valuelist[0])
             except NumberRangeException:
                 self.data = None
                 raise ValueError(self.gettext(self.error_msg))
Exemplo n.º 5
0
    def test_nullify_number_range(self):
        building = self.Building(persons_at_night=NumberRange(1, 3))

        self.session.add(building)
        self.session.commit()

        building = self.session.query(self.Building).first()
        building.persons_at_night = None
        self.session.commit()

        building = self.session.query(self.Building).first()
        assert building.persons_at_night is None
Exemplo n.º 6
0
 def test_sub_operator(self):
     assert NumberRange(1, 3) - NumberRange(1, 2) == NumberRange(0, 1)
Exemplo n.º 7
0
 def test_add_operator(self):
     assert NumberRange(1, 2) + NumberRange(1, 2) == NumberRange(2, 4)
Exemplo n.º 8
0
 def test_from_normalized_str(self):
     assert str(NumberRange.from_normalized_str('[1,2]')) == '1 - 2'
     assert str(NumberRange.from_normalized_str('[1,3)')) == '1 - 2'
     assert str(NumberRange.from_normalized_str('(1,3)')) == '2'
Exemplo n.º 9
0
 def test_from_str_exception_handling(self):
     with raises(NumberRangeException):
         NumberRange.from_str('1 - ')
Exemplo n.º 10
0
 def test_from_str_supports_single_integers(self):
     number_range = NumberRange.from_str('1')
     assert number_range.min_value == 1
     assert number_range.max_value == 1
Exemplo n.º 11
0
 def test_raises_exception_for_badly_constructed_range(self):
     with raises(NumberRangeException):
         NumberRange(3, 2)
Exemplo n.º 12
0
 def test_str_representation(self):
     assert str(NumberRange(1, 3)) == '1 - 3'
     assert str(NumberRange(1, 1)) == '1'
Exemplo n.º 13
0
 def test_equality_operator(self):
     assert NumberRange(1, 3) == NumberRange(1, 3)