Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DashboardLeaf
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ProjectLeaf
DashboardLeaf
Commits
56861662
Commit
56861662
authored
4 years ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
SensorLineChartTile: Refactoring: group tests info class
parent
4f334b8d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/logic/tile/tiles/TestSensorLineChartTile.py
+86
-112
86 additions, 112 deletions
src/logic/tile/tiles/TestSensorLineChartTile.py
with
86 additions
and
112 deletions
src/logic/tile/tiles/TestSensorLineChartTile.py
+
86
−
112
View file @
56861662
import
datetime
from
unittest.mock
import
MagicMock
import
pytest
from
logic.tile.tiles.SensorLineChartTile
import
SensorLineChartTile
,
SensorType
@pytest.fixture
()
def
example_settings
():
return
{
"
title
"
:
"
My Room
"
,
"
url
"
:
"
http://127.0.0.1:10003
"
,
"
sensorID
"
:
1
,
"
sensorIDsForMinMax
"
:
[
2
,
3
,
4
],
"
numberOfHoursToShow
"
:
4
,
"
decimals
"
:
1
,
"
lineColor
"
:
"
rgba(254, 151, 0, 1)
"
,
"
fillColor
"
:
"
rgba(254, 151, 0, 0.2)
"
,
"
showAxes
"
:
False
,
"
outdatedValueWarningLimitInSeconds
"
:
300
# use -1 to disable warning
}
@pytest.fixture
()
def
example_settings_with_axes
():
def
example_settings
(
showAxes
:
bool
):
return
{
"
title
"
:
"
My Room
"
,
"
url
"
:
"
http://127.0.0.1:10003
"
,
...
...
@@ -33,7 +14,7 @@ def example_settings_with_axes():
"
decimals
"
:
1
,
"
lineColor
"
:
"
rgba(254, 151, 0, 1)
"
,
"
fillColor
"
:
"
rgba(254, 151, 0, 0.2)
"
,
"
showAxes
"
:
True
,
"
showAxes
"
:
showAxes
,
"
outdatedValueWarningLimitInSeconds
"
:
300
# use -1 to disable warning
}
...
...
@@ -47,94 +28,87 @@ def storage_leaf_service_mock(minValue, maxValue):
return
storageLeafServiceMock
class
TestGetMinMax
:
START_DATE
=
datetime
.
date
(
year
=
2021
,
month
=
2
,
day
=
8
)
END_DATE
=
datetime
.
date
(
year
=
2021
,
month
=
2
,
day
=
9
)
def
test_humidity_returns_0_and_100
(
example_settings
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings
,
10
)
def
test_humidity_returns_0_and_100
(
self
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings
(
False
),
10
)
yValues
=
[
'
12.5
'
,
'
10.5
'
]
result
=
tile
.
_get_min_and_max
(
'
myPage
'
,
SensorType
.
HUMIDITY
,
START_DATE
,
END_DATE
,
self
.
START_DATE
,
self
.
END_DATE
,
storage_leaf_service_mock
(
15.0
,
20.0
),
yValues
)
assert
result
==
(
0
,
100
)
def
test_temperature_no_values_returns_min_and_max_of_api
(
example_settings
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings
,
10
)
def
test_temperature_no_values_returns_min_and_max_of_api
(
self
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings
(
False
),
10
)
result
=
tile
.
_get_min_and_max
(
'
myPage
'
,
SensorType
.
TEMPERATURE
,
START_DATE
,
END_DATE
,
self
.
START_DATE
,
self
.
END_DATE
,
storage_leaf_service_mock
(
15.0
,
20.0
),
[])
assert
result
==
(
-
SensorLineChartTile
.
MAX_Y_AXIS_SPACING
,
20
+
SensorLineChartTile
.
MAX_Y_AXIS_SPACING
)
def
test_temperature_min_max_data_is_none_returns_zero
(
example_settings
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings
,
10
)
def
test_temperature_min_max_data_is_none_returns_zero
(
self
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings
(
False
),
10
)
result
=
tile
.
_get_min_and_max
(
'
myPage
'
,
SensorType
.
TEMPERATURE
,
START_DATE
,
END_DATE
,
self
.
START_DATE
,
self
.
END_DATE
,
storage_leaf_service_mock
(
None
,
None
),
[])
assert
result
==
(
-
SensorLineChartTile
.
MAX_Y_AXIS_SPACING
,
SensorLineChartTile
.
MAX_Y_AXIS_SPACING
)
def
test_temperature_min_is_above_zero_returns_zero_min
(
example_settings
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings
,
10
)
def
test_temperature_min_is_above_zero_returns_zero_min
(
self
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings
(
False
),
10
)
result
=
tile
.
_get_min_and_max
(
'
myPage
'
,
SensorType
.
TEMPERATURE
,
START_DATE
,
END_DATE
,
self
.
START_DATE
,
self
.
END_DATE
,
storage_leaf_service_mock
(
5
,
6
),
[])
assert
result
==
(
-
SensorLineChartTile
.
MAX_Y_AXIS_SPACING
,
6
+
SensorLineChartTile
.
MAX_Y_AXIS_SPACING
)
def
test_temperature_min_is_below_zero_returns_min
(
example_settings
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings
,
10
)
def
test_temperature_min_is_below_zero_returns_min
(
self
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings
(
False
),
10
)
result
=
tile
.
_get_min_and_max
(
'
myPage
'
,
SensorType
.
TEMPERATURE
,
START_DATE
,
END_DATE
,
self
.
START_DATE
,
self
.
END_DATE
,
storage_leaf_service_mock
(
-
3
,
6
),
[])
assert
result
==
(
-
3
-
SensorLineChartTile
.
MAX_Y_AXIS_SPACING
,
6
+
SensorLineChartTile
.
MAX_Y_AXIS_SPACING
)
def
test_temperature_show_axes_no_values
(
example_settings_with_axes
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings_with_axes
,
10
)
def
test_temperature_show_axes_no_values
(
self
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings
(
True
),
10
)
result
=
tile
.
_get_min_and_max
(
'
myPage
'
,
SensorType
.
TEMPERATURE
,
START_DATE
,
END_DATE
,
self
.
START_DATE
,
self
.
END_DATE
,
storage_leaf_service_mock
(
None
,
None
),
[])
assert
result
==
(
-
SensorLineChartTile
.
MAX_Y_AXIS_SPACING
,
SensorLineChartTile
.
MAX_Y_AXIS_SPACING
)
def
test_temperature_show_axes_values_above_zero_return_zero_min
(
example_settings_with_axes
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings_with_axes
,
10
)
def
test_temperature_show_axes_values_above_zero_return_zero_min
(
self
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings
(
True
),
10
)
result
=
tile
.
_get_min_and_max
(
'
myPage
'
,
SensorType
.
TEMPERATURE
,
START_DATE
,
END_DATE
,
self
.
START_DATE
,
self
.
END_DATE
,
storage_leaf_service_mock
(
None
,
None
),
[
6.0
,
12
])
assert
result
==
(
-
SensorLineChartTile
.
MAX_Y_AXIS_SPACING
,
12
+
SensorLineChartTile
.
MAX_Y_AXIS_SPACING
)
def
test_temperature_show_axes_values_below_zero_return_min
(
example_settings_with_axes
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings_with_axes
,
10
)
def
test_temperature_show_axes_values_below_zero_return_min
(
self
):
tile
=
SensorLineChartTile
(
'
mySensorTile
'
,
example_settings
(
True
),
10
)
result
=
tile
.
_get_min_and_max
(
'
myPage
'
,
SensorType
.
TEMPERATURE
,
START_DATE
,
END_DATE
,
self
.
START_DATE
,
self
.
END_DATE
,
storage_leaf_service_mock
(
None
,
None
),
[
-
6.0
,
12
])
assert
result
==
(
-
6
-
SensorLineChartTile
.
MAX_Y_AXIS_SPACING
,
12
+
SensorLineChartTile
.
MAX_Y_AXIS_SPACING
)
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