Commit 9268b733 authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

[test][toolchainscene] adding toolchain scene tests

Fixes #251
parent b317efa6
...@@ -25,11 +25,16 @@ ...@@ -25,11 +25,16 @@
import pytest import pytest
from PyQt5.QtWidgets import QGraphicsScene
from PyQt5.QtWidgets import QGraphicsView
from ..backend.asset import Asset from ..backend.asset import Asset
from ..backend.asset import AssetType from ..backend.asset import AssetType
from ..backend.assetmodel import AssetModel from ..backend.assetmodel import AssetModel
from ..widgets.toolchaineditor import ToolchainEditor from ..widgets.toolchaineditor import ToolchainEditor
from ..widgets.toolchaineditor import ToolchainView
from ..widgets.toolchainscene import ToolchainScene
from .conftest import sync_prefix from .conftest import sync_prefix
from .conftest import prefix from .conftest import prefix
...@@ -53,6 +58,62 @@ def get_valid_toolchains(test_prefix): ...@@ -53,6 +58,62 @@ def get_valid_toolchains(test_prefix):
] ]
class TestToolchainScene:
def test_good_init(self, qtbot):
configuration = {"grid_size": 1000, "grid_color": [220, 220, 220, 220]}
scene = ToolchainScene(configuration)
assert isinstance(scene, QGraphicsScene)
assert scene.grid_size == configuration["grid_size"]
assert scene.grid_color == configuration["grid_color"]
def test_bad_init(self, qtbot):
configuration = {"bad": 1000}
scene = ToolchainScene(configuration)
assert isinstance(scene, QGraphicsScene)
assert scene.grid_size == 36
assert scene.grid_color == [232, 232, 232, 255]
def test_bad_grid_size_type(self, qtbot):
configuration = {"grid_size": 1000.0}
with pytest.raises(TypeError) as excinfo:
ToolchainScene(configuration)
expected_exception_message = "Grid size configuration has to be of type integer"
assert str(excinfo.value) == expected_exception_message
def test_bad_grid_color_type(self, qtbot):
configuration = {"grid_color": "blue"}
with pytest.raises(TypeError) as excinfo:
ToolchainScene(configuration)
expected_exception_message = "Grid color configuration has to be of type list"
assert str(excinfo.value) == expected_exception_message
def test_bad_grid_color_elements_size(self, qtbot):
configuration = {"grid_color": [220, 220]}
with pytest.raises(TypeError) as excinfo:
ToolchainScene(configuration)
expected_exception_message = "Invalid grid element types or unmatching size"
assert str(excinfo.value) == expected_exception_message
def test_wrong_grid_color_elements_types(self, qtbot):
configuration = {"grid_color": [220, 220, 220.0]}
with pytest.raises(TypeError) as excinfo:
ToolchainScene(configuration)
expected_exception_message = "Invalid grid element types or unmatching size"
assert str(excinfo.value) == expected_exception_message
@pytest.mark.parametrize("toolchain", get_valid_toolchains(prefix))
def test_add_scene_to_view(self, qtbot, toolchain):
configuration = {"grid_size": 1000, "grid_color": [220, 220, 220, 220]}
scene = ToolchainScene(configuration)
toolchainview = ToolchainView(toolchain)
assert toolchainview.scene() is None
toolchainview.setScene(scene)
assert toolchainview.scene() == scene
assert isinstance(toolchainview, QGraphicsView)
assert isinstance(scene, QGraphicsScene)
class TestToolchainEditor: class TestToolchainEditor:
"""Test that the mock editor works correctly""" """Test that the mock editor works correctly"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment