Skip to content

Commit

Permalink
Create base parser classes: Testcase and Testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-sentry committed Oct 23, 2023
1 parent 8fcd4db commit afd2124
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
55 changes: 55 additions & 0 deletions codecov_cli/parsers/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from datetime import datetime, timedelta
from typing import List


class ParsingError(Exception):
...


class Testcase(object):
def __init__(self, name: str, status: bool, duration: timedelta):
self.name = name
self.status = status
self.duration = duration

def __repr__(self):
return f"{self.name}:{self.status}:{self.duration.total_seconds()}::"


class Testsuite(object):
def __init__(
self,
name: str,
timestamp: datetime,
time: timedelta,
testcases: List[Testcase],
failures: int,
errors: int,
skipped: int,
total: int,
):
self.testcases = testcases or []
self.name = name
self.time = time
self.timestamp = timestamp
self.failures = failures
self.errors = errors
self.skipped = skipped
self.total = total

def to_str(self):
return (
";".join(
[
self.name,
str(self.timestamp.timestamp()),
str(self.time.total_seconds()),
str(self.failures),
str(self.errors),
str(self.skipped),
str(self.total),
str(self.testcases),
]
)
+ ";"
)
22 changes: 22 additions & 0 deletions tests/parsers/test_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from datetime import datetime, timedelta

from codecov_cli.parsers.base import Testcase, Testsuite


def test_testsuite():
now = datetime.now()
ts = Testsuite(
"test_name",
now,
timedelta(seconds=1),
[Testcase("testcase_name", True, timedelta(seconds=1))],
errors=0,
failures=0,
skipped=0,
total=1,
)

assert (
ts.to_str()
== f"test_name;{now.timestamp()};1.0;0;0;0;1;[testcase_name:True:1.0::];"
)

0 comments on commit afd2124

Please sign in to comment.