Exemplo n.º 1
0
def test__parse():
    """Test _parse function for ValueSet."""
    def test_TypeError(values):
        """Test TypeError raising in split_by_types."""
        with pytest.raises(TypeError) as excinfo:
            ValueSet._parse(values)

    # test standard type parsing
    standard_types = ValueSet._parse(
        [-1, -2, -1.0, -1.5, -1L, -2L, 'a', 'b', True, False,
         Interval(0, 10), Interval(0.0, 10.0), Interval(0L, 10L), Point(1.0)])

    assert standard_types == [-1.5, -1.0, 'a', 'b',
                              False, True, Interval(-2, 10),
                              Interval(0.0, 10.0), Interval(-2L, 10L),
                              Point(1.0)]

    # test single numbers being filtered by intervals
    number_filters = ValueSet._parse(
        [-2, 1, -1.5, 1.0, -2L, 1L,
            Interval(0, 10), Interval(0.0, 10.0), Interval(0L, 10L)])

    assert number_filters == [-2, -1.5, -2L, Interval(0, 10),
                              Interval(0.0, 10.0), Interval(0L, 10L)]

    interval_collapsing = ValueSet._parse(
        [Interval(0, 10), Interval(5, 15), Interval(7, 11), Interval(15, 25),
         Interval(-10, 500), Interval(0.0, 10.4), Interval(5.56, 15.33),
         Interval(7.765, 11.001), Interval(15.32, 25.77),
         Interval(-10.2, 500.442), Interval(0L, 10L), Interval(5L, 15L),
         Interval(7L, 11L), Interval(15L, 25L), Interval(-10L, 500L)])

    assert interval_collapsing == [
        Interval(-10, 500), Interval(-10.2, 500.442), Interval(-10L, 500L)]

    point_duplicates = ValueSet._parse([Point(1.0), Point(1.0), Point('x')])

    assert point_duplicates == [Point(1.0), Point('x')]

    line_segment_duplicates = ValueSet._parse(
        [LineSegment(Point(1.0), Point(0.0)),
         LineSegment(Point(1.0), Point(0.0)),
         LineSegment(Point('x'), Point('x')),
         LineSegment(Point('x', 'x'), Point('x', 'x')),
         LineSegment(Point('x', 'x'), Point('x', 'x'))])

    assert line_segment_duplicates == [LineSegment(Point(1.0), Point(0.0)),
                                       LineSegment(Point('x'), Point('x')),
                                       LineSegment(Point('x', 'x'), Point('x', 'x'))]
Exemplo n.º 2
0
 def test_TypeError(values):
     """Test TypeError raising in split_by_types."""
     with pytest.raises(TypeError) as excinfo:
         ValueSet._parse(values)