Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beat.editor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
beat
beat.editor
Commits
a469913c
Commit
a469913c
authored
6 years ago
by
Flavio TARSETTI
Browse files
Options
Downloads
Patches
Plain Diff
[test] refactored description widget's tests
parent
e0434e4d
No related branches found
No related tags found
1 merge request
!55
Reusable widget short description
Pipeline
#27610
passed
6 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
beat/editor/test/test_editors.py
+28
-34
28 additions, 34 deletions
beat/editor/test/test_editors.py
with
28 additions
and
34 deletions
beat/editor/test/test_editors.py
+
28
−
34
View file @
a469913c
...
@@ -58,39 +58,33 @@ class MockAssetEditor(AbstractAssetEditor):
...
@@ -58,39 +58,33 @@ class MockAssetEditor(AbstractAssetEditor):
def
set_dataformat_model
(
self
,
model
):
def
set_dataformat_model
(
self
,
model
):
self
.
dataformat_model
=
model
self
.
dataformat_model
=
model
def
load_json
(
self
,
json_object
):
def
load_json
(
self
,
json_object
,
widget_type
):
"""
Load the json object passed as parameter
"""
"""
Load the json object passed as parameter
"""
for
name
,
type_
in
json_object
.
items
():
if
widget_type
==
"
field
"
:
field
=
FieldWidget
(
self
.
dataformat_model
)
for
name
,
type_
in
json_object
.
items
():
field
.
format_name
=
name
field
=
FieldWidget
(
self
.
dataformat_model
)
field
.
format_type
=
type_
field
.
format_name
=
name
self
.
layout
().
addWidget
(
field
)
field
.
format_type
=
type_
self
.
layout
().
addWidget
(
field
)
def
dump_json
(
self
):
elif
widget_type
==
"
description
"
:
short_text
=
json_object
[
"
short_description
"
]
self
.
description
.
form_description
.
setText
(
short_text
)
def
dump_json
(
self
,
widget_type
):
"""
Returns the json representation of the asset
"""
"""
Returns the json representation of the asset
"""
field_list
=
self
.
findChildren
(
FieldWidget
)
json_data
=
{}
json_data
=
{}
for
field
in
field_list
:
if
widget_type
==
"
field
"
:
json_data
[
field
.
format_name
]
=
field
.
format_type
field_list
=
self
.
findChildren
(
FieldWidget
)
for
field
in
field_list
:
json_data
[
field
.
format_name
]
=
field
.
format_type
elif
widget_type
==
"
description
"
:
json_data
[
"
short_description
"
]
=
self
.
description
.
short_description
()
return
json_data
return
json_data
def
set_description
(
self
,
desc
):
"""
Sets the text description of the asset
"""
self
.
description
.
short_description
=
desc
def
get_description
(
self
):
"""
Returns the text description of the asset
"""
text_data
=
self
.
description
.
short_description
return
text_data
@pytest.fixture
()
@pytest.fixture
()
def
dataformat_model
():
def
dataformat_model
():
...
@@ -100,16 +94,16 @@ def dataformat_model():
...
@@ -100,16 +94,16 @@ def dataformat_model():
class
TestMockEditor
:
class
TestMockEditor
:
"""
Test that the mock editor works correctly
"""
"""
Test that the mock editor works correctly
"""
def
test_json_load_and_dump
(
self
,
qtbot
,
dataformat_model
):
def
test_json_load_and_dump
_field_widget
(
self
,
qtbot
,
dataformat_model
):
json_reference
=
{
"
value32
"
:
"
float32
"
,
"
value64
"
:
"
float64
"
}
json_reference
=
{
"
value32
"
:
"
float32
"
,
"
value64
"
:
"
float64
"
}
widget
=
MockAssetEditor
()
widget
=
MockAssetEditor
()
widget
.
set_dataformat_model
(
dataformat_model
)
widget
.
set_dataformat_model
(
dataformat_model
)
widget
.
load_json
(
json_reference
)
widget
.
load_json
(
json_reference
,
"
field
"
)
assert
widget
.
dump_json
()
==
json_reference
assert
widget
.
dump_json
(
"
field
"
)
==
json_reference
def
test_dataformat_creation
(
self
,
qtbot
,
dataformat_model
):
def
test_dataformat_creation
_field_widget
(
self
,
qtbot
,
dataformat_model
):
widget
=
MockAssetEditor
()
widget
=
MockAssetEditor
()
widget
.
set_dataformat_model
(
dataformat_model
)
widget
.
set_dataformat_model
(
dataformat_model
)
...
@@ -123,7 +117,7 @@ class TestMockEditor:
...
@@ -123,7 +117,7 @@ class TestMockEditor:
field
.
format_name
=
"
value32
"
field
.
format_name
=
"
value32
"
field
.
format_type
=
"
float32
"
field
.
format_type
=
"
float32
"
assert
widget
.
dump_json
()
==
{
"
value32
"
:
"
float32
"
}
assert
widget
.
dump_json
(
"
field
"
)
==
{
"
value32
"
:
"
float32
"
}
qtbot
.
mouseClick
(
widget
.
add_field_button
,
QtCore
.
Qt
.
LeftButton
)
qtbot
.
mouseClick
(
widget
.
add_field_button
,
QtCore
.
Qt
.
LeftButton
)
fields
=
widget
.
findChildren
(
FieldWidget
)
fields
=
widget
.
findChildren
(
FieldWidget
)
...
@@ -135,13 +129,13 @@ class TestMockEditor:
...
@@ -135,13 +129,13 @@ class TestMockEditor:
field
.
format_name
=
"
value64
"
field
.
format_name
=
"
value64
"
field
.
format_type
=
"
float64
"
field
.
format_type
=
"
float64
"
assert
widget
.
dump_json
()
==
{
"
value32
"
:
"
float32
"
,
"
value64
"
:
"
float64
"
}
assert
widget
.
dump_json
(
"
field
"
)
==
{
"
value32
"
:
"
float32
"
,
"
value64
"
:
"
float64
"
}
def
test_description_
set_and_
get
(
self
,
qtbot
,
dataformat_model
):
def
test_
json_load_and_dump_
description_
wid
get
(
self
,
qtbot
):
text
_reference
=
"
short
descr
1
iption
of a beat objec
t
"
json
_reference
=
{
"
short
_
description
"
:
"
Short description tes
t
"
}
widget
=
MockAssetEditor
()
widget
=
MockAssetEditor
()
widget
.
set_dataformat_model
(
dataformat_model
)
widget
.
set_dataformat_model
(
dataformat_model
)
widget
.
set_description
(
text_reference
)
widget
.
load_json
(
json_reference
,
"
description
"
)
assert
widget
.
get_
description
(
)
==
text
_reference
assert
widget
.
dump_json
(
"
description
"
)
==
json
_reference
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment