Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.editor
Commits
1d10ce54
Commit
1d10ce54
authored
Jun 28, 2019
by
Samuel GAIST
Committed by
Samuel GAIST
Jun 28, 2019
Browse files
[widgets][assetwidget] Don't load invalid asset
Fixes
#232
parent
28a6b07b
Pipeline
#31546
passed with stage
in 23 minutes and 20 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
beat/editor/test/test_assetwidget.py
View file @
1d10ce54
...
...
@@ -306,3 +306,26 @@ class TestAssetWidget:
asset_widget
.
deleteAsset
(
asset
.
declaration_path
)
assert
asset_widget
.
current_editor
.
asset_type
==
AssetType
.
UNKNOWN
assert
not
os
.
path
.
exists
(
asset
.
declaration_path
)
def
test_load_empty_json
(
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
,
"critical"
,
lambda
*
args
:
QMessageBox
.
Ok
)
asset
=
Asset
(
test_prefix
,
asset_type
,
asset_name
)
with
open
(
asset
.
declaration_path
,
"wt"
)
as
declaration_file
:
declaration_file
.
write
(
""
)
asset
=
Asset
(
test_prefix
,
asset_type
,
asset_name
)
asset_widget
.
loadAsset
(
asset
)
beat/editor/widgets/assetwidget.py
View file @
1d10ce54
...
...
@@ -355,12 +355,20 @@ class AssetWidget(QWidget):
self
.
maybe_save
()
self
.
current_asset
=
asset
self
.
__clear_watcher
()
self
.
watcher
.
addPath
(
self
.
current_asset
.
declaration_path
)
self
.
__update_content
()
is_valid
,
errors
=
asset
.
is_valid
()
if
not
is_valid
:
QMessageBox
.
critical
(
self
,
self
.
tr
(
"Invalid asset"
),
self
.
tr
(
f
"The asset you are trying to load is invalid
\n
{
errors
}
"
),
)
else
:
self
.
watcher
.
addPath
(
asset
.
declaration_path
)
self
.
current_asset
=
asset
self
.
__update_content
()
@
pyqtSlot
()
def
saveJson
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment