Commit df08a2eb authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

[test/widget] improve unit tests and correct typos

parent f698c6d1
Pipeline #37711 passed with stage
in 12 minutes and 59 seconds
......@@ -27,7 +27,6 @@ import pytest
import simplejson as json
from PyQt5.QtCore import QFile
from PyQt5.QtCore import QIODevice
from PyQt5.QtWidgets import QGraphicsScene
from PyQt5.QtWidgets import QGraphicsView
......@@ -45,11 +44,10 @@ from .conftest import prefix
def toolchain_config():
config_data = {}
_file = QFile(":/resources/toolchain_style_config")
if _file.open(QFile.ReadOnly | QIODevice.Text):
config_data = json.loads(_file.readAll().data().decode("utf-8"))
return config_data
file_ = QFile(":/resources/toolchain_style_config")
is_open = file_.open(QFile.ReadOnly | QFile.Text)
assert is_open
return json.loads(file_.readAll().data().decode("utf-8"))
@pytest.fixture()
......@@ -77,14 +75,10 @@ def get_valid_toolchains(test_prefix):
class TestToolchainScene:
def test_good_init(self, qtbot, scene_config):
configuration = {
"grid_size": scene_config["grid_size"],
"grid_color": scene_config["grid_color"],
}
scene = ToolchainScene(configuration)
scene = ToolchainScene(scene_config)
assert isinstance(scene, QGraphicsScene)
assert scene.grid_size == configuration["grid_size"]
assert scene.grid_color == configuration["grid_color"]
assert scene.grid_size == scene_config["grid_size"]
assert scene.grid_color == scene_config["grid_color"]
def test_bad_init(self, qtbot, scene_config):
configuration = {"bad": 1000}
......@@ -115,9 +109,8 @@ class TestToolchainScene:
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)
def test_add_scene_to_view(self, qtbot, toolchain, scene_config):
scene = ToolchainScene(scene_config)
toolchainview = ToolchainView(toolchain)
assert toolchainview.scene() is None
......
......@@ -35,7 +35,6 @@ from PyQt5.QtCore import QPointF
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import QFile
from PyQt5.QtCore import QIODevice
from PyQt5.QtGui import QColor
from PyQt5.QtGui import QBrush
......@@ -1426,9 +1425,9 @@ class Toolchain(QWidget):
self.autonomous_loop_evaluator_list = []
config_data = {}
_file = QFile(":/resources/toolchain_style_config")
if _file.open(QFile.ReadOnly | QIODevice.Text):
config_data = json.loads(_file.readAll().data().decode("utf-8"))
file_ = QFile(":/resources/toolchain_style_config")
if file_.open(QFile.ReadOnly | QFile.Text):
config_data = json.loads(file_.readAll().data().decode("utf-8"))
self.scene_config = config_data["toolchainscene_config"]
self.scene = ToolchainScene(self.scene_config)
......
Markdown is supported
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