Skip to content

Commit fd1df03

Browse files
committed
tests: custom_tools: added
Simple testing of the custom tool integration. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 65b8524 commit fd1df03

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3
2+
3+
"""Example out-of-tree tool"""
4+
5+
__author__ = "Jordan Yates"
6+
__copyright__ = "Copyright 2025, Embeint Inc"
7+
8+
from infuse_iot.commands import InfuseCommand
9+
10+
11+
class SubCommand(InfuseCommand):
12+
NAME = "custom_tool"
13+
HELP = "Test out-of-tree tool"
14+
DESCRIPTION = "Test out-of-tree tool"
15+
16+
@classmethod
17+
def add_parser(cls, parser):
18+
parser.add_argument("--echo", "-e", required=True, type=str)
19+
20+
def __init__(self, args):
21+
self.echo_string = args.echo
22+
23+
def run(self):
24+
print("Echoing provided string:")
25+
print(self.echo_string)

tests/test_custom_tools.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import pathlib
5+
import subprocess
6+
7+
import pytest
8+
9+
import infuse_iot.credentials as cred
10+
11+
assert "TOXTEMPDIR" in os.environ, "you must run these tests using tox"
12+
13+
14+
def test_custom_tool_integration():
15+
# Validate custom tool integration
16+
echo_string = "test_string"
17+
18+
try:
19+
cred.delete_custom_tool_path()
20+
except Exception as _:
21+
pass
22+
23+
with pytest.raises(subprocess.CalledProcessError):
24+
subprocess.check_output(["infuse", "custom_tool", "--echo", echo_string])
25+
26+
custom_tools_path = pathlib.Path(__file__).parent.parent / 'scripts' / 'custom_tools'
27+
28+
subprocess.check_output(["infuse", "credentials", "--custom-tools", str(custom_tools_path)])
29+
30+
output = subprocess.check_output(["infuse", "custom_tool", "--echo", echo_string]).decode()
31+
assert echo_string in output
32+
33+
cred.delete_custom_tool_path()
34+
35+
with pytest.raises(subprocess.CalledProcessError):
36+
subprocess.check_output(["infuse", "custom_tool", "--echo", echo_string])

0 commit comments

Comments
 (0)