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
b7bed576
Commit
b7bed576
authored
Jan 11, 2019
by
Samuel GAIST
Browse files
[test][editor] Code cleanup
- Moved test into a class - Use fixture for model creation
parent
0d66210b
Changes
1
Hide whitespace changes
Inline
Side-by-side
beat/editor/test/test_editors.py
View file @
b7bed576
...
...
@@ -22,6 +22,7 @@
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
import
pytest
from
PyQt5
import
QtCore
...
...
@@ -36,7 +37,7 @@ from ..widgets.field import Field
class
MockAssetEditor
(
AbstractAssetEditor
):
"""
Base class of all asset
editor
s
Mock editor to show how to test an
editor
"""
def
__init__
(
self
,
parent
=
None
):
...
...
@@ -56,6 +57,7 @@ class MockAssetEditor(AbstractAssetEditor):
def
load_json
(
self
,
json_object
):
"""Load the json object passed as parameter"""
for
name
,
type_
in
json_object
.
items
():
field
=
Field
(
self
.
dataformat_model
)
field
.
format_name
=
name
...
...
@@ -64,6 +66,7 @@ class MockAssetEditor(AbstractAssetEditor):
def
dump_json
(
self
):
"""Returns the json representation of the asset"""
field_list
=
self
.
findChildren
(
Field
)
json_data
=
{}
...
...
@@ -74,31 +77,47 @@ class MockAssetEditor(AbstractAssetEditor):
return
json_data
def
test_json_load_and_dump
(
qtbot
):
json_reference
=
{
"value32"
:
"float32"
,
"value64"
:
"float64"
}
@
pytest
.
fixture
()
def
dataformat_model
():
return
QStringListModel
([
"float32"
,
"float64"
,
"int32"
,
"int64"
])
class
TestMockEditor
:
"""Test that the mock editor works correctly"""
def
test_json_load_and_dump
(
self
,
qtbot
,
dataformat_model
):
json_reference
=
{
"value32"
:
"float32"
,
"value64"
:
"float64"
}
widget
=
MockAssetEditor
()
widget
.
set_dataformat_model
(
dataformat_model
)
widget
.
load_json
(
json_reference
)
assert
widget
.
dump_json
()
==
json_reference
dataformat_model
=
QStringListModel
([
"float32"
,
"float64"
,
"int32"
,
"int64"
])
def
test_dataformat_creation
(
self
,
qtbot
,
dataformat_model
):
widget
=
MockAssetEditor
()
widget
.
set_dataformat_model
(
dataformat_model
)
widget
=
MockAssetEditor
()
widget
.
set_dataformat_model
(
dataformat_model
)
widget
.
load_json
(
json_reference
)
qtbot
.
mouseClick
(
widget
.
add_field_button
,
QtCore
.
Qt
.
LeftButton
)
fields
=
widget
.
findChildren
(
Field
)
assert
widget
.
dump_json
()
==
json_reference
assert
len
(
fields
)
==
1
field
=
fields
[
0
]
def
test_dataformat_creation
(
qtbot
):
# json_reference = {"value32": "float32", "value64":
"float
64"}
field
.
format_name
=
"value32"
field
.
format_type
=
"float
32"
dataformat_model
=
QStringListModel
([
"float
32"
,
"float
64"
,
"int32"
,
"int64"
])
assert
widget
.
dump_json
()
==
{
"value
32"
:
"float
32"
}
widget
=
MockAssetEditor
(
)
widget
.
set_dataformat_model
(
dataformat_mod
el
)
qtbot
.
mouseClick
(
widget
.
add_field_button
,
QtCore
.
Qt
.
LeftButton
)
fields
=
widget
.
findChildren
(
Fi
el
d
)
qtbot
.
mouseClick
(
widget
.
add_field_button
,
QtCore
.
Qt
.
LeftButton
)
fields
=
widget
.
findChildren
(
Field
)
assert
len
(
fields
)
==
2
assert
len
(
fields
)
==
1
field
=
fields
[
1
]
field
=
fields
[
0
]
field
.
format_name
=
"value64"
field
.
format_type
=
"float64"
qtbot
.
mouseClick
(
field
.
dataformat_box
,
QtCore
.
Qt
.
LeftButton
)
assert
widget
.
dump_json
()
==
{
"value32"
:
"float32"
,
"value64"
:
"float64"
}
Write
Preview
Supports
Markdown
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