Ejemplo n.º 1
0
def test_and(aggregator):
    construction = ((aggregator.centre == mock.Gaussian) & (aggregator.centre.x == 0))
    assert construction == q.Q(
        "centre",
        q.And(
            q.T(mock.Gaussian),
            q.Q(
                "x",
                q.V(
                    "=", 0
                )
            )
        )
    )
Ejemplo n.º 2
0
    def test_complicated(self, less_than, greater_than):
        first = q.Q("a", q.Q("b", q.And(q.Q("c", less_than), greater_than)))

        second = q.Q("a", q.Q("b", q.Q("c", greater_than)))

        combined = q.Q(
            "a",
            q.Q("b",
                q.And(q.Q("c", q.And(less_than, greater_than)), greater_than)))

        assert first & second == combined
Ejemplo n.º 3
0
    def test_with_string(self):
        query = q.Q("a", q.SV("=", 'value'))

        assert query.query == ("SELECT parent_id "
                               "FROM object AS o "
                               "JOIN string_value AS sv "
                               "ON o.id = sv.id "
                               "WHERE (o.name = 'a' "
                               "AND sv.value = 'value')")
Ejemplo n.º 4
0
    def test_with_value(self):
        query = q.Q("a", q.V("=", 1))

        assert query.query == ("SELECT parent_id "
                               "FROM object AS o "
                               "JOIN value AS v "
                               "ON o.id = v.id "
                               "WHERE (o.name = 'a' "
                               "AND v.value = 1)")
Ejemplo n.º 5
0
    def for_name(name: str) -> q.Q:
        """
        Create a query for fits based on the name of a
        top level instance attribute

        Parameters
        ----------
        name
            The name of the attribute. e.g. galaxies

        Returns
        -------
        A query generating object
        """
        return q.Q(name)
Ejemplo n.º 6
0
def test_second():
    assert q.Q("a") & q.Q("a", q.Q("b")) == q.Q("a", q.Q("b"))
Ejemplo n.º 7
0
def test_simple(aggregator):
    assert aggregator.centre == q.Q("centre")
Ejemplo n.º 8
0
def make_second_level(less_than, greater_than):
    return q.Q("a", q.And(less_than, q.Q('b', greater_than)))
Ejemplo n.º 9
0
def test_trivial():
    assert q.Q("a") & q.Q("a") == q.Q("a")
Ejemplo n.º 10
0
def test_with_string(aggregator):
    assert (aggregator.centre == "centre") == q.Q("centre", q.SV("=", "centre"))
Ejemplo n.º 11
0
def test_less_than(aggregator):
    assert (aggregator.centre < 1) == q.Q("centre", q.V("<", 1))
Ejemplo n.º 12
0
def test_less_than(aggregator):
    assert (aggregator.model.centre < 1).query == q.Q("centre", q.V("<",
                                                                    1)).query
Ejemplo n.º 13
0
def test_third_level(aggregator):
    assert (aggregator.lens.centre.x == 1) == q.Q("lens", q.Q("centre", q.Q("x", q.V("=", 1))))
Ejemplo n.º 14
0
def test_with_string(aggregator):
    assert (aggregator.model.centre == "centre").query == q.Q(
        "centre", q.SV("=", "centre")).query
Ejemplo n.º 15
0
def test_greater_than(aggregator):
    assert (aggregator.model.centre > 1).query == q.Q("centre", q.V(">",
                                                                    1)).query
Ejemplo n.º 16
0
def test_simple(aggregator):
    assert aggregator.model.centre.query == q.Q("centre").query
Ejemplo n.º 17
0
def test_with_type(aggregator):
    assert (aggregator.model.centre == af.Gaussian).query == q.Q(
        "centre", q.T(af.Gaussian)).query
Ejemplo n.º 18
0
def test_with_value(aggregator):
    assert (aggregator.model.centre == 1).query == q.Q("centre", q.V("=",
                                                                     1)).query
Ejemplo n.º 19
0
def test_with_value(aggregator):
    assert (aggregator.centre == 1) == q.Q("centre", q.V("=", 1))
Ejemplo n.º 20
0
def test_less_than_equals(aggregator):
    assert (aggregator.model.centre <= 1).query == q.Q("centre", q.V("<=",
                                                                     1)).query
Ejemplo n.º 21
0
def test_second_level(aggregator):
    assert (aggregator.lens.centre == 1) == q.Q("lens", q.Q("centre", q.V("=", 1)))
Ejemplo n.º 22
0
def test_and(aggregator):
    construction = ((aggregator.model.centre == af.Gaussian) &
                    (aggregator.model.centre.x == 0))
    assert construction.query == q.Q(
        "centre", q.And(q.T(af.Gaussian), q.Q("x", q.V("=", 0)))).query
Ejemplo n.º 23
0
def test_with_type(aggregator):
    assert (aggregator.centre == mock.Gaussian) == q.Q("centre", q.T(mock.Gaussian))
Ejemplo n.º 24
0
def test_greater_than_equals(aggregator):
    assert (aggregator.centre >= 1) == q.Q("centre", q.V(">=", 1))
Ejemplo n.º 25
0
def test_greater_than(aggregator):
    assert (aggregator.centre > 1) == q.Q("centre", q.V(">", 1))
Ejemplo n.º 26
0
def make_simple_and(less_than, greater_than):
    return q.Q("a", q.And(less_than, greater_than))
Ejemplo n.º 27
0
def test_less_than_equals(aggregator):
    assert (aggregator.centre <= 1) == q.Q("centre", q.V("<=", 1))
Ejemplo n.º 28
0
def make_simple_or(less_than, greater_than):
    return q.Q("a", q.Or(less_than, greater_than))
Ejemplo n.º 29
0
def test_and_commutativity():
    a_and_b = q.And(q.Q("a"), q.Q("b"))
    combined = a_and_b & q.Q("c")

    assert combined == q.And(q.Q("a"), q.Q("b"), q.Q("c"))
    assert len(combined.conditions) == 3
Ejemplo n.º 30
0
def test_single_argument():
    assert isinstance(q.And(q.Q("a")), q.Q)