Merge branch 'devel' into dev/commRefactoringNG

This commit is contained in:
Gina Häußge committed 2021-04-19 18:01:30 +02:00
commit d197fabffc
72 files changed
+4014 -3784

No files matched your search

Whitespace-only changes.
@@ -1 +0,0 @@
Raspberry Pi Zero W Rev 1.1
@@ -1 +0,0 @@
0.15.1
@@ -1 +0,0 @@
print("throttled=0x50005")
-185
View File
@@ -1,185 +0,0 @@
import unittest
import unittest.mock as mock
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("builtins.open", 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", 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
with mock.patch("builtins.open", 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", 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,
},
)
+23 -5
View File
@@ -13,6 +13,7 @@ class TimelapseRenderJobTest(unittest.TestCase):
@data(
(
(
'{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y {filters} "{output}"',
"/path/to/ffmpeg",
25,
"10000k",
@@ -22,10 +23,25 @@ class TimelapseRenderJobTest(unittest.TestCase):
"mpeg2video",
),
{},
'/path/to/ffmpeg -framerate 25 -i "/path/to/input/files_%d.jpg" -vcodec mpeg2video -threads 1 -r 25 -y -b 10000k -f vob -vf \'[in] format=yuv420p [out]\' "/path/to/output.mpg"',
'/path/to/ffmpeg -r 25 -i "/path/to/input/files_%d.jpg" -vcodec mpeg2video -threads 1 -b 10000k -f vob -y -vf \'[in] format=yuv420p [out]\' "/path/to/output.mpg"',
),
(
(
'{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y -g 5 {filters} "{output}"',
"/path/to/ffmpeg",
25,
"10000k",
1,
"/path/to/input/files_%d.jpg",
"/path/to/output.mpg",
"mpeg2video",
),
{},
'/path/to/ffmpeg -r 25 -i "/path/to/input/files_%d.jpg" -vcodec mpeg2video -threads 1 -b 10000k -f vob -y -g 5 -vf \'[in] format=yuv420p [out]\' "/path/to/output.mpg"',
),
(
(
'{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y {filters} "{output}"',
"/path/to/ffmpeg",
25,
"10000k",
@@ -35,10 +51,11 @@ class TimelapseRenderJobTest(unittest.TestCase):
"libx264",
),
{},
'/path/to/ffmpeg -framerate 25 -i "/path/to/input/files_%d.jpg" -vcodec libx264 -threads 1 -r 25 -y -b 10000k -f mp4 -vf \'[in] format=yuv420p [out]\' "/path/to/output.mp4"',
'/path/to/ffmpeg -r 25 -i "/path/to/input/files_%d.jpg" -vcodec libx264 -threads 1 -b 10000k -f mp4 -y -vf \'[in] format=yuv420p [out]\' "/path/to/output.mp4"',
),
(
(
'{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y {filters} "{output}"',
"/path/to/ffmpeg",
25,
"10000k",
@@ -48,10 +65,11 @@ class TimelapseRenderJobTest(unittest.TestCase):
"mpeg2video",
),
{"hflip": True},
'/path/to/ffmpeg -framerate 25 -i "/path/to/input/files_%d.jpg" -vcodec mpeg2video -threads 1 -r 25 -y -b 10000k -f vob -vf \'[in] format=yuv420p,hflip [out]\' "/path/to/output.mpg"',
'/path/to/ffmpeg -r 25 -i "/path/to/input/files_%d.jpg" -vcodec mpeg2video -threads 1 -b 10000k -f vob -y -vf \'[in] format=yuv420p,hflip [out]\' "/path/to/output.mpg"',
),
(
(
'{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y {filters} "{output}"',
"/path/to/ffmpeg",
25,
"20000k",
@@ -61,13 +79,13 @@ class TimelapseRenderJobTest(unittest.TestCase):
"mpeg2video",
),
{"rotate": True, "watermark": "/path/to/watermark.png"},
'/path/to/ffmpeg -framerate 25 -i "/path/to/input/files_%d.jpg" -vcodec mpeg2video -threads 4 -r 25 -y -b 20000k -f vob -vf \'[in] format=yuv420p,transpose=2 [postprocessed]; movie=/path/to/watermark.png [wm]; [postprocessed][wm] overlay=10:main_h-overlay_h-10 [out]\' "/path/to/output.mpg"',
'/path/to/ffmpeg -r 25 -i "/path/to/input/files_%d.jpg" -vcodec mpeg2video -threads 4 -b 20000k -f vob -y -vf \'[in] format=yuv420p,transpose=2 [postprocessed]; movie=/path/to/watermark.png [wm]; [postprocessed][wm] overlay=10:main_h-overlay_h-10 [out]\' "/path/to/output.mpg"',
),
)
@unpack
def test_create_ffmpeg_command_string(self, args, kwargs, expected):
actual = TimelapseRenderJob._create_ffmpeg_command_string(*args, **kwargs)
self.assertEqual(actual, expected)
self.assertEqual(expected, actual)
@data(
({}, "[in] format=yuv420p [out]"),