-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create base parser classes: Testcase and Testsuite
- Loading branch information
1 parent
8fcd4db
commit afd2124
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
] | ||
) | ||
+ ";" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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::];" | ||
) |