Skip to content

Commit

Permalink
trunk fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
dfrankland committed Oct 4, 2024
1 parent 06095c3 commit f839892
Showing 1 changed file with 60 additions and 59 deletions.
119 changes: 60 additions & 59 deletions context-py/tests/test_parse_and_validate.py
Original file line number Diff line number Diff line change
@@ -1,80 +1,81 @@
def test_env_parse_and_validate():
from context_py import env_parse, env_validate, CIPlatform, EnvValidationLevel
from context_py import CIPlatform, EnvValidationLevel, env_parse, env_validate

env_vars = {
'GITHUB_ACTIONS': 'true',
'GITHUB_REF': 'abc',
'GITHUB_ACTOR': 'Spikey',
'GITHUB_REPOSITORY': 'analytics-cli',
'GITHUB_RUN_ID': '12345',
}
env_vars = {
"GITHUB_ACTIONS": "true",
"GITHUB_REF": "abc",
"GITHUB_ACTOR": "Spikey",
"GITHUB_REPOSITORY": "analytics-cli",
"GITHUB_RUN_ID": "12345",
}

ci_info = env_parse(env_vars)
env_validation = env_validate(ci_info)
ci_info = env_parse(env_vars)
env_validation = env_validate(ci_info)

assert ci_info.platform == CIPlatform.GitHubActions
assert env_validation.max_level() == EnvValidationLevel.SubOptimal
assert [issue.error_message for issue in env_validation.issues_flat()] == [
"CI info author email too short",
"CI info author name too short",
"CI info commit message too short",
"CI info committer email too short",
"CI info committer name too short",
"CI info title too short",
], "\n" + "\n".join([issue.error_message for issue in env_validation.issues_flat()])

assert ci_info.platform == CIPlatform.GitHubActions
assert env_validation.max_level() == EnvValidationLevel.SubOptimal
assert [
issue.error_message
for issue in env_validation.issues_flat()
] == [
"CI info author email too short",
"CI info author name too short",
"CI info commit message too short",
"CI info committer email too short",
"CI info committer name too short",
"CI info title too short",
], '\n' + '\n'.join([
issue.error_message
for issue in env_validation.issues_flat()
])

def test_junit_parse_and_validate():
import datetime
from context_py import junit_parse, junit_validate, JunitValidationLevel
import datetime

from context_py import JunitValidationLevel, junit_parse, junit_validate

timestamp=datetime.datetime.now().astimezone(datetime.timezone.utc).isoformat()
junit_xml = f"""
timestamp = datetime.datetime.now().astimezone(datetime.timezone.utc).isoformat()
junit_xml = f"""
<testsuites name="my-test-run" tests="1" failures="1" errors="0">
<testsuite name="my-test-suite" tests="1" disabled="0" errors="0" failures="1" timestamp="{timestamp}">
<testcase name="failure-case" file="test.py" classname="MyClass" timestamp="{timestamp}" time="1">
<failure/>
</testcase>
</testsuite>
</testsuites>
""";
"""

report = junit_parse(str.encode(junit_xml))
junit_report_validation = junit_validate(report[0])
report = junit_parse(str.encode(junit_xml))
junit_report_validation = junit_validate(report[0])

assert (
junit_report_validation.max_level() == JunitValidationLevel.Valid
), "\n" + "\n".join(
[
issue.error_message
for test_suite in junit_report_validation.test_suites_owned()
for test_case in test_suite.test_cases_owned()
for issue in test_case.issues_flat()
]
)

assert junit_report_validation.max_level() == JunitValidationLevel.Valid, '\n' + '\n'.join([
issue.error_message
for test_suite in junit_report_validation.test_suites_owned()
for test_case in test_suite.test_cases_owned()
for issue in test_case.issues_flat()
])

def test_repo_validate():
import math
import time
from context_py import repo_validate, BundleRepo, RepoUrlParts, RepoValidationLevel
import math
import time

from context_py import BundleRepo, RepoUrlParts, RepoValidationLevel, repo_validate

repo = RepoUrlParts("github", "trunk-io", "analytics-cli")
bundle_repo = BundleRepo(
repo,
".",
"https://github.com/trunk-io/analytics-cli",
"abc",
"main",
math.floor(time.time()),
"commit",
"Spikey",
"spikey@trunk.io",
)
repo = RepoUrlParts("github", "trunk-io", "analytics-cli")
bundle_repo = BundleRepo(
repo,
".",
"https://github.com/trunk-io/analytics-cli",
"abc",
"main",
math.floor(time.time()),
"commit",
"Spikey",
"spikey@trunk.io",
)

repo_validation = repo_validate(bundle_repo)
repo_validation = repo_validate(bundle_repo)

assert repo_validation.max_level() == RepoValidationLevel.Valid, '\n' + '\n'.join([
issue.error_message
for issue in repo_validation.issues_flat()
])
assert repo_validation.max_level() == RepoValidationLevel.Valid, "\n" + "\n".join(
[issue.error_message for issue in repo_validation.issues_flat()]
)

0 comments on commit f839892

Please sign in to comment.