Skip to content

Commit 50dfcd8

Browse files
committed
add test for uses_services get_platform rule
1 parent 5f4067a commit 50dfcd8

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

pants-plugins/uses_services/BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
python_sources()
2+
3+
python_tests(
4+
name="tests",
5+
)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2023 The StackStorm Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from __future__ import annotations
15+
16+
import dataclasses
17+
18+
import pytest
19+
20+
from pants.testutil.rule_runner import QueryRule, RuleRunner
21+
22+
from .platform_rules import Platform, rules as platform_rules
23+
24+
25+
@pytest.fixture
26+
def rule_runner() -> RuleRunner:
27+
return RuleRunner(
28+
rules=[
29+
*platform_rules(),
30+
QueryRule(Platform, ()),
31+
],
32+
target_types=[],
33+
)
34+
35+
36+
def test_get_platform(rule_runner: RuleRunner) -> None:
37+
rule_runner.set_options(
38+
["--backend-packages=uses_services"],
39+
env_inherit={"PATH", "PYENV_ROOT", "HOME"},
40+
)
41+
42+
platform = rule_runner.request(Platform, ())
43+
44+
assert isinstance(platform, Platform)
45+
assert dataclasses.is_dataclass(platform)
46+
# there isn't a good way to inject mocks into the script that
47+
# the rule_runner runs in a venv. So, there isn't a nice way
48+
# to test the values of the Platform fields as people could
49+
# run tests on any platform.

0 commit comments

Comments
 (0)