Skip to content

Commit

Permalink
fix: address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-sentry committed Jan 8, 2025
1 parent 0b8e968 commit 0efb81c
Show file tree
Hide file tree
Showing 13 changed files with 226 additions and 188 deletions.
Empty file removed generated_proto/sample/__init__.py
Empty file.
33 changes: 0 additions & 33 deletions generated_proto/sample/sample_pb2.py

This file was deleted.

8 changes: 4 additions & 4 deletions generated_proto/testrun/ta_testrun_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions generated_proto/testrun/ta_testrun_pb2.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from typing import ClassVar as _ClassVar
from typing import Iterable as _Iterable
from typing import Optional as _Optional
from typing import Union as _Union

from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf.internal import containers as _containers
from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper

DESCRIPTOR: _descriptor.FileDescriptor

class TestRun(_message.Message):
__slots__ = (
"timestamp",
"name",
"classname",
"testsuite",
"computed_name",
"outcome",
"failure_message",
"duration_seconds",
"repoid",
"commit_sha",
"branch_name",
"flags",
"filename",
"framework",
)
class Outcome(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
__slots__ = ()
PASSED: _ClassVar[TestRun.Outcome]
FAILED: _ClassVar[TestRun.Outcome]
SKIPPED: _ClassVar[TestRun.Outcome]

PASSED: TestRun.Outcome
FAILED: TestRun.Outcome
SKIPPED: TestRun.Outcome
TIMESTAMP_FIELD_NUMBER: _ClassVar[int]
NAME_FIELD_NUMBER: _ClassVar[int]
CLASSNAME_FIELD_NUMBER: _ClassVar[int]
TESTSUITE_FIELD_NUMBER: _ClassVar[int]
COMPUTED_NAME_FIELD_NUMBER: _ClassVar[int]
OUTCOME_FIELD_NUMBER: _ClassVar[int]
FAILURE_MESSAGE_FIELD_NUMBER: _ClassVar[int]
DURATION_SECONDS_FIELD_NUMBER: _ClassVar[int]
REPOID_FIELD_NUMBER: _ClassVar[int]
COMMIT_SHA_FIELD_NUMBER: _ClassVar[int]
BRANCH_NAME_FIELD_NUMBER: _ClassVar[int]
FLAGS_FIELD_NUMBER: _ClassVar[int]
FILENAME_FIELD_NUMBER: _ClassVar[int]
FRAMEWORK_FIELD_NUMBER: _ClassVar[int]
timestamp: int
name: str
classname: str
testsuite: str
computed_name: str
outcome: TestRun.Outcome
failure_message: str
duration_seconds: float
repoid: int
commit_sha: str
branch_name: str
flags: _containers.RepeatedScalarFieldContainer[str]
filename: str
framework: str
def __init__(
self,
timestamp: _Optional[int] = ...,
name: _Optional[str] = ...,
classname: _Optional[str] = ...,
testsuite: _Optional[str] = ...,
computed_name: _Optional[str] = ...,
outcome: _Optional[_Union[TestRun.Outcome, str]] = ...,
failure_message: _Optional[str] = ...,
duration_seconds: _Optional[float] = ...,
repoid: _Optional[int] = ...,
commit_sha: _Optional[str] = ...,
branch_name: _Optional[str] = ...,
flags: _Optional[_Iterable[str]] = ...,
filename: _Optional[str] = ...,
framework: _Optional[str] = ...,
) -> None: ...
8 changes: 0 additions & 8 deletions protobuf/sample.proto

This file was deleted.

6 changes: 3 additions & 3 deletions protobuf/ta_testrun.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto2";

message TestRun {
optional string timestamp = 1;
optional int64 timestamp = 1;
optional string name = 2;
optional string classname = 3;
optional string testsuite = 4;
Expand All @@ -16,12 +16,12 @@ message TestRun {
optional Outcome outcome = 6;

optional string failure_message = 7;
optional float duration = 8;
optional float duration_seconds = 8;

optional int64 repoid = 10;
optional string commit_sha = 11;

optional string branch = 12;
optional string branch_name = 12;

repeated string flags = 13;

Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pre-commit
polars==1.12.0
proto-plus>=1.25.0
psycopg2>=2.9.10
protobuf>=5.29.2`
protobuf>=5.29.2
pydantic>=2.9.0
PyJWT>=2.4.0
pytest
Expand Down
54 changes: 36 additions & 18 deletions services/tests/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import polars as pl
import pytest

import generated_proto.sample.sample_pb2 as sample_pb2
import generated_proto.testrun.ta_testrun_pb2 as ta_testrun_pb2
from services.bigquery import BigQueryService

fake_private_key = """-----BEGIN RSA PRIVATE KEY-----
Expand Down Expand Up @@ -55,12 +55,12 @@ def test_bigquery_service():
results = bigquery_service.query(sql)

Check warning on line 55 in services/tests/test_bigquery.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/tests/test_bigquery.py#L55

Added line #L55 was not covered by tests

assert len(results) == 2
assert set([row["timestamp"] for row in results]) == {
assert {row["timestamp"] for row in results} == {

Check warning on line 58 in services/tests/test_bigquery.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/tests/test_bigquery.py#L57-L58

Added lines #L57 - L58 were not covered by tests
datetime.fromisoformat("2025-01-01T00:00:00Z"),
datetime.fromisoformat("2024-12-30T00:00:00Z"),
}
assert set([row["name"] for row in results]) == {"name", "name2"}
assert set([row["id"] for row in results]) == {1, 2}
assert {row["name"] for row in results} == {"name", "name2"}
assert {row["id"] for row in results} == {1, 2}

Check warning on line 63 in services/tests/test_bigquery.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/tests/test_bigquery.py#L62-L63

Added lines #L62 - L63 were not covered by tests


@pytest.mark.skip(reason="This test requires being run using actual working creds")
Expand All @@ -78,53 +78,71 @@ def test_bigquery_service_polars():
)

assert len(results) == 2
assert set(results["timestamp"].to_list()) == {
assert {x for x in results["timestamp"].to_list()} == {

Check warning on line 81 in services/tests/test_bigquery.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/tests/test_bigquery.py#L80-L81

Added lines #L80 - L81 were not covered by tests
datetime.fromisoformat("2025-01-01T00:00:00Z"),
datetime.fromisoformat("2024-12-30T00:00:00Z"),
}
assert set(results["name"].to_list()) == {"name", "name2"}
assert set(results["id"].to_list()) == {1, 2}
assert {x for x in results["name"].to_list()} == {"name", "name2"}
assert {x for x in results["id"].to_list()} == {1, 2}

Check warning on line 86 in services/tests/test_bigquery.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/tests/test_bigquery.py#L85-L86

Added lines #L85 - L86 were not covered by tests


# this test should only be run manually when making changes to the way we write to bigquery
# the reason it's not automated is because vcrpy does not seem to work with the gRPC requests
@pytest.mark.skip(reason="This test requires being run using actual working creds")
def test_bigquery_service_write():
table_name = "codecov-dev.test_dataset.sample_table"
table_name = "codecov-dev.test_dataset.testruns"
bigquery_service = BigQueryService(gcp_config)

Check warning on line 94 in services/tests/test_bigquery.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/tests/test_bigquery.py#L93-L94

Added lines #L93 - L94 were not covered by tests

bigquery_service.query(f"TRUNCATE TABLE `{table_name}`")

Check warning on line 96 in services/tests/test_bigquery.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/tests/test_bigquery.py#L96

Added line #L96 was not covered by tests

data = [

Check warning on line 98 in services/tests/test_bigquery.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/tests/test_bigquery.py#L98

Added line #L98 was not covered by tests
sample_pb2.Sample(
timestamp="2025-01-01T00:00:00Z",
id="1",
ta_testrun_pb2.TestRun(
timestamp=int(
datetime.fromisoformat("2025-01-01T00:00:00.000000Z").timestamp()
* 1000000
),
name="name",
classname="classname",
testsuite="testsuite",
computed_name="computed_name",
outcome=ta_testrun_pb2.TestRun.Outcome.PASSED,
failure_message="failure_message",
duration_seconds=1.0,
filename="filename",
),
sample_pb2.Sample(
timestamp="2024-12-30T00:00:00Z",
id="2",
ta_testrun_pb2.TestRun(
timestamp=int(
datetime.fromisoformat("2024-12-30T00:00:00.000000Z").timestamp()
* 1000000
),
name="name2",
classname="classname2",
testsuite="testsuite2",
computed_name="computed_name2",
outcome=ta_testrun_pb2.TestRun.Outcome.FAILED,
failure_message="failure_message2",
duration_seconds=2.0,
filename="filename2",
),
]

serialized_data = [row.SerializeToString() for row in data]

Check warning on line 129 in services/tests/test_bigquery.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/tests/test_bigquery.py#L129

Added line #L129 was not covered by tests

bigquery_service.write(

Check warning on line 131 in services/tests/test_bigquery.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/tests/test_bigquery.py#L131

Added line #L131 was not covered by tests
"test_dataset",
"test_table",
sample_pb2,
"testruns",
ta_testrun_pb2,
serialized_data,
)

results = bigquery_service.query(f"SELECT * FROM `{table_name}`")

Check warning on line 138 in services/tests/test_bigquery.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/tests/test_bigquery.py#L138

Added line #L138 was not covered by tests

assert len(results) == 2

Check warning on line 140 in services/tests/test_bigquery.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/tests/test_bigquery.py#L140

Added line #L140 was not covered by tests

assert set([row["timestamp"] for row in results]) == set(
assert {row["timestamp"] for row in results} == set(

Check warning on line 142 in services/tests/test_bigquery.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/tests/test_bigquery.py#L142

Added line #L142 was not covered by tests
[
datetime.fromisoformat("2025-01-01T00:00:00Z"),
datetime.fromisoformat("2024-12-30T00:00:00Z"),
]
)
assert set([row["name"] for row in results]) == set(["name", "name2"])
assert {row["name"] for row in results} == set(["name", "name2"])

Check warning on line 148 in services/tests/test_bigquery.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/tests/test_bigquery.py#L148

Added line #L148 was not covered by tests
10 changes: 6 additions & 4 deletions ta_storage/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from abc import ABC, abstractmethod
from typing import Any

from test_results_parser import Testrun

from database.models.reports import Upload

Expand All @@ -8,11 +9,12 @@ class TADriver(ABC):
@abstractmethod
def write_testruns(
self,
timestamp: int,
repo_id: int,
commit_id: str,
branch: str,
commit_sha: str,
branch_name: str,
upload: Upload,
framework: str | None,
testruns: list[dict[str, Any]],
testruns: list[Testrun],
):
pass

Check warning on line 20 in ta_storage/base.py

View check run for this annotation

Codecov Notifications / codecov/patch

ta_storage/base.py#L20

Added line #L20 was not covered by tests
Loading

0 comments on commit 0efb81c

Please sign in to comment.