Skip to content

Commit

Permalink
🦉 Updates from OwlBot post-processor
Browse files Browse the repository at this point in the history
  • Loading branch information
gcf-owl-bot[bot] committed Aug 29, 2023
1 parent e560662 commit bd52f4b
Showing 1 changed file with 42 additions and 23 deletions.
65 changes: 42 additions & 23 deletions tests/system/test_aggregation_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ def test_count_query_default(aggregation_query_client, nested_query, database_id


@pytest.mark.parametrize("database_id", [None, _helpers.TEST_DATABASE], indirect=True)
def test_count_query_with_alias(
aggregation_query_client, nested_query, database_id
):
def test_count_query_with_alias(aggregation_query_client, nested_query, database_id):
query = nested_query

aggregation_query = aggregation_query_client.aggregation_query(query)
Expand Down Expand Up @@ -142,7 +140,9 @@ def test_avg_query_default(aggregation_query_client, nested_query, database_id):
assert len(result[0]) == 1
r = result[0][0]
assert r.alias == "property_1"
expected_avg = sum(c["appearances"] for c in populate_datastore.CHARACTERS) / len(populate_datastore.CHARACTERS)
expected_avg = sum(c["appearances"] for c in populate_datastore.CHARACTERS) / len(
populate_datastore.CHARACTERS
)
assert r.value == expected_avg


Expand All @@ -157,14 +157,14 @@ def test_avg_query_with_alias(aggregation_query_client, nested_query, database_i
assert len(result[0]) == 1
r = result[0][0]
assert r.alias == "avg_appearances"
expected_avg = sum(c["appearances"] for c in populate_datastore.CHARACTERS) / len(populate_datastore.CHARACTERS)
expected_avg = sum(c["appearances"] for c in populate_datastore.CHARACTERS) / len(
populate_datastore.CHARACTERS
)
assert r.value == expected_avg


@pytest.mark.parametrize("database_id", [None, _helpers.TEST_DATABASE], indirect=True)
def test_count_query_with_limit(
aggregation_query_client, nested_query, database_id
):
def test_count_query_with_limit(aggregation_query_client, nested_query, database_id):
query = nested_query

aggregation_query = aggregation_query_client.aggregation_query(query)
Expand All @@ -187,10 +187,9 @@ def test_count_query_with_limit(
assert r.alias == "total_up_to"
assert r.value == limit


@pytest.mark.parametrize("database_id", [None, _helpers.TEST_DATABASE], indirect=True)
def test_sum_query_with_limit(
aggregation_query_client, nested_query, database_id
):
def test_sum_query_with_limit(aggregation_query_client, nested_query, database_id):
query = nested_query

aggregation_query = aggregation_query_client.aggregation_query(query)
Expand All @@ -206,9 +205,7 @@ def test_sum_query_with_limit(


@pytest.mark.parametrize("database_id", [None, _helpers.TEST_DATABASE], indirect=True)
def test_avg_query_with_limit(
aggregation_query_client, nested_query, database_id
):
def test_avg_query_with_limit(aggregation_query_client, nested_query, database_id):
query = nested_query

aggregation_query = aggregation_query_client.aggregation_query(query)
Expand All @@ -219,7 +216,9 @@ def test_avg_query_with_limit(
assert len(result[0]) == 1
r = result[0][0]
assert r.alias == "avg_limited"
expected = sum(c["appearances"] for c in populate_datastore.CHARACTERS[:limit]) / limit
expected = (
sum(c["appearances"] for c in populate_datastore.CHARACTERS[:limit]) / limit
)
assert r.value == expected


Expand All @@ -240,8 +239,12 @@ def test_aggregation_query_multiple_aggregations(
result_dict = {r.alias: r for r in result[0]}
assert result_dict["total"].value == len(populate_datastore.CHARACTERS)
assert result_dict["all"].value == len(populate_datastore.CHARACTERS)
assert result_dict["sum_appearances"].value == sum(c["appearances"] for c in populate_datastore.CHARACTERS)
assert result_dict["avg_appearances"].value == sum(c["appearances"] for c in populate_datastore.CHARACTERS) / len(populate_datastore.CHARACTERS)
assert result_dict["sum_appearances"].value == sum(
c["appearances"] for c in populate_datastore.CHARACTERS
)
assert result_dict["avg_appearances"].value == sum(
c["appearances"] for c in populate_datastore.CHARACTERS
) / len(populate_datastore.CHARACTERS)


@pytest.mark.parametrize("database_id", [None, _helpers.TEST_DATABASE], indirect=True)
Expand Down Expand Up @@ -269,8 +272,12 @@ def test_aggregation_query_add_aggregation(
assert len(result[0]) == 3
result_dict = {r.alias: r for r in result[0]}
assert result_dict["total"].value == len(populate_datastore.CHARACTERS)
assert result_dict["sum_appearances"].value == sum(c["appearances"] for c in populate_datastore.CHARACTERS)
assert result_dict["avg_appearances"].value == sum(c["appearances"] for c in populate_datastore.CHARACTERS) / len(populate_datastore.CHARACTERS)
assert result_dict["sum_appearances"].value == sum(
c["appearances"] for c in populate_datastore.CHARACTERS
)
assert result_dict["avg_appearances"].value == sum(
c["appearances"] for c in populate_datastore.CHARACTERS
) / len(populate_datastore.CHARACTERS)


@pytest.mark.parametrize("database_id", [None, _helpers.TEST_DATABASE], indirect=True)
Expand Down Expand Up @@ -299,8 +306,12 @@ def test_aggregation_query_add_aggregations(
result_dict = {r.alias: r for r in result[0]}
assert result_dict["total"].value == len(populate_datastore.CHARACTERS)
assert result_dict["all"].value == len(populate_datastore.CHARACTERS)
assert result_dict["sum_appearances"].value == sum(c["appearances"] for c in populate_datastore.CHARACTERS)
assert result_dict["avg_appearances"].value == sum(c["appearances"] for c in populate_datastore.CHARACTERS) / len(populate_datastore.CHARACTERS)
assert result_dict["sum_appearances"].value == sum(
c["appearances"] for c in populate_datastore.CHARACTERS
)
assert result_dict["avg_appearances"].value == sum(
c["appearances"] for c in populate_datastore.CHARACTERS
) / len(populate_datastore.CHARACTERS)


@pytest.mark.parametrize("database_id", [None, _helpers.TEST_DATABASE], indirect=True)
Expand Down Expand Up @@ -355,7 +366,11 @@ def test_aggregation_query_with_nested_query_filtered(
assert len(result[0]) == 3
result_dict = {r.alias: r for r in result[0]}
assert result_dict["total"].value == expected_matches
expected_sum = sum(c["appearances"] for c in populate_datastore.CHARACTERS if c["appearances"] >= 20)
expected_sum = sum(
c["appearances"]
for c in populate_datastore.CHARACTERS
if c["appearances"] >= 20
)
assert result_dict["sum_appearances"].value == expected_sum
assert result_dict["avg_appearances"].value == expected_sum / expected_matches

Expand Down Expand Up @@ -384,6 +399,10 @@ def test_aggregation_query_with_nested_query_multiple_filters(
assert len(result[0]) == 3
result_dict = {r.alias: r for r in result[0]}
assert result_dict["total"].value == expected_matches
expected_sum = sum(c["appearances"] for c in populate_datastore.CHARACTERS if c["appearances"] >= 26 and "Stark" in c["family"])
expected_sum = sum(
c["appearances"]
for c in populate_datastore.CHARACTERS
if c["appearances"] >= 26 and "Stark" in c["family"]
)
assert result_dict["sum_appearances"].value == expected_sum
assert result_dict["avg_appearances"].value == expected_sum / expected_matches

0 comments on commit bd52f4b

Please sign in to comment.