Skip to content

Commit

Permalink
Add unit tests for translate module
Browse files Browse the repository at this point in the history
  • Loading branch information
amolenaar committed Nov 26, 2019
1 parent 0039cb0 commit 90f6f02
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
BabelGladeExtractor.egg-info/
__pycache__/
test.appdata.xml
test.desktop
20 changes: 20 additions & 0 deletions babelglade/tests/locale/fr/LC_MESSAGES/test.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
msgid ""
msgstr ""
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid "This should be translated."
msgstr "Cela devrait être traduit."

msgid ""
"\n"
" Multi line\n"
" text.\n"
" "
msgstr ""
"\n"
" Texte\n"
" multi-ligne.\n"
" "
20 changes: 20 additions & 0 deletions babelglade/tests/locale/nl/LC_MESSAGES/test.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
msgid ""
msgstr ""
"Language: nl\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid "This should be translated."
msgstr "Dit moet worden vertaald."

msgid ""
"\n"
" Multi line\n"
" text.\n"
" "
msgstr ""
"\n"
" Meerregelige\n"
" tekst.\n"
" "
13 changes: 13 additions & 0 deletions babelglade/tests/test.raw.appdata.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2019 Tobias Mueller <[email protected]> -->
<component type="desktop">
<id>babelglade.test</id>

<description>
<p translatable="yes">This should be translated.</p>
<p translatable="yes">
Multi line
text.
</p>
</description>
</component>
9 changes: 9 additions & 0 deletions babelglade/tests/test.raw.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Desktop Entry]
Name=Keysign
Comment=This should be translated.
Keywords=python;gpg;gnupg;key;openpgp;
Type=Application
Exec=python3 -m keysign
Icon=org.gnome.Keysign
Categories=GTK;GNOME;Utility;
StartupNotify=true
39 changes: 39 additions & 0 deletions babelglade/tests/test_translate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

import os
from babelglade.translate import translate_desktop_file, translate_appdata_file

def relative(test_file):
return os.path.join(os.path.dirname(__file__), test_file)


def test_desktop_file():
translate_desktop_file(relative("test.raw.desktop"), "test.desktop", relative("locale"))

with open("test.desktop") as desktop:
content = desktop.read()

assert "Comment=This should be translated." in content
assert "Comment[nl]=Dit moet worden vertaald." in content
assert "Comment[fr]=Cela devrait être traduit." in content

def test_appdata_xml():
translate_appdata_file(relative("test.raw.appdata.xml"), "test.appdata.xml", relative("locale"))

with open("test.appdata.xml") as desktop:
content = desktop.read()

assert "<p>This should be translated.</p>" in content
assert '<p xml:lang="fr">Cela devrait être traduit.</p>' in content
assert '<p xml:lang="nl">Dit moet worden vertaald.</p>' in content
assert """<p>
Multi line
text.
</p>""" in content
assert """<p xml:lang="fr">
Texte
multi-ligne.
</p>""" in content
assert """<p xml:lang="nl">
Meerregelige
tekst.
</p>""" in content

0 comments on commit 90f6f02

Please sign in to comment.