def test_appstream_parse_os_error(self): file_name = "snapcraft_legacy.appdata.xml" assert not Path(file_name).is_file() error = "Error reading file './snapcraft_legacy.appdata.xml': failed to load" with pytest.raises(errors.SnapcraftError, match=error): appstream.extract(file_name, workdir=".")
def test_appstream_parse_error(self): file_name = "snapcraft_legacy.appdata.xml" content = textwrap.dedent("""\ <?xml version="1.0" encoding="utf-8"?> <component type="desktop"> <id>io.snapcraft.snapcraft</id> <metadata_license>CC0-1.0</metadata_license> <project_license>GPL-3.0</project_license> <name>snapcraft</name> <summary>Create snaps</summary> <description> <p>Command Line Utility to create snaps.</p> </description> <provides> <binary>snapcraft</binary> </component> """) Path(file_name).write_text(content) with pytest.raises(errors.MetadataExtractionError) as raised: appstream.extract(file_name, workdir=".") assert str(raised.value) == ( "Error extracting metadata from './snapcraft_legacy.appdata.xml': " "Opening and ending tag mismatch: provides line 11 and component, " "line 13, column 13 (snapcraft_legacy.appdata.xml, line 13)")
def test_appstream_with_multiple_launchables(self): Path("foo.metainfo.xml").write_text( textwrap.dedent("""\ <?xml version="1.0" encoding="UTF-8"?> <component> <launchable type="desktop-id"> com.example.test-app1.desktop </launchable> <launchable type="test-wrong-type"> dummy </launchable> <launchable type="desktop-id"> com.example.test-app2.desktop </launchable> <launchable type="desktop-id"> unexisting </launchable> </component>""")) _create_desktop_file( "usr/local/share/applications/com.example.test/app1.desktop") _create_desktop_file( "usr/local/share/applications/com.example.test/app2.desktop") expected = [ "usr/local/share/applications/com.example.test/app1.desktop", "usr/local/share/applications/com.example.test/app2.desktop", ] extracted = appstream.extract("foo.metainfo.xml", workdir=".") assert extracted is not None assert extracted.desktop_file_paths == expected
def test_appstream_with_comments(self): file_name = "foo.appdata.xml" content = textwrap.dedent("""\ <?xml version="1.0" encoding="UTF-8"?> <component type="desktop"> <id>com.github.maoschanz.drawing</id> <metadata_license>CC0-1.0</metadata_license> <project_license>GPL-3.0-or-later</project_license> <content_rating type="oars-1.1"/> <!-- TRANSLATORS: the application name --> <name>Drawing</name> <!-- TRANSLATORS: one-line description for the app --> <summary>Draw stuff</summary> <description> <!-- TRANSLATORS: AppData description marketing paragraph --> <p>Command Line Utility to create snaps quickly.</p> <p xml:lang="es">Aplicativo de línea de comandos para crear snaps.</p> <p>Ordered Features:</p> <p xml:lang="es">Funciones:</p> <ol> <li>Build snaps.</li> <li xml:lang="es">Construye snaps.</li> <li>Publish snaps to the store.</li> <li xml:lang="es">Publica snaps en la tienda.</li> </ol> <p>Unordered Features:</p> <ul> <li>Build snaps.</li> <li xml:lang="es">Construye snaps.</li> <li>Publish snaps to the store.</li> <li xml:lang="es">Publica snaps en la tienda.</li> </ul> </description> </component> """) Path(file_name).write_text(content) metadata = appstream.extract(file_name, workdir=".") assert metadata is not None assert metadata.description == textwrap.dedent("""\ Command Line Utility to create snaps quickly. Ordered Features: 1. Build snaps. 2. Publish snaps to the store. Unordered Features: - Build snaps. - Publish snaps to the store.""")
def test_appstream_no_desktop_suffix(self, desktop_file_path): Path("foo.metainfo.xml").write_text( textwrap.dedent("""\ <?xml version="1.0" encoding="UTF-8"?> <component type="desktop"> <id>com.example.test-app</id> </component>""")) _create_desktop_file(desktop_file_path) extracted = appstream.extract("foo.metainfo.xml", workdir=".") assert extracted is not None assert extracted.desktop_file_paths == [desktop_file_path]
def test_appstream_em(self): file_name = "foliate.appdata.xml" content = textwrap.dedent("""\ <?xml version="1.0" encoding="UTF-8"?> <component type="desktop"> <id>com.github.maoschanz.drawing</id> <metadata_license>CC0-1.0</metadata_license> <project_license>GPL-3.0-or-later</project_license> <content_rating type="oars-1.1"/> <name>Drawing</name> <description> <p>Command Line Utility to <em>create snaps</em> quickly.</p> <p xml:lang="es">Aplicativo de línea de comandos para crear snaps.</p> <p>Ordered Features:</p> <p xml:lang="es">Funciones:</p> <ol> <li><em>Build snaps</em>.</li> <li xml:lang="es">Construye snaps.</li> <li>Publish snaps to the store.</li> <li xml:lang="es">Publica snaps en la tienda.</li> </ol> <p>Unordered Features:</p> <ul> <li><em>Build snaps</em>.</li> <li xml:lang="es">Construye snaps.</li> <li>Publish snaps to the store.</li> <li xml:lang="es">Publica snaps en la tienda.</li> </ul> </description> </component> """) Path(file_name).write_text(content) metadata = appstream.extract(file_name, workdir=".") assert metadata is not None assert metadata.description == textwrap.dedent("""\ Command Line Utility to _create snaps_ quickly. Ordered Features: 1. _Build snaps_. 2. Publish snaps to the store. Unordered Features: - _Build snaps_. - Publish snaps to the store.""")
def test_entries(self, file_extension, key, attributes, param_name, value, expect): file_name = f"foo.{file_extension}" attrs = " ".join(f'{attr}="{attributes[attr]}"' for attr in attributes) Path(file_name).write_text( textwrap.dedent(f"""\ <?xml version="1.0" encoding="UTF-8"?> <component> <{key} {attrs}>{value}</{key}> </component>""")) Path("icon.png").touch() kwargs = {param_name: expect} expected = ExtractedMetadata(**kwargs) assert appstream.extract(file_name, workdir=".") == expected
def test_appstream_release(self): file_name = "foliate.appdata.xml" # pylint: disable=line-too-long content = textwrap.dedent("""\ <?xml version="1.0" encoding="UTF-8"?> <component type="desktop"> <releases> <release version="1.5.3" date="2019-07-25"> <description> <ul> <li>Fixed Flatpak version not being able to open .mobi, .azw, and .azw3 files</li> <li>Improved Wiktionary lookup, now with links and example sentences</li> <li>Improved popover footnote extraction and formatting</li> <li>Added option to export annotations to BibTeX</li> </ul> </description> </release> <release version="1.5.2" date="2019-07-19"> <description> <ul> <li>Fixed table of contents navigation not working with some books</li> <li>Fixed not being able to zoom images with Kindle books</li> <li>Fixed not being able to open books with .epub3 filename extension</li> <li>Fixed temporary directory not being cleaned after closing</li> </ul> </description> </release> <release version="1.5.1" date="2019-07-17"> <description> <ul> <li>Fixed F9 shortcut not working</li> <li>Updated translations</li> </ul> </description> </release> </releases> </component> """) # pylint: enable=line-too-long Path(file_name).write_text(content) metadata = appstream.extract(file_name, workdir=".") assert metadata is not None assert metadata.version == "1.5.3"
def test_appstream_with_ol(self): file_name = "snapcraft_legacy.appdata.xml" content = textwrap.dedent("""\ <?xml version="1.0" encoding="utf-8"?> <component type="desktop"> <id>io.snapcraft.snapcraft</id> <metadata_license>CC0-1.0</metadata_license> <project_license>GPL-3.0</project_license> <name>snapcraft</name> <name xml:lang="es">snapcraft</name> <summary>Create snaps</summary> <summary xml:lang="es">Crea snaps</summary> <description> <p>Command Line Utility to create snaps.</p> <p xml:lang="es">Aplicativo de línea de comandos para crear snaps.</p> <p>Features:</p> <p xml:lang="es">Funciones:</p> <ol> <li>Build snaps.</li> <li xml:lang="es">Construye snaps.</li> <li>Publish snaps to the store.</li> <li xml:lang="es">Publica snaps en la tienda.</li> </ol> </description> <provides> <binary>snapcraft</binary> </provides> </component> """) Path(file_name).write_text(content) metadata = appstream.extract(file_name, workdir=".") assert metadata is not None assert metadata.summary == "Create snaps" assert metadata.description == textwrap.dedent("""\ Command Line Utility to create snaps. Features: 1. Build snaps. 2. Publish snaps to the store.""")
def test_appstream_multilang_title(self): file_name = "foliate.appdata.xml" content = textwrap.dedent("""\ <?xml version="1.0" encoding="UTF-8"?> <component type="desktop"> <name>Foliate</name> <name xml:lang="id_ID">Foliate_id</name> <name xml:lang="pt_BR">Foliate_pt</name> <name xml:lang="ru_RU">Foliate_ru</name> <name xml:lang="nl_NL">Foliate_nl</name> <name xml:lang="fr_FR">Foliate_fr</name> <name xml:lang="cs_CS">Foliate_cs</name> </component> """) Path(file_name).write_text(content) metadata = appstream.extract(file_name, workdir=".") assert metadata is not None assert metadata.title == "Foliate"
def test_unhandled_file_test_case(self): assert appstream.extract("unhandled-file", workdir=".") is None
def test_appstream_with_ul_in_p(self): file_name = "snapcraft_legacy.appdata.xml" # pylint: disable=line-too-long content = textwrap.dedent("""\ <?xml version="1.0" encoding="UTF-8"?> <component type="desktop"> <id>com.github.maoschanz.drawing</id> <metadata_license>CC0-1.0</metadata_license> <project_license>GPL-3.0-or-later</project_license> <content_rating type="oars-1.1"/> <name>Drawing</name> <name xml:lang="tr">Çizim</name> <name xml:lang="pt_BR">Drawing</name> <summary>A drawing application for the GNOME desktop</summary> <summary xml:lang="pt_BR">Uma aplicacao de desenho para o ambiente GNOME</summary> <summary xml:lang="nl">Een tekenprogramma voor de GNOME-werkomgeving</summary> <description> <p>"Drawing" is a basic image editor, supporting PNG, JPEG and BMP file types.</p> <p xml:lang="pt_BR">"Drawing" e um simples editor de imagens, que suporta arquivos PNG,JPEG e BMP</p> <p xml:lang="nl">"Tekenen" is een eenvoudige afbeeldingsbewerker, met ondersteuning voor PNG, JPEG en BMP.</p> <p xml:lang="fr">"Dessin" est un éditeur d'images basique, qui supporte les fichiers de type PNG, JPEG ou BMP.</p> <p>It allows you to draw or edit pictures with tools such as: <ul> <li>Pencil (with various options)</li> <li xml:lang="pt_BR">Lápis (Com varias opções)</li> <li xml:lang="nl">Potlood (verschillende soorten)</li> <li xml:lang="fr">Crayon (avec diverses options)</li> <li>Selection (cut/copy/paste/drag/…)</li> <li xml:lang="tr">Seçim (kes/kopyala/yapıştır/sürükle /…)</li> <li xml:lang="ru">Выделение (вырезать/копировать/вставить/перетащить/…)</li> <li xml:lang="pt_BR">Seleção (cortar/copiar/colar/arrastar/…)</li> <li xml:lang="nl">Selectie (knippen/kopiëren/plakken/verslepen/...)</li> <li xml:lang="it">Selezione (taglia/copia/incolla/trascina/…)</li> <li xml:lang="he">בחירה (חתיכה/העתקה/הדבקה/גרירה/...)</li> <li xml:lang="fr">Sélection (copier/coller/déplacer/…)</li> <li xml:lang="es">Selección (cortar/copiar/pegar/arrastrar/…)</li> <li xml:lang="de_DE">Auswahl (Ausschneiden/Kopieren/Einfügen/Ziehen/...)</li> <li>Line, Arc (with various options)</li> <li xml:lang="pt_BR">Linha, Arco (com varias opcoes)</li> <li xml:lang="nl">Lijn, Boog (verschillende soorten)</li> <li xml:lang="fr">Trait, Arc (avec diverses options)</li> <li>Shapes (rectangle, circle, polygon, …)</li> <li xml:lang="pt_BR">Formas (retângulo, circulo, polígono, …)</li> <li xml:lang="nl">Vormen (vierkant, cirkel, veelhoek, ...)</li> <li xml:lang="fr">Formes (rectangle, cercle, polygone, …)</li> <li>Text insertion</li> <li xml:lang="pt_BR">Inserção de texto</li> <li xml:lang="nl">Tekst invoeren</li> <li xml:lang="fr">Insertion de texte</li> <li>Resizing, cropping, rotating</li> <li xml:lang="pt_BR">Redimencionar, cortar, rotacionar</li> <li xml:lang="nl">Afmetingen wijzigen, bijsnijden, draaien</li> <li xml:lang="fr">Redimensionnement, rognage, rotation</li> </ul> </p> </description> </component> """) # pylint: enable=line-too-long Path(file_name).write_text(content) metadata = appstream.extract(file_name, workdir=".") assert metadata is not None assert metadata.summary == "A drawing application for the GNOME desktop" assert metadata.description == textwrap.dedent("""\ "Drawing" is a basic image editor, supporting PNG, JPEG and BMP file types. It allows you to draw or edit pictures with tools such as: - Pencil (with various options) - Selection (cut/copy/paste/drag/…) - Line, Arc (with various options) - Shapes (rectangle, circle, polygon, …) - Text insertion - Resizing, cropping, rotating""")
def _expect_icon(self, icon): expected = ExtractedMetadata(icon=icon) actual = appstream.extract("foo.appdata.xml", workdir=".") assert actual is not None assert actual.icon == expected.icon