Beispiel #1
0
 def test_where(self, source: frame.Queryable):
     """Where test."""
     self._subcondition(source, lambda s, e: s.where(e),
                        lambda q: q.prefilter)
     with pytest.raises(error.Syntax):
         source.where(
             function.Count(source.score) > 2)  # aggregation filter
Beispiel #2
0
 def test_select(self, source: frame.Queryable):
     """Select test."""
     assert source.select(source.score).selection[0] == source.score
     assert source.select(source.score,
                          source.surname).selection == (source.score,
                                                        source.surname)
     with pytest.raises(error.Syntax):
         source.select(
             source.reference().score)  # not subset of source columns
Beispiel #3
0
 def test_join(self, source: frame.Queryable, school: frame.Table):
     """Join test."""
     joined = source.join(school, school.sid == source.school)
     assert isinstance(joined.source, frame.Join)
     assert joined.source.kind == frame.Join.Kind.INNER
     assert joined.source.right == school
     assert joined.source.condition == function.Equal(
         school.sid, source.school)
     self._condition(source, lambda s, e: s.join(school, e),
                     lambda q: q.source.condition)
     with pytest.raises(error.Syntax):
         source.join(school,
                     function.Count(source.score) > 2)  # aggregation filter
Beispiel #4
0
 def test_orderby(self, source: frame.Queryable):
     """Orderby test."""
     assert source.orderby(
         source.score).ordering[0] == (source.score,
                                       series.Ordering.Direction.ASCENDING)
     assert source.orderby(source.score, source.surname,
                           'desc').ordering == (
                               (source.score,
                                series.Ordering.Direction.ASCENDING),
                               (source.surname,
                                series.Ordering.Direction.DESCENDING),
                           )
     assert source.orderby(source.score, 'DESC',
                           (source.surname, 'ASCENDING')).ordering == (
                               (source.score,
                                series.Ordering.Direction.DESCENDING),
                               (source.surname,
                                series.Ordering.Direction.ASCENDING),
                           )
     self._expression(source, lambda s, e: s.orderby(e),
                      lambda q: q.ordering[0].column)
Beispiel #5
0
 def _condition(
     cls,
     source: frame.Queryable,
     handler: typing.Callable[[frame.Queryable, series.Expression],
                              frame.Query],
     target: typing.Callable[[frame.Query], series.Expression],
 ):
     """Common condition testing routine."""
     cls._expression(source, handler, target)
     with pytest.raises(error.Syntax):
         handler(source, source.score + 1)  # not logical
     with pytest.raises(error.Syntax):  # not subset of source columns
         handler(source, source.reference().score == 'foo')
Beispiel #6
0
 def test_groupby(self, source: frame.Queryable):
     """Groupby test."""
     assert source.select(source.score.alias('foo')).groupby(
         source.score).grouping[0] == source.score
     assert source.select(source.score, source.surname).groupby(
         source.score, source.surname).grouping == (
             source.score,
             source.surname,
         )
     with pytest.raises(error.Syntax):
         source.select(source.score, source.surname).groupby(
             source.score)  # surname neither aggregate nor group
     with pytest.raises(error.Syntax):
         source.select(function.Count(source.score)).groupby(
             function.Count(source.score))  # grouping by aggregation
     assert source.select(source.score, function.Count(
         source.surname)).groupby(source.score)
     assert source.select(source.score,
                          function.Count(source.surname) + 1).groupby(
                              source.score)
     self._expression(source.select(source.score > 2),
                      lambda s, e: s.groupby(e), lambda q: q.grouping[0])
Beispiel #7
0
 def test_reference(self, source: frame.Queryable):
     """Test the queryable reference."""
     assert isinstance(source.reference(), frame.Reference)
Beispiel #8
0
 def test_limit(self, source: frame.Queryable):
     """Limit test."""
     assert source.limit(1).rows == (1, 0)
     assert source.limit(1, 1).rows == (1, 1)
Beispiel #9
0
 def test_having(self, source: frame.Queryable):
     """Having test."""
     self._subcondition(source, lambda s, e: s.having(e),
                        lambda q: q.postfilter)
     assert source.having(function.Count(source.score) >
                          2)  # aggregation filtering is valid for having