Skip to content

Commit c6197d0

Browse files
authored
Merge pull request #60 from buildkite/rename-runtime-environment-to-run-env
Rename `RuntimeEnvironment` to `RunEnv`
2 parents 6de4da5 + 56f2b4e commit c6197d0

4 files changed

Lines changed: 56 additions & 56 deletions

File tree

src/buildkite_test_collector/collector/payload.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ..pytest_plugin.logger import logger
99

1010
from .instant import Instant
11-
from .run_env import RuntimeEnvironment
11+
from .run_env import RunEnv
1212

1313
JsonValue = Union[str, int, float, bool, 'JsonDict', Tuple['JsonValue']]
1414
JsonDict = Dict[str, JsonValue]
@@ -209,14 +209,14 @@ def as_json(self, started_at: Instant) -> JsonDict:
209209
@dataclass(frozen=True)
210210
class Payload:
211211
"""The full test analytics payload"""
212-
run_env: RuntimeEnvironment
212+
run_env: RunEnv
213213
data: Tuple[TestData]
214214
started_at: Optional[Instant]
215215
finished_at: Optional[Instant]
216216

217217
@classmethod
218-
def init(cls, run_env: RuntimeEnvironment) -> 'Payload':
219-
"""Create a new instance of payload with the provided runtime environment"""
218+
def init(cls, run_env: RunEnv) -> 'Payload':
219+
"""Create a new instance of payload with the provided RunEnv"""
220220

221221
return cls(
222222
run_env=run_env,

src/buildkite_test_collector/collector/run_env.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Runtime environment detection"""
1+
"""Test Engine run_env"""
22

33
from dataclasses import dataclass
44
from typing import Dict, Optional
@@ -17,13 +17,13 @@ def __get_env(name: str) -> Optional[str]:
1717
return var
1818

1919

20-
def __buildkite_env() -> Optional['RuntimeEnvironment']:
20+
def __buildkite_env() -> Optional['RunEnv']:
2121
build_id = __get_env("BUILDKITE_BUILD_ID")
2222

2323
if build_id is None:
2424
return None
2525

26-
return RuntimeEnvironment(
26+
return RunEnv(
2727
ci="buildkite",
2828
key=build_id,
2929
url=__get_env("BUILDKITE_BUILD_URL"),
@@ -35,7 +35,7 @@ def __buildkite_env() -> Optional['RuntimeEnvironment']:
3535
)
3636

3737

38-
def __github_actions_env() -> Optional['RuntimeEnvironment']:
38+
def __github_actions_env() -> Optional['RunEnv']:
3939
action = __get_env("GITHUB_ACTION")
4040
run_number = __get_env("GITHUB_RUN_NUMBER")
4141
run_attempt = __get_env("GITHUB_RUN_ATTEMPT")
@@ -46,7 +46,7 @@ def __github_actions_env() -> Optional['RuntimeEnvironment']:
4646
repo = __get_env("GITHUB_REPOSITORY")
4747
run_id = __get_env("GITHUB_RUN_ID")
4848

49-
return RuntimeEnvironment(
49+
return RunEnv(
5050
ci="github_actions",
5151
key=f"{action}-{run_number}-{run_attempt}",
5252
url=f"https://github.com/{repo}/actions/runs/{run_id}",
@@ -58,14 +58,14 @@ def __github_actions_env() -> Optional['RuntimeEnvironment']:
5858
)
5959

6060

61-
def __circle_ci_env() -> Optional['RuntimeEnvironment']:
61+
def __circle_ci_env() -> Optional['RunEnv']:
6262
build_num = __get_env("CIRCLE_BUILD_NUM")
6363
workflow_id = __get_env("CIRCLE_WORKFLOW_ID")
6464

6565
if (build_num is None or workflow_id is None):
6666
return None
6767

68-
return RuntimeEnvironment(
68+
return RunEnv(
6969
ci="circleci",
7070
key=f"{workflow_id}-{build_num}",
7171
url=__get_env("CIRCLE_BUILD_URL"),
@@ -77,8 +77,8 @@ def __circle_ci_env() -> Optional['RuntimeEnvironment']:
7777
)
7878

7979

80-
def __generic_env() -> 'RuntimeEnvironment':
81-
return RuntimeEnvironment(
80+
def __generic_env() -> 'RunEnv':
81+
return RunEnv(
8282
ci="generic",
8383
key=str(uuid4()),
8484
url=None,
@@ -91,8 +91,8 @@ def __generic_env() -> 'RuntimeEnvironment':
9191

9292

9393
@dataclass(frozen=True)
94-
class RuntimeEnvironment:
95-
"""The detected RuntimeEnvironment"""
94+
class RunEnv:
95+
"""The detected RunEnv"""
9696
ci: str
9797
key: str
9898
number: Optional[str]
@@ -120,7 +120,7 @@ def as_json(self) -> Dict[str, str]:
120120
return {k: v for k, v in attrs.items() if v is not None}
121121

122122

123-
def detect_env() -> RuntimeEnvironment:
123+
def detect_env() -> RunEnv:
124124
"""Attempt to detect the CI system we're running in"""
125125
return __buildkite_env() or \
126126
__github_actions_env() or \

tests/buildkite_test_collector/collector/test_run_env.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ def test_detect_env_with_buildkite_api_env_vars_returns_the_correct_environment(
2323
"BUILDKITE_MESSAGE": "All we are is dust in the wind, dude.",
2424
}
2525
with mock.patch.dict(os.environ, env, clear=True):
26-
runtime_env = detect_env()
26+
run_env = detect_env()
2727

28-
assert runtime_env.ci == "buildkite"
29-
assert runtime_env.key == id
30-
assert runtime_env.url == "https://example.test/buildkite"
31-
assert runtime_env.branch == "rufus"
32-
assert runtime_env.commit_sha == commit
33-
assert runtime_env.number == number
34-
assert runtime_env.job_id == job_id
35-
assert runtime_env.message == "All we are is dust in the wind, dude."
28+
assert run_env.ci == "buildkite"
29+
assert run_env.key == id
30+
assert run_env.url == "https://example.test/buildkite"
31+
assert run_env.branch == "rufus"
32+
assert run_env.commit_sha == commit
33+
assert run_env.number == number
34+
assert run_env.job_id == job_id
35+
assert run_env.message == "All we are is dust in the wind, dude."
3636

3737

3838
def test_detect_env_with_github_actions_env_vars_returns_the_correct_environment():
@@ -53,16 +53,16 @@ def test_detect_env_with_github_actions_env_vars_returns_the_correct_environment
5353
}
5454

5555
with mock.patch.dict(os.environ, env, clear=True):
56-
runtime_env = detect_env()
56+
run_env = detect_env()
5757

58-
assert runtime_env.ci == "github_actions"
59-
assert runtime_env.key == f"bring-about-world-peace-{run_number}-{run_attempt}"
60-
assert runtime_env.url == f"https://github.com/bill-and-ted/phone-booth/actions/runs/{run_id}"
61-
assert runtime_env.branch == "rufus"
62-
assert runtime_env.commit_sha == commit
63-
assert runtime_env.number == run_number
64-
assert runtime_env.job_id is None
65-
assert runtime_env.message == "excellent adventure"
58+
assert run_env.ci == "github_actions"
59+
assert run_env.key == f"bring-about-world-peace-{run_number}-{run_attempt}"
60+
assert run_env.url == f"https://github.com/bill-and-ted/phone-booth/actions/runs/{run_id}"
61+
assert run_env.branch == "rufus"
62+
assert run_env.commit_sha == commit
63+
assert run_env.number == run_number
64+
assert run_env.job_id is None
65+
assert run_env.message == "excellent adventure"
6666

6767
def test_detect_env_with_circle_ci_env_vars_returns_the_correct_environment():
6868
build_num = str(randint(0, 1000))
@@ -79,31 +79,31 @@ def test_detect_env_with_circle_ci_env_vars_returns_the_correct_environment():
7979
}
8080

8181
with mock.patch.dict(os.environ, env, clear=True):
82-
runtime_env = detect_env()
82+
run_env = detect_env()
8383

84-
assert runtime_env.ci == "circleci"
85-
assert runtime_env.key == f"{workflow_id}-{build_num}"
86-
assert runtime_env.url == "https://example.test/circle"
87-
assert runtime_env.branch == "rufus"
88-
assert runtime_env.commit_sha == commit
89-
assert runtime_env.number == build_num
90-
assert runtime_env.job_id is None
91-
assert runtime_env.message == "excellent adventure"
84+
assert run_env.ci == "circleci"
85+
assert run_env.key == f"{workflow_id}-{build_num}"
86+
assert run_env.url == "https://example.test/circle"
87+
assert run_env.branch == "rufus"
88+
assert run_env.commit_sha == commit
89+
assert run_env.number == build_num
90+
assert run_env.job_id is None
91+
assert run_env.message == "excellent adventure"
9292

9393
def test_detect_env_with_generic_env_vars():
9494
env = {}
9595

9696
with mock.patch.dict(os.environ, env, clear=True):
97-
runtime_env = detect_env()
98-
99-
assert runtime_env.ci == "generic"
100-
assert UUID(runtime_env.key)
101-
assert runtime_env.url is None
102-
assert runtime_env.branch is None
103-
assert runtime_env.commit_sha is None
104-
assert runtime_env.number is None
105-
assert runtime_env.job_id is None
106-
assert runtime_env.message is None
97+
run_env = detect_env()
98+
99+
assert run_env.ci == "generic"
100+
assert UUID(run_env.key)
101+
assert run_env.url is None
102+
assert run_env.branch is None
103+
assert run_env.commit_sha is None
104+
assert run_env.number is None
105+
assert run_env.job_id is None
106+
assert run_env.message is None
107107

108108
def test_env_as_json(fake_env):
109109
json = fake_env.as_json()

tests/buildkite_test_collector/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pytest
88

99
from buildkite_test_collector.collector.payload import TestData, TestResultPassed, TestHistory, Payload, TestResultFailed, TestResultSkipped
10-
from buildkite_test_collector.collector.run_env import RuntimeEnvironment
10+
from buildkite_test_collector.collector.run_env import RunEnv
1111
from buildkite_test_collector.collector.instant import Instant
1212

1313

@@ -72,8 +72,8 @@ def history_finished() -> TestHistory:
7272

7373

7474
@pytest.fixture
75-
def fake_env() -> RuntimeEnvironment:
76-
return RuntimeEnvironment(
75+
def fake_env() -> RunEnv:
76+
return RunEnv(
7777
ci="example",
7878
key=str(uuid4()),
7979
number=str(randint(0, 1000)),

0 commit comments

Comments
 (0)