def test_setup_assets_remote_icon(self, desktop_file, yaml_data, new_dir): # create primed tree (no icon) desktop_file("prime/test.desktop") # define project # pylint: disable=line-too-long project = Project.unmarshal( yaml_data( { "adopt-info": "part", "icon": "https://dashboard.snapcraft.io/site_media/appmedia/2018/04/Snapcraft-logo-bird.png", "apps": { "app1": { "command": "test.sh", "common-id": "my-test", "desktop": "test.desktop", }, }, }, )) # pylint: enable=line-too-long setup_assets( project, assets_dir=Path("snap"), project_dir=Path.cwd(), prime_dir=Path("prime"), ) # desktop file should be in meta/gui and named after app desktop_path = Path("prime/meta/gui/app1.desktop") assert desktop_path.is_file() # desktop file content should make icon relative to ${SNAP} content = desktop_path.read_text() assert content == textwrap.dedent("""\ [Desktop Entry] Name=appstream-desktop Exec=test-project.app1 Type=Application Icon=${SNAP}/meta/gui/icon.png """) # icon was downloaded icon_path = Path("prime/meta/gui/icon.png") assert icon_path.is_file() assert icon_path.stat().st_size > 0
def test_setup_assets_no_apps(self, desktop_file, yaml_data, new_dir): desktop_file("prime/test.desktop") Path("prime/usr/share/icons").mkdir(parents=True) Path("prime/usr/share/icons/icon.svg").touch() Path("snap/gui").mkdir() # define project project = Project.unmarshal(yaml_data({"adopt-info": "part"})) # setting up assets does not crash setup_assets( project, assets_dir=Path("snap"), project_dir=Path.cwd(), prime_dir=Path("prime"), ) assert os.listdir("prime/meta/gui") == []
def test_gadget_missing(yaml_data, new_dir): project = Project.unmarshal( yaml_data({ "type": "gadget", "version": "1.0", "summary": "summary", "description": "description", })) with pytest.raises(errors.SnapcraftError) as raised: setup_assets( project, assets_dir=Path("snap"), project_dir=Path.cwd(), prime_dir=Path("prime"), ) assert str(raised.value) == "gadget.yaml is required for gadget snaps"
def test_setup_assets_icon_in_assets_dir(self, desktop_file, yaml_data, new_dir): desktop_file("prime/test.desktop") Path("snap/gui").mkdir(parents=True) Path("snap/gui/icon.svg").touch() # define project project = Project.unmarshal( yaml_data( { "adopt-info": "part", "apps": { "app1": { "command": "test.sh", "common-id": "my-test", "desktop": "test.desktop", }, }, }, )) setup_assets( project, assets_dir=Path("snap"), project_dir=Path.cwd(), prime_dir=Path("prime"), ) # desktop file should be in meta/gui and named after app desktop_path = Path("prime/meta/gui/app1.desktop") assert desktop_path.is_file() # desktop file content should make icon relative to ${SNAP} content = desktop_path.read_text() assert content == textwrap.dedent("""\ [Desktop Entry] Name=appstream-desktop Exec=test-project.app1 Type=Application Icon=${SNAP}/snap/gui/icon.svg """) # icon file exists Path("prime/snap/gui/icon.svg").is_file()
def test_gadget(yaml_data, gadget_yaml_file, new_dir): project = Project.unmarshal( yaml_data({ "type": "gadget", "version": "1.0", "summary": "summary", "description": "description", })) setup_assets( project, assets_dir=Path("snap"), project_dir=Path.cwd(), prime_dir=Path("prime"), ) # gadget file should be in meta/ gadget_path = Path("prime/meta/gadget.yaml") assert gadget_path.is_file()
def test_kernel_missing(yaml_data, new_dir): project = Project.unmarshal({ "name": "custom-kernel", "type": "kernel", "confinement": "strict", "version": "1.0", "summary": "summary", "description": "description", "parts": {}, }) setup_assets( project, assets_dir=Path("snap"), project_dir=Path.cwd(), prime_dir=Path("prime"), ) # kernel file should not be in meta/ kernel_path = Path("prime/meta/kernel.yaml") assert not kernel_path.is_file()
def test_setup_assets_hook_command_chain_error(self, yaml_data, new_dir): # define project project = Project.unmarshal( yaml_data( { "adopt-info": "part1", "hooks": { "hook1": { "command-chain": ["does-not-exist"] }, }, }, )) with pytest.raises(errors.SnapcraftError) as raised: setup_assets( project, assets_dir=Path("snap"), project_dir=Path.cwd(), prime_dir=new_dir, ) assert str(raised.value) == ( "Failed to generate snap metadata: The command-chain item 'does-not-exist' " "defined in hook 'hook1' does not exist or is not executable.")