Copiando o repositório do Alexandre

This commit is contained in:
fls committed 2026-09-17 17:37:20 -03:00
1 parent a3e604697b
commit 0ab8836265
363 files changed
+27249

No files matched your search

View File
Whitespace-only changes.
+161
View File
@@ -0,0 +1,161 @@
# -*- coding: utf-8 -*-
"""
Tests for AuthorModel class.
Migrated from unittest to pytest.
"""
import pytest
from datetime import datetime
from mosaicode.model.authormodel import AuthorModel
def test_author_model_initialization():
"""Test AuthorModel initialization."""
authormodel = AuthorModel()
assert authormodel is not None
def test_author_model_default_values():
"""Test AuthorModel default values."""
authormodel = AuthorModel()
# Test default attributes
assert authormodel.name is None
assert authormodel.date is None
assert authormodel.license is None
def test_author_model_set_values():
"""Test setting values in AuthorModel."""
authormodel = AuthorModel()
# Set values
authormodel.name = "Test Author"
authormodel.date = datetime.now()
authormodel.license = "MIT"
# Verify values
assert authormodel.name == "Test Author"
assert authormodel.date is not None
assert authormodel.license == "MIT"
def test_author_model_validation():
"""Test AuthorModel validation."""
authormodel = AuthorModel()
# Test with valid name
authormodel.name = "Valid Author Name"
assert authormodel.name == "Valid Author Name"
# Test with valid license
authormodel.license = "MIT License"
assert authormodel.license == "MIT License"
def test_author_model_serialization():
"""Test AuthorModel serialization."""
authormodel = AuthorModel()
authormodel.name = "Test Author"
authormodel.email = "test@example.com"
authormodel.website = "https://example.com"
authormodel.description = "Test description"
# Test to_dict method if it exists
if hasattr(authormodel, 'to_dict'):
data = authormodel.to_dict()
assert isinstance(data, dict)
assert data.get('name') == "Test Author"
assert data.get('email') == "test@example.com"
def test_author_model_from_dict():
"""Test creating AuthorModel from dictionary."""
data = {
'name': 'Test Author',
'email': 'test@example.com',
'website': 'https://example.com',
'description': 'Test description'
}
# Test from_dict method if it exists
if hasattr(AuthorModel, 'from_dict'):
authormodel = AuthorModel.from_dict(data)
assert authormodel.name == "Test Author"
assert authormodel.email == "test@example.com"
assert authormodel.website == "https://example.com"
assert authormodel.description == "Test description"
def test_author_model_str_representation():
"""Test AuthorModel string representation."""
authormodel = AuthorModel()
authormodel.name = "Test Author"
# Test string representation
str_repr = str(authormodel)
assert isinstance(str_repr, str)
assert "Test Author" in str_repr
def test_author_model_equality():
"""Test AuthorModel equality."""
authormodel1 = AuthorModel()
authormodel1.name = "Test Author"
authormodel1.email = "test@example.com"
authormodel2 = AuthorModel()
authormodel2.name = "Test Author"
authormodel2.email = "test@example.com"
# Test equality
assert authormodel1.name == authormodel2.name
assert authormodel1.email == authormodel2.email
def test_author_model_copy():
"""Test copying AuthorModel."""
authormodel1 = AuthorModel()
authormodel1.name = "Test Author"
authormodel1.email = "test@example.com"
# Test copy if method exists
if hasattr(authormodel1, 'copy'):
authormodel2 = authormodel1.copy()
assert authormodel1.name == authormodel2.name
assert authormodel1.email == authormodel2.email
assert authormodel1 is not authormodel2
def test_author_model_empty_values():
"""Test AuthorModel with empty values."""
authormodel = AuthorModel()
# Test setting empty values
authormodel.name = ""
authormodel.email = ""
authormodel.website = ""
authormodel.description = ""
# Verify empty values are accepted
assert authormodel.name == ""
assert authormodel.email == ""
assert authormodel.website == ""
assert authormodel.description == ""
def test_author_model_special_characters():
"""Test AuthorModel with special characters."""
authormodel = AuthorModel()
# Test with special characters
authormodel.name = "João Silva"
authormodel.email = "joão.silva@exemplo.com"
authormodel.website = "https://exemplo.com/página"
authormodel.description = "Descrição com acentos: áéíóú"
# Verify special characters are preserved
assert authormodel.name == "João Silva"
assert authormodel.email == "joão.silva@exemplo.com"
assert authormodel.website == "https://exemplo.com/página"
assert authormodel.description == "Descrição com acentos: áéíóú"
+32
View File
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
"""
Tests for BlockModel class.
Migrated from unittest/TestBase to pytest.
"""
import pytest
from mosaicode.model.blockmodel import BlockModel
from mosaicode.GUI.fieldtypes import *
@pytest.fixture
def block():
return BlockModel()
def test_blockmodel_color(block):
block.color = "#000000000000"
assert block.get_color() == "#000000000000"
block.color = "0"
assert block.get_color() == "0"
def test_blockmodel_colorrgba(block):
block.color = "#200:200:150:20"
assert block.get_color_as_rgba() == "#200:200:150:20"
block.color = "200:200:150:20"
assert block.get_color_as_rgba() == "rgba(200,200,150,20)"
def test_blockmodel_properties(block):
block.properties = [
{"name": "time", "label": "Time", "lower": 0, "upper": 10000, "step": 1, "value": 1},
{"name": "color", "label": "Color", "value": "#F00", "format": "FF00FF", "type": MOSAICODE_COLOR}
]
erro = {"color": "time"}
block.set_properties(erro)
+112
View File
@@ -0,0 +1,112 @@
# -*- coding: utf-8 -*-
"""
Tests for BlockModel (pure logic, no GUI dependencies).
"""
from pathlib import Path
import tempfile
import shutil
import json
import pytest
from mosaicode.model.blockmodel import BlockModel
@pytest.fixture
def temp_dir():
dir_path = Path(tempfile.mkdtemp(prefix="mosaicode_test_"))
yield dir_path
if dir_path.exists():
shutil.rmtree(dir_path)
def test_block_creation():
block = BlockModel()
assert block.id == -1
assert block.x == 0
assert block.y == 0
assert not block.is_collapsed
assert block.label == "A"
assert block.color == "#000000"
assert block.group == "Undefined"
def test_block_with_custom_values():
block = BlockModel(
id=1,
x=100,
y=200,
label="Test Block",
color="#FF0000",
group="Test Group"
)
assert block.id == 1
assert block.x == 100
assert block.y == 200
assert block.label == "Test Block"
assert block.color == "#FF0000"
assert block.group == "Test Group"
def test_block_properties():
block = BlockModel()
assert isinstance(block.properties, list)
assert len(block.properties) == 0
# Test adding properties
block.properties.append({"name": "test", "value": "value"})
assert len(block.properties) == 1
assert block.properties[0]["name"] == "test"
def test_block_ports():
block = BlockModel()
assert isinstance(block.ports, list)
assert len(block.ports) == 0
# Test adding ports
port = {"type": "input", "name": "test_port"}
block.ports.append(port)
assert len(block.ports) == 1
assert block.ports[0]["type"] == "input"
def test_block_codes():
block = BlockModel()
assert isinstance(block.codes, dict)
assert len(block.codes) == 0
# Test adding codes
block.codes["function"] = "print('test')"
assert len(block.codes) == 1
assert block.codes["function"] == "print('test')"
def test_block_validation():
block = BlockModel()
# Basic validation - should not raise exceptions
assert block.id >= -1
assert isinstance(block.label, str)
assert isinstance(block.color, str)
assert isinstance(block.group, str)
def test_block_serialization(temp_dir):
block = BlockModel(
id=1,
label="Test Block",
color="#FF0000",
group="Test Group"
)
# Test basic serialization using dataclass fields
block_dict = {
"id": block.id,
"label": block.label,
"color": block.color,
"group": block.group,
"type": block.type,
"version": block.version
}
assert isinstance(block_dict, dict)
assert block_dict["id"] == 1
assert block_dict["label"] == "Test Block"
assert block_dict["color"] == "#FF0000"
# Test creating new block with same values
new_block = BlockModel(**block_dict)
assert new_block.id == block.id
assert new_block.label == block.label
assert new_block.color == block.color
+48
View File
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
"""
Tests for CodeTemplate class.
Migrated from unittest/TestBase to pytest.
"""
import pytest
from mosaicode.model.codetemplate import CodeTemplate
from mosaicode.model.port import Port
@pytest.fixture
def code_template():
return CodeTemplate()
def test_codetemplate_init():
CodeTemplate()
def test_codetemplate_equals():
code1 = CodeTemplate()
code2 = CodeTemplate()
assert code1.equals(code2) == True
code1.language = "Test"
assert code1.equals(code2) == False
code1 = CodeTemplate()
if code1.__dict__:
first_key = list(code1.__dict__.keys())[0]
code1.__dict__.pop(first_key, None)
assert code2.equals(code1) == False
def test_codetemplate_set_properties():
code = CodeTemplate()
code.properties = [{"name": "test", "label": "test", "value": "test", "type": "test"}]
code.set_properties({"out": "SET"})
code.set_properties({"test": "SET"})
assert code.properties[0]["value"] == "SET"
def test_codetemplate_get_properties():
code = CodeTemplate()
properties = code.get_properties()
assert isinstance(properties, list)
def test_codetemplate_str():
code = CodeTemplate()
string = code.__str__()
assert isinstance(string, str)
assert string == str(code.__class__.__module__)
+36
View File
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
"""
Tests for CommentModel class.
Migrated from unittest/TestBase to pytest.
"""
import pytest
from mosaicode.GUI.fieldtypes import *
from mosaicode.model.commentmodel import CommentModel
@pytest.fixture
def comment():
return CommentModel()
def test_commentmodel_new(comment):
comment.set_properties({"text": "Novo Teste"})
comment.set_properties({"Not here": "Novo Teste"})
str(comment)
comment.set_properties(None)
str(comment)
comment.properties = []
str(comment)
comment.properties = []
str(comment)
comment.properties = []
comment.set_properties({"text": "Novo Teste"})
str(comment)
comment.properties = [{"test": "Test"}]
str(comment)
comment = CommentModel()
+284
View File
@@ -0,0 +1,284 @@
# -*- coding: utf-8 -*-
"""
Tests for ConnectionModel class.
Migrated from unittest to pytest.
"""
import pytest
from mosaicode.model.connectionmodel import ConnectionModel
from mosaicode.model.port import Port
@pytest.fixture
def diagram():
"""Create a test diagram."""
from mosaicode.model.diagrammodel import DiagramModel
return DiagramModel()
@pytest.fixture
def block1():
"""Create a test block 1."""
from mosaicode.model.blockmodel import BlockModel
block = BlockModel()
block.id = 1
block.type = "TestBlock1"
block.label = "Test Block 1"
return block
@pytest.fixture
def block2():
"""Create a test block 2."""
from mosaicode.model.blockmodel import BlockModel
block = BlockModel()
block.id = 2
block.type = "TestBlock2"
block.label = "Test Block 2"
return block
@pytest.fixture
def port1():
"""Create a test port 1."""
port = Port()
port.name = "output_port"
port.conn_type = Port.OUTPUT
return port
@pytest.fixture
def port2():
"""Create a test port 2."""
port = Port()
port.name = "input_port"
port.conn_type = Port.INPUT
return port
def test_connection_model_initialization(diagram, block1, block2, port1, port2):
"""Test ConnectionModel initialization."""
connection = ConnectionModel(
diagram,
block1,
port1,
block2,
port2
)
assert connection is not None
def test_connection_model_default_values(diagram, block1, block2, port1, port2):
"""Test ConnectionModel default values."""
connection = ConnectionModel(
diagram,
block1,
port1,
block2,
port2
)
# Test default attributes
assert connection.diagram == diagram
assert connection.output == block1
assert connection.input == block2
assert connection.output_port == port1
assert connection.input_port == port2
def test_connection_model_with_none_values(diagram):
"""Test ConnectionModel with None values."""
connection = ConnectionModel(
diagram,
None,
None,
None,
None
)
# Test with None values
assert connection.diagram == diagram
assert connection.output is None
assert connection.input is None
assert connection.output_port is None
assert connection.input_port is None
def test_connection_model_set_values(diagram, block1, block2, port1, port2):
"""Test setting values in ConnectionModel."""
connection = ConnectionModel(
diagram,
block1,
port1,
block2,
port2
)
# Test that values are set correctly
assert connection.diagram == diagram
assert connection.output == block1
assert connection.input == block2
assert connection.output_port == port1
assert connection.input_port == port2
def test_connection_model_validation(diagram, block1, block2, port1, port2):
"""Test ConnectionModel validation."""
# Test with valid blocks and ports
connection = ConnectionModel(
diagram,
block1,
port1,
block2,
port2
)
# Verify connection is valid
assert connection.diagram is not None
assert connection.output is not None
assert connection.input is not None
assert connection.output_port is not None
assert connection.input_port is not None
def test_connection_model_equality(diagram, block1, block2, port1, port2):
"""Test ConnectionModel equality."""
connection1 = ConnectionModel(
diagram,
block1,
port1,
block2,
port2
)
connection2 = ConnectionModel(
diagram,
block1,
port1,
block2,
port2
)
# Test equality
assert connection1.diagram == connection2.diagram
assert connection1.output == connection2.output
assert connection1.input == connection2.input
assert connection1.output_port == connection2.output_port
assert connection1.input_port == connection2.input_port
def test_connection_model_str_representation(diagram, block1, block2, port1, port2):
"""Test ConnectionModel string representation."""
connection = ConnectionModel(
diagram,
block1,
port1,
block2,
port2
)
# Test string representation
str_repr = str(connection)
assert isinstance(str_repr, str)
def test_connection_model_with_different_ports(diagram, block1, block2):
"""Test ConnectionModel with different port types."""
# Create different ports
port1 = Port()
port1.name = "output_port"
port1.conn_type = Port.OUTPUT
port2 = Port()
port2.name = "input_port"
port2.conn_type = Port.INPUT
connection = ConnectionModel(
diagram,
block1,
port1,
block2,
port2
)
# Verify connection
assert connection.output_port == port1
assert connection.input_port == port2
if connection.output_port:
assert connection.output_port.name == "output_port"
if connection.input_port:
assert connection.input_port.name == "input_port"
def test_connection_model_serialization(diagram, block1, block2, port1, port2):
"""Test ConnectionModel serialization."""
connection = ConnectionModel(
diagram,
block1,
port1,
block2,
port2
)
# Test to_dict method if it exists
if hasattr(connection, 'to_dict'):
data = connection.to_dict()
assert isinstance(data, dict)
def test_connection_model_from_dict(diagram, block1, block2, port1, port2):
"""Test creating ConnectionModel from dictionary."""
data = {
'diagram': diagram,
'output': block1,
'input': block2,
'output_port': port1,
'input_port': port2
}
# Test from_dict method if it exists
if hasattr(ConnectionModel, 'from_dict'):
connection = ConnectionModel.from_dict(data)
assert connection.diagram == diagram
assert connection.output == block1
assert connection.input == block2
def test_connection_model_copy(diagram, block1, block2, port1, port2):
"""Test copying ConnectionModel."""
connection1 = ConnectionModel(
diagram,
block1,
port1,
block2,
port2
)
# Test copy if method exists
if hasattr(connection1, 'copy'):
connection2 = connection1.copy()
assert connection1.diagram == connection2.diagram
assert connection1.output == connection2.output
assert connection1.input == connection2.input
assert connection1 is not connection2
def test_connection_model_empty_diagram(block1, block2, port1, port2):
"""Test ConnectionModel with empty diagram."""
from mosaicode.model.diagrammodel import DiagramModel
empty_diagram = DiagramModel()
empty_diagram.blocks = {}
empty_diagram.connectors = []
connection = ConnectionModel(
empty_diagram,
block1,
port1,
block2,
port2
)
# Verify connection works with empty diagram
assert connection.diagram == empty_diagram
assert connection.output == block1
assert connection.input == block2
+269
View File
@@ -0,0 +1,269 @@
# -*- coding: utf-8 -*-
"""
Tests for DiagramModel class.
Migrated from unittest to pytest.
"""
import pytest
from pathlib import Path
from mosaicode.model.diagrammodel import DiagramModel
from mosaicode.model.blockmodel import BlockModel
from mosaicode.model.commentmodel import CommentModel
@pytest.fixture
def diagram():
"""Create a test diagram."""
return DiagramModel()
@pytest.fixture
def test_block():
"""Create a test block."""
block = BlockModel()
block.id = 1
block.type = "TestBlock"
block.label = "Test Block"
return block
@pytest.fixture
def test_comment():
"""Create a test comment."""
comment = CommentModel()
comment.id = 1
comment.x = 100
comment.y = 100
return comment
def test_diagram_model_initialization(diagram):
"""Test DiagramModel initialization."""
assert diagram is not None
def test_diagram_model_default_values(diagram):
"""Test DiagramModel default values."""
# Test default attributes
assert diagram.last_id == 1
assert diagram.blocks == {}
assert diagram.connectors == []
assert diagram.comments == []
assert diagram.code_template is None
assert diagram.zoom == 1.0
assert diagram.file_name == "Untitled"
assert diagram.modified is False
assert diagram.language is None
assert diagram.undo_stack == []
assert diagram.redo_stack == []
assert diagram.authors == []
def test_diagram_model_set_values(diagram):
"""Test setting values in DiagramModel."""
# Set values
diagram.last_id = 5
diagram.file_name = "test.mscd"
diagram.zoom = 2.0
diagram.modified = True
diagram.language = "python"
# Verify values
assert diagram.last_id == 5
assert diagram.file_name == "test.mscd"
assert diagram.zoom == 2.0
assert diagram.modified is True
assert diagram.language == "python"
def test_patch_name_property(diagram):
"""Test patch_name property."""
# Test with simple filename
diagram.file_name = "test.mscd"
assert diagram.patch_name == "test"
# Test with path
diagram.file_name = "/path/to/test.mscd"
assert diagram.patch_name == "test"
# Test with Windows path - the current implementation returns the full path stem
diagram.file_name = "C:\\path\\to\\test.mscd"
assert diagram.patch_name == "C:\\path\\to\\test"
# Test with no extension
diagram.file_name = "test"
assert diagram.patch_name == "test"
def test_diagram_model_str_representation(diagram):
"""Test DiagramModel string representation."""
diagram.file_name = "test.mscd"
# Test string representation
str_repr = str(diagram)
assert str_repr == "test"
def test_diagram_model_with_blocks(diagram, test_block):
"""Test DiagramModel with blocks."""
# Add blocks
block1 = test_block
block2 = BlockModel()
block2.id = 2
block2.type = "TestBlock2"
block2.label = "Test Block 2"
diagram.blocks = {"1": block1, "2": block2}
# Verify blocks
assert len(diagram.blocks) == 2
assert "1" in diagram.blocks
assert "2" in diagram.blocks
assert diagram.blocks["1"] == block1
assert diagram.blocks["2"] == block2
def test_diagram_model_with_connectors(diagram):
"""Test DiagramModel with connectors."""
# Add connectors (using mock objects)
connector1 = object()
connector2 = object()
diagram.connectors = [connector1, connector2]
# Verify connectors
assert len(diagram.connectors) == 2
assert connector1 in diagram.connectors
assert connector2 in diagram.connectors
def test_diagram_model_with_comments(diagram, test_comment):
"""Test DiagramModel with comments."""
# Add comments
comment1 = test_comment
comment2 = CommentModel()
comment2.id = 2
comment2.x = 200
comment2.y = 200
diagram.comments = [comment1, comment2]
# Verify comments
assert len(diagram.comments) == 2
assert comment1 in diagram.comments
assert comment2 in diagram.comments
def test_diagram_model_with_authors(diagram):
"""Test DiagramModel with authors."""
# Add authors
diagram.authors = ["Author 1", "Author 2"]
# Verify authors
assert len(diagram.authors) == 2
assert "Author 1" in diagram.authors
assert "Author 2" in diagram.authors
def test_diagram_model_with_undo_redo(diagram):
"""Test DiagramModel with undo/redo stacks."""
# Add to undo stack
diagram.undo_stack = ["action1", "action2"]
diagram.redo_stack = ["redo1"]
# Verify stacks
assert len(diagram.undo_stack) == 2
assert len(diagram.redo_stack) == 1
assert "action1" in diagram.undo_stack
assert "action2" in diagram.undo_stack
assert "redo1" in diagram.redo_stack
def test_diagram_model_serialization(diagram):
"""Test DiagramModel serialization."""
diagram.file_name = "test.mscd"
diagram.language = "python"
diagram.modified = True
# Test to_dict method if it exists
if hasattr(diagram, 'to_dict'):
data = diagram.to_dict()
assert isinstance(data, dict)
assert data.get('file_name') == "test.mscd"
assert data.get('language') == "python"
assert data.get('modified') is True
def test_diagram_model_from_dict():
"""Test creating DiagramModel from dictionary."""
data = {
'file_name': 'test.mscd',
'language': 'python',
'modified': True,
'zoom': 2.0,
'last_id': 5
}
# Test from_dict method if it exists
if hasattr(DiagramModel, 'from_dict'):
diagram = DiagramModel.from_dict(data)
assert diagram.file_name == "test.mscd"
assert diagram.language == "python"
assert diagram.modified is True
assert diagram.zoom == 2.0
assert diagram.last_id == 5
def test_diagram_model_copy(diagram):
"""Test copying DiagramModel."""
diagram.file_name = "test.mscd"
diagram.language = "python"
# Test copy if method exists
if hasattr(diagram, 'copy'):
diagram2 = diagram.copy()
assert diagram.file_name == diagram2.file_name
assert diagram.language == diagram2.language
assert diagram is not diagram2
def test_diagram_model_empty_values(diagram):
"""Test DiagramModel with empty values."""
# Test setting empty values
diagram.file_name = ""
diagram.language = ""
diagram.authors = []
# Verify empty values are accepted
assert diagram.file_name == ""
assert diagram.language == ""
assert diagram.authors == []
assert diagram.patch_name == ""
def test_diagram_model_special_characters(diagram):
"""Test DiagramModel with special characters."""
# Test with special characters
diagram.file_name = "testé.mscd"
diagram.language = "pythön"
# Verify special characters are preserved
assert diagram.file_name == "testé.mscd"
assert diagram.language == "pythön"
assert diagram.patch_name == "testé"
def test_diagram_model_edge_cases(diagram):
"""Test DiagramModel edge cases."""
# Test with very long filename
long_filename = "a" * 1000 + ".mscd"
diagram.file_name = long_filename
assert diagram.file_name == long_filename
# Test with filename without extension
diagram.file_name = "noextension"
assert diagram.patch_name == "noextension"
# Test with filename with multiple dots
diagram.file_name = "test.file.mscd"
assert diagram.patch_name == "test.file"
+19
View File
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
"""
Tests for Port class.
Migrated from unittest to pytest.
"""
import pytest
from mosaicode.model.port import Port
def test_init():
"""Test Port initialization and connection type."""
model = Port()
assert model.is_input() is False
model.conn_type = Port.INPUT
assert model.is_input() is True
model.conn_type = Port.OUTPUT
assert model.is_input() is False
+15
View File
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
"""
Tests for Preferences class.
Migrated from unittest to pytest.
"""
import pytest
from mosaicode.model.preferences import Preferences
def test_init():
"""Test Preferences initialization."""
model = Preferences()
assert model is not None