TasmotaManager/test_hostname_matching.py

62 lines
1.7 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Test script for hostname matching in TasmotaManager.py
This script tests the hostname matching functionality with various patterns:
1. Exact match
2. Partial match
3. Wildcard match
4. Multiple matches
"""
import subprocess
import sys
import os
def run_test(test_name, hostname_pattern):
"""Run a test with the given hostname pattern"""
print(f"\n{'='*80}")
print(f"TEST: {test_name}")
print(f"Pattern: {hostname_pattern}")
print(f"{'='*80}")
# Run the TasmotaManager.py script with the --Device parameter and --debug flag
cmd = ["python3", "TasmotaManager.py", "--Device", hostname_pattern, "--debug"]
print(f"Running command: {' '.join(cmd)}")
# Run the command and capture output
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
stdout, stderr = process.communicate()
# Print the output
print("\nSTDOUT:")
print(stdout)
if stderr:
print("\nSTDERR:")
print(stderr)
print(f"\nExit code: {process.returncode}")
return process.returncode
def main():
"""Run all tests"""
# Test 1: Exact match
run_test("Exact Match", "MasterLamp-5891")
# Test 2: Partial match
run_test("Partial Match", "Master")
# Test 3: Wildcard match
run_test("Wildcard Match", "Master*")
# Test 4: Wildcard match with * on both sides
run_test("Wildcard Match (both sides)", "*Lamp*")
# Test 5: Multiple matches (should match multiple devices and use the first one)
run_test("Multiple Matches", "M")
print("\nAll tests completed!")
if __name__ == "__main__":
main()