Skip to content

Commit

Permalink
Merged distribution of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
muelli authored Nov 29, 2019
2 parents 6ac8ab8 + d451aa3 commit 4c66c77
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
5 changes: 3 additions & 2 deletions babelglade/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
import unittest

def suite():
from babelglade.tests import test_extract
from babelglade.tests import test_extract, test_translate
suite = unittest.TestSuite()
suite.addTest(test_extract.suite())
suite.addTest(unittest.makeSuite(test_extract.GladeExtractTests))
suite.addTest(unittest.makeSuite(test_translate.TranslateTestCase))
return suite

if __name__ == '__main__':
Expand Down
6 changes: 0 additions & 6 deletions babelglade/tests/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,3 @@ def test_yield_four_item_tuples_without_comments(self):
extracted = extract_glade(self.glade_fileobj, DEFAULT_KEYWORDS, False, {})
for entry in list(extracted):
assert len(entry) == 4, "extract_galde did not return a 4 tupple item"


def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(GladeExtractTests))
return suite
37 changes: 20 additions & 17 deletions babelglade/tests/test_translate.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@

import os
import unittest
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"))
class TranslateTestCase(unittest.TestCase):

with open("test.desktop") as desktop:
content = desktop.read()
def test_desktop_file(self):
translate_desktop_file(relative("test.raw.desktop"), "test.desktop", relative("locale"))

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
with open("test.desktop") as desktop:
content = desktop.read()

def test_appdata_xml():
translate_appdata_file(relative("test.raw.appdata.xml"), "test.appdata.xml", relative("locale"))
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

with open("test.appdata.xml") as desktop:
content = desktop.read()
def test_appdata_xml(self):
translate_appdata_file(relative("test.raw.appdata.xml"), "test.appdata.xml", relative("locale"))

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>
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">
assert """<p xml:lang="fr">
Texte
multi-ligne.
</p>""" in content
assert """<p xml:lang="nl">
assert """<p xml:lang="nl">
Meerregelige
tekst.
</p>""" in content
6 changes: 5 additions & 1 deletion babelglade/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def translate_desktop_file(infile, outfile, localedir):
# First the original line found it in the file, then the translations.
outfp.writelines((outline+'\n' for outline in ([line] + additional_lines)))

infp.close()
outfp.close()


def translate_appdata_file(infile, outfile, localedir):
catalogs = get_catalogs(localedir)
Expand Down Expand Up @@ -94,7 +97,8 @@ def get_catalogs(localedir):
catalogs = {}

for pofile in pofiles:
catalog = read_po(open(pofile, 'r'))
with open(pofile, 'r') as f:
catalog = read_po(f)
catalogs[catalog.locale] = catalog
logging.info("Found %d strings for %s", len(catalog), catalog.locale)
# logging.debug("Strings for %r", catalog, catalog.values())
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
[distutils.commands]
compile_catalog = babel.messages.frontend:compile_catalog
""",
packages = ['babelglade']
packages = ['babelglade', 'babelglade.tests']

)

0 comments on commit 4c66c77

Please sign in to comment.