def test_cli_openexr(self): from tests.mock_responses import CoroMock filepath = Path(__file__).parent.as_posix() settings = { # Point blender_cmd to this file so that we're sure it exists. 'blender_cmd': f'{self.thisfile!r} --with --cli="args for CLI"', 'chunk_size': 100, 'frames': '1..2', 'format': 'OPEN_EXR', 'filepath': filepath, } cse = CoroMock(...) cse.coro.return_value.wait = CoroMock(return_value=0) cse.coro.return_value.pid = 47 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( self.thisfile, '--with', '--cli=args for CLI', '--enable-autoexec', '-noaudio', '--background', filepath, '--render-format', 'EXR', # see https://developer.blender.org/D4502 '--render-frame', '1..2', stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, )
def test_cli_args(self): """Test that CLI arguments in the blender_cmd setting are handled properly.""" from tests.mock_responses import CoroMock filepath = Path(__file__).parent.as_posix() settings = { # Point blender_cmd to this file so that we're sure it exists. 'blender_cmd': f'{self.thisfile!r} --with --cli="args for CLI"', 'chunk_size': 100, 'frames': '1..2', 'format': 'JPEG', 'filepath': filepath, } cse = CoroMock(...) cse.coro.return_value.wait = CoroMock(return_value=0) cse.coro.return_value.pid = 47 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( self.thisfile, '--with', '--cli=args for CLI', '--enable-autoexec', '-noaudio', '--background', filepath, '--render-format', 'JPEG', '--render-frame', '1..2', stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=mock.ANY, )
def test_exr_directory(self): from tests.mock_responses import CoroMock filepath = Path(__file__).parent.as_posix() settings = { # Point blender_cmd to this file so that we're sure it exists. 'blender_cmd': f'{self.thisfile!r} --with --cli="args for CLI"', 'filepath': filepath, 'exr_directory': '/some/path/to/exr', 'output_pattern': 'preview-######', } cse = CoroMock(...) cse.coro.return_value.wait = CoroMock(return_value=0) cse.coro.return_value.pid = 47 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( self.thisfile, '--with', '--cli=args for CLI', '--enable-autoexec', '-noaudio', '--background', filepath, '--python-exit-code', '32', '--python', str(self.cmd.pyscript), '--', '--exr-glob', '/some/path/to/exr/*.exr', '--output-pattern', 'preview-######', stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, )
def test_cli_args_override_file(self): """Test that an override file next to the blend file is recognised.""" from tests.mock_responses import CoroMock with tempfile.TemporaryDirectory() as tempdir: temppath = Path(tempdir) blendpath = temppath / 'thefile.blend' blendpath.touch() override = temppath / 'thefile-overrides.py' override.touch() settings = { # Point blender_cmd to this file so that we're sure it exists. 'blender_cmd': self.thisfile, 'chunk_size': 100, 'frames': '1..2', 'format': 'JPEG', 'filepath': blendpath.as_posix(), } cse = CoroMock(...) cse.coro.return_value.wait = CoroMock(return_value=0) cse.coro.return_value.pid = 47 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( self.thisfile, '--enable-autoexec', '-noaudio', '--background', blendpath.as_posix(), '--python-exit-code', '42', '--python', override.as_posix(), '--render-format', 'JPEG', '--render-frame', '1..2', stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, )
def test_cli_environment(self): """Test that LD_LIBRARY_PATH is removed from the environment.""" from tests.mock_responses import CoroMock filepath = Path(__file__).parent.as_posix() settings = { # Point blender_cmd to this file so that we're sure it exists. 'blender_cmd': f'{self.thisfile!r} --with --cli="args for CLI"', 'chunk_size': 100, 'frames': '1..2', 'format': 'JPEG', 'filepath': filepath, } cse = CoroMock(...) cse.coro.return_value.wait = CoroMock(return_value=0) cse.coro.return_value.pid = 47 mock_env = { 'PATH': '/path/a:/path/b', 'LD_LIBRARY_PATH': '/path/to/conflicting/libraries', } with patch('asyncio.create_subprocess_exec', new=cse) as mock_cse, \ patch('os.environ', new=mock_env): self.loop.run_until_complete(self.cmd.run(settings)) mock_cse.assert_called_once_with( self.thisfile, '--with', '--cli=args for CLI', '--enable-autoexec', '-noaudio', '--background', filepath, '--render-format', 'JPEG', '--render-frame', '1..2', stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env={ 'PATH': '/path/a:/path/b', }, )
def write_check(self, post_run=None): from tests.mock_responses import EmptyResponse, CoroMock self.manager.post = CoroMock(return_value=EmptyResponse()) with tempfile.TemporaryDirectory() as tdir_name: tdir = Path(tdir_name) yield tdir self.worker.schedule_fetch_task() self.asyncio_loop.run_until_complete( self.worker.single_iteration_fut) if post_run is not None: post_run() self.manager.post.assert_called_once_with('/ack-status-change/error', loop=self.asyncio_loop) self.assertFalse(self.worker.sleeping_fut.done())
def test_happy_remove_file(self): from tests.mock_responses import EmptyResponse, CoroMock self.manager.post = CoroMock(return_value=EmptyResponse()) with tempfile.TemporaryDirectory() as tdir_name: tdir = Path(tdir_name) testfile = tdir / 'writable-testfile.txt' self.worker.pretask_check_params.pre_task_check_write = ( testfile, ) self.worker.schedule_fetch_task() self.asyncio_loop.run_until_complete( self.worker.single_iteration_fut) self.assertFalse(testfile.exists(), '%s should have been deleted' % testfile) self.manager.post.assert_called_once_with('/task', loop=self.asyncio_loop) self.assertIsNone(self.worker.sleeping_fut)
def setUp(self): from flamenco_worker.upstream import FlamencoManager from flamenco_worker.upstream_update_queue import TaskUpdateQueue from flamenco_worker.cli import construct_asyncio_loop from tests.mock_responses import CoroMock logging.getLogger('flamenco_worker.upstream_update_queue').setLevel( logging.DEBUG) self.asyncio_loop = construct_asyncio_loop() self.shutdown_future = self.asyncio_loop.create_future() self.manager = Mock(spec=FlamencoManager) self.manager.post = CoroMock() self.tmpdir = tempfile.TemporaryDirectory() self.tuqueue = TaskUpdateQueue( db_fname='%s/unittest.db' % self.tmpdir.name, manager=self.manager, shutdown_future=self.shutdown_future, backoff_time=0.3, # faster retry to keep the unittest speedy. )