Skip to content

Commit 89b6960

Browse files
committed
finish updating interface of ServiceSpecificMessages
1 parent 11d422b commit 89b6960

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

pants-plugins/uses_services/exceptions.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
from __future__ import annotations
15+
1416
from dataclasses import dataclass
17+
from textwrap import dedent
1518

1619
from uses_services.platform_rules import Platform
1720

@@ -35,7 +38,9 @@ class ServiceSpecificMessages:
3538
class ServiceMissingError(Exception):
3639
"""Error raised when a test uses a service but that service is missing."""
3740

38-
def __init__(self, service, platform: Platform, instructions="", msg=None):
41+
def __init__(
42+
self, service: str, platform: Platform, instructions: str = "", msg=None
43+
):
3944
if msg is None:
4045
msg = f"The {service} service does not seem to be running or is not accessible!"
4146
if instructions:
@@ -46,9 +51,9 @@ def __init__(self, service, platform: Platform, instructions="", msg=None):
4651
self.instructions = instructions
4752

4853
@classmethod
49-
def generate_instructions(
54+
def generate(
5055
cls, platform: Platform, messages: ServiceSpecificMessages
51-
):
56+
) -> ServiceMissingError:
5257
service = messages.service
5358

5459
supported = False
@@ -154,4 +159,9 @@ def generate_instructions(
154159
and start {service}. Good luck!
155160
"""
156161
)
157-
return instructions
162+
163+
return cls(
164+
service=service,
165+
platform=platform,
166+
instructions=instructions,
167+
)

pants-plugins/uses_services/mongo_rules.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ async def mongo_is_running(
159159
return MongoIsRunning()
160160

161161
# mongo is not running, so raise an error with instructions.
162-
raise ServiceMissingError(
163-
platform,
164-
ServiceSpecificMessages(
162+
raise ServiceMissingError.generate(
163+
platform=platform,
164+
messages=ServiceSpecificMessages(
165165
service="mongo",
166166
service_start_cmd_el_7="service mongo start",
167167
service_start_cmd_el="systemctl start mongod",

0 commit comments

Comments
 (0)