# Conflicts: # .github/workflows/build.yml # docs/conf.py # docs/development/environment.rst # docs/sphinxext/codeblockext.py # docs/sphinxext/onlineinclude.py # setup.py # src/octoprint/access/groups.py # src/octoprint/access/permissions.py # src/octoprint/access/users.py # src/octoprint/cli/__init__.py # src/octoprint/cli/analysis.py # src/octoprint/cli/client.py # src/octoprint/cli/config.py # src/octoprint/cli/plugins.py # src/octoprint/cli/server.py # src/octoprint/cli/user.py # src/octoprint/environment.py # src/octoprint/events.py # src/octoprint/filemanager/__init__.py # src/octoprint/filemanager/analysis.py # src/octoprint/filemanager/destinations.py # src/octoprint/filemanager/storage.py # src/octoprint/filemanager/util.py # src/octoprint/logging/__init__.py # src/octoprint/logging/handlers.py # src/octoprint/plugin/__init__.py # src/octoprint/plugin/core.py # src/octoprint/plugins/action_command_notification/__init__.py # src/octoprint/plugins/action_command_prompt/__init__.py # src/octoprint/plugins/appkeys/__init__.py # src/octoprint/plugins/backup/__init__.py # src/octoprint/plugins/corewizard/__init__.py # src/octoprint/plugins/corewizard/subwizards.py # src/octoprint/plugins/discovery/__init__.py # src/octoprint/plugins/errortracking/__init__.py # src/octoprint/plugins/gcodeviewer/__init__.py # src/octoprint/plugins/logging/__init__.py # src/octoprint/plugins/pi_support/__init__.py # src/octoprint/plugins/softwareupdate/cli.py # src/octoprint/plugins/softwareupdate/updaters/single_file_plugin.py # src/octoprint/plugins/softwareupdate/updaters/sleep_a_bit.py # src/octoprint/plugins/softwareupdate/version_checks/always_current.py # src/octoprint/plugins/softwareupdate/version_checks/bitbucket_commit.py # src/octoprint/plugins/softwareupdate/version_checks/github_release.py # src/octoprint/plugins/softwareupdate/version_checks/httpheader.py # src/octoprint/plugins/softwareupdate/version_checks/jsondata.py # src/octoprint/plugins/softwareupdate/version_checks/never_current.py # src/octoprint/plugins/softwareupdate/version_checks/pypi_release.py # src/octoprint/plugins/tracking/__init__.py # src/octoprint/plugins/virtual_printer/virtual.py # src/octoprint/printer/__init__.py # src/octoprint/printer/estimation.py # src/octoprint/printer/profile.py # src/octoprint/printer/standard.py # src/octoprint/server/__init__.py # src/octoprint/server/api/__init__.py # src/octoprint/server/api/system.py # src/octoprint/server/api/users.py # src/octoprint/server/util/flask.py # src/octoprint/server/util/tornado.py # src/octoprint/server/util/webassets.py # src/octoprint/settings.py # src/octoprint/slicing/__init__.py # src/octoprint/timelapse.py # src/octoprint/util/__init__.py # src/octoprint/util/comm.py # src/octoprint/util/commandline.py # src/octoprint/util/connectivity.py # src/octoprint/util/fixes.py # src/octoprint/util/gcodeInterpreter.py # src/octoprint/util/jinja.py # src/octoprint/util/json/__init__.py # src/octoprint/util/net.py # src/octoprint_client/__init__.py # src/octoprint_setuptools/__init__.py # tests/filemanager/test_filemanager.py # tests/filemanager/test_localstorage.py # tests/plugin/test_core.py # tests/plugin/test_settings.py # tests/plugin/test_types_blueprint.py # tests/plugin/test_types_settings.py # tests/server/api/test_system.py # tests/server/util/test_flask.py # tests/server/util/test_tornado.py # tests/slicing/test_slicingmanager.py # tests/test_daemon.py # tests/timelapse/test_timelapse_helpers.py # tests/util/test_comm.py # tests/util/test_file_helpers.py # tests/util/test_pip.py # tests/util/test_repeated_timer.py # tests/util/test_resettable_timer.py # versioneer.py
192 lines
6.1 KiB
Python
192 lines
6.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
|
|
|
import unittest
|
|
import unittest.mock as mock
|
|
|
|
import _fixups
|
|
import ddt
|
|
|
|
from octoprint.util.platform import CLOSE_FDS
|
|
|
|
OCTOPI_VERSION = "0.14.0"
|
|
|
|
DT_MODEL = "Raspberry Pi Model F Rev 1.1"
|
|
|
|
VCGENCMD = "/usr/bin/vcgencmd get_throttled"
|
|
|
|
|
|
class PiSupportTestCase(unittest.TestCase):
|
|
def test_get_octopi_version(self):
|
|
from octoprint.plugins.pi_support import get_octopi_version
|
|
|
|
# import _fixups
|
|
|
|
with mock.patch(_fixups.OPEN_SIGNATURE, mock.mock_open(), create=True) as m:
|
|
m.return_value.readline.return_value = OCTOPI_VERSION
|
|
version = get_octopi_version()
|
|
|
|
m.assert_called_once_with("/etc/octopi_version", "rt", encoding="utf-8")
|
|
self.assertEqual(version, OCTOPI_VERSION)
|
|
|
|
def test_get_proc_dt_model(self):
|
|
from octoprint.plugins.pi_support import get_proc_dt_model
|
|
|
|
# import _fixups
|
|
|
|
with mock.patch(_fixups.OPEN_SIGNATURE, mock.mock_open(), create=True) as m:
|
|
m.return_value.readline.return_value = DT_MODEL
|
|
model = get_proc_dt_model()
|
|
|
|
m.assert_called_once_with("/proc/device-tree/model", "rt", encoding="utf-8")
|
|
self.assertEqual(model, DT_MODEL)
|
|
|
|
def test_get_vcgencmd_throttle_state(self):
|
|
from octoprint.plugins.pi_support import get_vcgencmd_throttled_state
|
|
|
|
with mock.patch("sarge.get_stdout", mock.MagicMock()) as m:
|
|
m.return_value = "throttled=0x70005"
|
|
state = get_vcgencmd_throttled_state(VCGENCMD)
|
|
|
|
m.assert_called_once_with(VCGENCMD, close_fds=CLOSE_FDS)
|
|
self.assertTrue(state.current_undervoltage)
|
|
self.assertFalse(state.current_overheat)
|
|
self.assertTrue(state.current_issue)
|
|
self.assertTrue(state.past_undervoltage)
|
|
self.assertTrue(state.past_overheat)
|
|
self.assertTrue(state.past_issue)
|
|
|
|
def test_get_vcgencmd_throttle_state_unparseable1(self):
|
|
from octoprint.plugins.pi_support import get_vcgencmd_throttled_state
|
|
|
|
with mock.patch("sarge.get_stdout", mock.MagicMock()) as m:
|
|
m.return_value = "invalid"
|
|
|
|
try:
|
|
get_vcgencmd_throttled_state(VCGENCMD)
|
|
except ValueError:
|
|
# expected
|
|
pass
|
|
else:
|
|
self.fail("Expected ValueError")
|
|
|
|
def test_get_vcgencmd_throttle_state_unparseable2(self):
|
|
from octoprint.plugins.pi_support import get_vcgencmd_throttled_state
|
|
|
|
with mock.patch("sarge.get_stdout", mock.MagicMock()) as m:
|
|
m.return_value = "throttled=0xinvalid"
|
|
|
|
try:
|
|
get_vcgencmd_throttled_state(VCGENCMD)
|
|
except ValueError:
|
|
# expected
|
|
pass
|
|
else:
|
|
self.fail("Expected ValueError")
|
|
|
|
|
|
@ddt.ddt
|
|
class ThrottleStateTestCase(unittest.TestCase):
|
|
@ddt.data(
|
|
(
|
|
0x00000,
|
|
{
|
|
"_undervoltage": False,
|
|
"_freq_capped": False,
|
|
"_throttled": False,
|
|
"_past_undervoltage": False,
|
|
"_past_freq_capped": False,
|
|
"_past_throttled": False,
|
|
"current_undervoltage": False,
|
|
"past_undervoltage": False,
|
|
"current_overheat": False,
|
|
"past_overheat": False,
|
|
"current_issue": False,
|
|
"past_issue": False,
|
|
},
|
|
),
|
|
(
|
|
0x50005,
|
|
{
|
|
"_undervoltage": True,
|
|
"_freq_capped": False,
|
|
"_throttled": True,
|
|
"_past_undervoltage": True,
|
|
"_past_freq_capped": False,
|
|
"_past_throttled": True,
|
|
"current_undervoltage": True,
|
|
"past_undervoltage": True,
|
|
"current_overheat": False,
|
|
"past_overheat": False,
|
|
"current_issue": True,
|
|
"past_issue": True,
|
|
},
|
|
),
|
|
(
|
|
0x50000,
|
|
{
|
|
"_undervoltage": False,
|
|
"_freq_capped": False,
|
|
"_throttled": False,
|
|
"_past_undervoltage": True,
|
|
"_past_freq_capped": False,
|
|
"_past_throttled": True,
|
|
"current_undervoltage": False,
|
|
"past_undervoltage": True,
|
|
"current_overheat": False,
|
|
"past_overheat": False,
|
|
"current_issue": False,
|
|
"past_issue": True,
|
|
},
|
|
),
|
|
(
|
|
0x00006,
|
|
{
|
|
"_undervoltage": False,
|
|
"_freq_capped": True,
|
|
"_throttled": True,
|
|
"_past_undervoltage": False,
|
|
"_past_freq_capped": False,
|
|
"_past_throttled": False,
|
|
"current_undervoltage": False,
|
|
"past_undervoltage": False,
|
|
"current_overheat": True,
|
|
"past_overheat": False,
|
|
"current_issue": True,
|
|
"past_issue": False,
|
|
},
|
|
),
|
|
)
|
|
@ddt.unpack
|
|
def test_conversion(self, input, expected_flags):
|
|
from octoprint.plugins.pi_support import ThrottleState
|
|
|
|
output = ThrottleState.from_value(input)
|
|
|
|
for key, value in expected_flags.items():
|
|
self.assertEqual(getattr(output, key), value)
|
|
|
|
def test_as_dict(self):
|
|
from octoprint.plugins.pi_support import ThrottleState
|
|
|
|
state = ThrottleState(
|
|
undervoltage=True,
|
|
throttled=True,
|
|
past_undervoltage=True,
|
|
past_freq_capped=True,
|
|
past_throttled=True,
|
|
)
|
|
|
|
self.assertDictEqual(
|
|
state.as_dict(),
|
|
{
|
|
"current_undervoltage": True,
|
|
"past_undervoltage": True,
|
|
"current_overheat": False,
|
|
"past_overheat": True,
|
|
"current_issue": True,
|
|
"past_issue": True,
|
|
"raw_value": -1,
|
|
},
|
|
)
|