def test_verify_non_linux_no_docker(tmp_path): """If Docker is disabled on non-Linux, an error is raised.""" command = LinuxAppImageCreateCommand(base_path=tmp_path) command.host_os = "WeirdOS" command.use_docker = False # Verify the tools with pytest.raises(BriefcaseCommandError): command.verify_tools()
def test_verify_windows_docker(tmp_path): """Docker cannot currently be used on Windows due to path issues.""" command = LinuxAppImageCreateCommand(base_path=tmp_path) command.host_os = "Windows" command.use_docker = True # Verify the tools with pytest.raises(BriefcaseCommandError): command.verify_tools()
def test_verify_linux_no_docker(tmp_path): """If Docker is disabled on Linux, the Docker alias is not set.""" command = LinuxAppImageCreateCommand(base_path=tmp_path) command.host_os = "Linux" command.use_docker = False # Verify the tools command.verify_tools() # No error, but no Docker wrapper either. assert command.Docker is None
def test_dockerize(first_app_config, tmp_path): command = LinuxAppImageCreateCommand(base_path=tmp_path) command.Docker = Docker command.use_docker = True # Before dockerization, subprocess is native assert type(command.subprocess) == Subprocess with command.dockerize(first_app_config): # During dockerization, subprocess is a container assert type(command.subprocess) == Docker # After dockerization, subprocess is native assert type(command.subprocess) == Subprocess
def test_dockerize_nodocker(first_app_config, tmp_path): """If docker is not in use, dockerize() is a no-op.""" command = LinuxAppImageCreateCommand(base_path=tmp_path) command.Docker = Docker command.use_docker = False # Before dockerization, subprocess is native assert type(command.subprocess) == Subprocess with command.dockerize(first_app_config): # During dockerization, subprocess is *still* native assert type(command.subprocess) == Subprocess # After dockerization, subprocess is native assert type(command.subprocess) == Subprocess
def test_verify_linux_docker(tmp_path): "If Docker is enabled on Linux, the Docker alias is set" command = LinuxAppImageCreateCommand(base_path=tmp_path) command.host_os = "Linux" command.use_docker = True command.verbosity = 0 # Mock the existence of Docker. command.subprocess = MagicMock() command.subprocess.check_output.return_value = "Docker version 19.03.8, build afacb8b\n" # Verify the tools command.verify_tools() # The Docker wrapper is set. assert command.Docker == Docker
def test_install_app_dependencies_no_docker(first_app_config, tmp_path): "If docker is *not* in use, calls are made on raw subprocess" first_app_config.requires = ['foo==1.2.3', 'bar>=4.5'] command = LinuxAppImageCreateCommand(base_path=tmp_path) command.use_docker = False command.subprocess = MagicMock() docker = MagicMock() command.Docker = MagicMock() command.Docker.return_value = docker command._path_index = { first_app_config: { 'app_packages_path': 'path/to/app_packages' } } command.install_app_dependencies(first_app_config) # A docker context was not created, nor was it prepared assert command.Docker.call_count == 0 assert docker.prepare.call_count == 0 # The no-op prepare call was made. command.subprocess.prepare.assert_called_with() # pip was invoked natively command.subprocess.run.assert_called_with([ sys.executable, '-m', 'pip', 'install', '--upgrade', '--no-user', '--target={tmp_path}/linux/First App/path/to/app_packages'.format( tmp_path=tmp_path), 'foo==1.2.3', 'bar>=4.5', ], check=True)
def test_install_app_dependencies(first_app_config, tmp_path): "If Docker is in use, a docker context is used to invoke pip" first_app_config.requires = ['foo==1.2.3', 'bar>=4.5'] command = LinuxAppImageCreateCommand(base_path=tmp_path) command.use_docker = True command.subprocess = MagicMock() docker = MagicMock() command.Docker = MagicMock() command.Docker.return_value = docker command._path_index = { first_app_config: { 'app_packages_path': 'path/to/app_packages' } } command.install_app_dependencies(first_app_config) # A docker context was created command.Docker.assert_called_with(command, first_app_config) # The docker container was prepared docker.prepare.assert_called_with() # pip was invoked inside docker. docker.run.assert_called_with([ sys.executable, '-m', 'pip', 'install', '--upgrade', '--no-user', '--target={tmp_path}/linux/First App/path/to/app_packages'.format( tmp_path=tmp_path), 'foo==1.2.3', 'bar>=4.5', ], check=True)
def test_install_app_dependencies_no_docker(first_app_config, tmp_path): """If docker is *not* in use, calls are made on raw subprocess.""" first_app_config.requires = ["foo==1.2.3", "bar>=4.5"] command = LinuxAppImageCreateCommand(base_path=tmp_path) command.use_docker = False command.subprocess = MagicMock() docker = MagicMock() command.Docker = MagicMock() command.Docker.return_value = docker command._path_index = { first_app_config: {"app_packages_path": "path/to/app_packages"} } command.install_app_dependencies(first_app_config) # A docker context was not created, nor was it prepared assert command.Docker.call_count == 0 assert docker.prepare.call_count == 0 # The no-op prepare call was made. command.subprocess.prepare.assert_called_with() # pip was invoked natively command.subprocess.run.assert_called_with( [ sys.executable, "-m", "pip", "install", "--upgrade", "--no-user", f"--target={tmp_path}/linux/appimage/First App/path/to/app_packages", "foo==1.2.3", "bar>=4.5", ], check=True, )
def test_install_app_dependencies(first_app_config, tmp_path): """If Docker is in use, a docker context is used to invoke pip.""" first_app_config.requires = ["foo==1.2.3", "bar>=4.5"] command = LinuxAppImageCreateCommand(base_path=tmp_path) command.use_docker = True command.subprocess = MagicMock() docker = MagicMock() command.Docker = MagicMock() command.Docker.return_value = docker command._path_index = { first_app_config: {"app_packages_path": "path/to/app_packages"} } command.install_app_dependencies(first_app_config) # A docker context was created command.Docker.assert_called_with(command, first_app_config) # The docker container was prepared docker.prepare.assert_called_with() # pip was invoked inside docker. docker.run.assert_called_with( [ sys.executable, "-m", "pip", "install", "--upgrade", "--no-user", f"--target={tmp_path}/linux/appimage/First App/path/to/app_packages", "foo==1.2.3", "bar>=4.5", ], check=True, )