57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
"""
|
|
Test script para verificar la función is_block_exportable
|
|
"""
|
|
|
|
|
|
# Mock class para simular un bloque de TIA Portal
|
|
class MockBlock:
|
|
def __init__(self, programming_language):
|
|
self.programming_language = programming_language
|
|
|
|
def get_property(self, name):
|
|
if name == "ProgrammingLanguage":
|
|
return self.programming_language
|
|
raise Exception(f"Property {name} not found")
|
|
|
|
|
|
# Importar la función desde x1.py
|
|
import sys
|
|
import os
|
|
|
|
sys.path.append(os.path.dirname(__file__))
|
|
from x1 import is_block_exportable
|
|
|
|
# Testear diferentes tipos de bloques
|
|
test_cases = [
|
|
("LAD", True, "LAD blocks should be exportable"),
|
|
("FBD", True, "FBD blocks should be exportable"),
|
|
("STL", True, "STL blocks should be exportable"),
|
|
("SCL", True, "SCL blocks should be exportable"),
|
|
("ProDiag_OB", False, "ProDiag_OB blocks should not be exportable"),
|
|
("ProDiag", False, "ProDiag blocks should not be exportable"),
|
|
("GRAPH", False, "GRAPH blocks should not be exportable"),
|
|
]
|
|
|
|
print("=== Test de validación de bloques ===")
|
|
for prog_lang, expected_exportable, description in test_cases:
|
|
block = MockBlock(prog_lang)
|
|
is_exportable, detected_lang, reason = is_block_exportable(block)
|
|
|
|
status = "✓ PASS" if is_exportable == expected_exportable else "✗ FAIL"
|
|
print(f"{status} - {description}")
|
|
print(f" Lenguaje: {detected_lang}, Exportable: {is_exportable}, Razón: {reason}")
|
|
print()
|
|
|
|
|
|
# Test con bloque que genera excepción
|
|
class MockBlockError:
|
|
def get_property(self, name):
|
|
raise Exception("Cannot access property")
|
|
|
|
|
|
print("=== Test de manejo de errores ===")
|
|
error_block = MockBlockError()
|
|
is_exportable, detected_lang, reason = is_block_exportable(error_block)
|
|
print(f"Bloque con error - Exportable: {is_exportable}, Lenguaje: {detected_lang}")
|
|
print(f"Razón: {reason}")
|