Commit dd5dd12d authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[test][assetwidget] Add more test

Tests added:
  - widget factory method
  - change on disk detection
  - root_prefix_path property
parent f496515e
......@@ -31,6 +31,7 @@ from PyQt5 import QtCore
from PyQt5.QtWidgets import QMessageBox
from ..widgets.assetwidget import AssetWidget
from ..widgets.assetwidget import widget_for_asset_type
from ..widgets.dialogs import AssetCreationDialog
from ..widgets.editor import PlaceholderEditor
......@@ -69,6 +70,11 @@ def asset_type_prefix_entry_map():
}
def test_widget_factory_error():
with pytest.raises(RuntimeError):
widget_for_asset_type("dummy")
class TestAssetWidget:
"""Test that the AssetWidget works correctly"""
......@@ -96,6 +102,13 @@ class TestAssetWidget:
assert isinstance(asset_widget.current_editor, editor_type)
def test_prefix_root_path(self, qtbot, test_prefix, beat_context):
asset_widget = AssetWidget()
qtbot.addWidget(asset_widget)
asset_widget.set_context(beat_context)
assert asset_widget.prefix_root_path == test_prefix
def test_dirty(
self, qtbot, monkeypatch, test_prefix, beat_context, asset_type_prefix_entry_map
):
......@@ -334,3 +347,33 @@ class TestAssetWidget:
with qtbot.assertNotEmitted(asset_widget.currentAssetChanged):
asset_widget.loadAsset(asset)
def test_change_on_disk(
self,
qtbot,
monkeypatch,
test_prefix,
beat_context,
asset_type,
asset_type_prefix_entry_map,
):
asset_widget = AssetWidget()
qtbot.addWidget(asset_widget)
asset_widget.set_context(beat_context)
asset_name = asset_type_prefix_entry_map[asset_type][0]
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes)
asset = Asset(test_prefix, asset_type, asset_name)
with qtbot.waitSignal(asset_widget.currentAssetChanged):
asset_widget.loadAsset(asset)
asset_widget.save_button.setEnabled(True)
declaration = asset.declaration
declaration["description"] = "modified"
with qtbot.waitSignal(asset_widget.watcher.fileChanged):
asset.declaration = declaration
assert not asset_widget.save_button.isEnabled()
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