Newer
Older
from unittest.mock import patch, call
from test_runner import AbstractCommandTest
class BlenderRenderTest(AbstractCommandTest):
def setUp(self):
super().setUp()
from flamenco_worker.commands import BlenderRenderCommand
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
self.cmd = BlenderRenderCommand(
worker=self.fworker,
task_id='12345',
command_idx=0,
)
def test_re_time(self):
line = '| Time:00:04.17 |'
m = self.cmd.re_time.search(line)
self.assertEqual(m.groupdict(), {
'hours': None,
'minutes': '00',
'seconds': '04',
'hunds': '17',
})
def test_parse_render_line(self):
line = 'Fra:10 Mem:17.52M (0.00M, Peak 33.47M) | Time:00:04.17 | Remaining:00:00.87 | ' \
'Mem:1.42M, Peak:1.42M | Scene, RenderLayer | Path Tracing Tile 110/135'
self.assertEqual(
self.cmd.parse_render_line(line),
{'fra': 10,
'mem': '17.52M',
'peakmem': '33.47M',
'time_sec': 4.17,
'remaining_sec': 0.87,
'status': 'Path Tracing Tile 110/135',
}
)
line = 'Fra:003 Mem:17.52G (0.00M, Peak 33G) | Time:03:00:04.17 | Remaining:44:00:00.87 | ' \
'Mem:1.42M, Peak:1.42M | Séance, RenderLëør | Computing cosmic flöw 110/13005'
self.assertEqual(
self.cmd.parse_render_line(line),
{'fra': 3,
'mem': '17.52G',
'peakmem': '33G',
'time_sec': 3 * 3600 + 4.17,
'remaining_sec': 44 * 3600 + 0.87,
'status': 'Computing cosmic flöw 110/13005',
}
)
def test_missing_files(self):
Sybren A. Stüvel
committed
"""Missing files should not abort the render."""
line = 'Warning: Unable to open je moeder'
Sybren A. Stüvel
committed
self.loop.run_until_complete(self.cmd.process_line(line))
self.fworker.register_task_update.assert_called_once_with(activity=line)
self.fworker.register_task_update.reset_mock()
Sybren A. Stüvel
committed
line = "Warning: Path 'je moeder' not found"
self.loop.run_until_complete(self.cmd.process_line(line))
self.fworker.register_task_update.assert_called_once_with(activity=line)
Sybren A. Stüvel
committed
def test_cli_args(self):
"""Test that CLI arguments in the blender_cmd setting are handled properly."""
Sybren A. Stüvel
committed
from pathlib import Path
import subprocess
from mock_responses import CoroMock
Sybren A. Stüvel
committed
filepath = str(Path(__file__).parent)
settings = {
Sybren A. Stüvel
committed
# Point blender_cmd to this file so that we're sure it exists.
'blender_cmd': '%s --with --cli="args for CLI"' % __file__,
'chunk_size': 100,
'frames': '1..2',
'format': 'JPEG',
Sybren A. Stüvel
committed
'filepath': filepath,
cse.coro.return_value.wait = CoroMock(return_value=0)
with patch('asyncio.create_subprocess_exec', new=cse) as mock_cse:
self.loop.run_until_complete(self.cmd.run(settings))
mock_cse.assert_called_once_with(
Sybren A. Stüvel
committed
__file__,
'--with',
'--cli=args for CLI',
Sybren A. Stüvel
committed
'--factory-startup',
'--enable-autoexec',
'-noaudio',
'--background',
Sybren A. Stüvel
committed
filepath,
'--render-format', 'JPEG',
'--render-frame', '1..2',
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)