From fd22a8e363db44aff153686cd6cc0f64fff1fdf8 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 31 Dec 2015 02:46:08 +0200 Subject: [PATCH] Add test for frontend update_command --- .gitignore | 2 +- tests/messages/test_frontend.py | 37 +++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 67ba223a..d8f8bc16 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,6 @@ test-env babel/global.dat babel/global.dat.json tests/messages/data/project/i18n/long_messages.pot -tests/messages/data/project/i18n/temp.pot +tests/messages/data/project/i18n/temp* tests/messages/data/project/i18n/en_US /venv* diff --git a/tests/messages/test_frontend.py b/tests/messages/test_frontend.py index 4676adc1..f958b805 100644 --- a/tests/messages/test_frontend.py +++ b/tests/messages/test_frontend.py @@ -24,9 +24,9 @@ import unittest from babel import __version__ as VERSION from babel.dates import format_datetime -from babel.messages import frontend +from babel.messages import frontend, Catalog from babel.util import LOCALTZ -from babel.messages.pofile import read_po +from babel.messages.pofile import read_po, write_po from babel._compat import StringIO @@ -1059,6 +1059,39 @@ compiling catalog %r to %r if os.path.isfile(mo_file): os.unlink(mo_file) + def test_update(self): + template = Catalog() + template.add("1") + template.add("2") + template.add("3") + tmpl_file = os.path.join(self._i18n_dir(), 'temp-template.pot') + with open(tmpl_file, "wb") as outfp: + write_po(outfp, template) + po_file = os.path.join(self._i18n_dir(), 'temp1.po') + self.cli.run(sys.argv + ['init', + '-l', 'fi', + '-o', po_file, + '-i', tmpl_file + ]) + with open(po_file, "r") as infp: + catalog = read_po(infp) + assert len(catalog) == 3 + + # Add another entry to the template + + template.add("4") + + with open(tmpl_file, "wb") as outfp: + write_po(outfp, template) + + self.cli.run(sys.argv + ['update', + '-l', 'fi_FI', + '-o', po_file, + '-i', tmpl_file]) + + with open(po_file, "r") as infp: + catalog = read_po(infp) + assert len(catalog) == 4 # Catalog was updated def test_parse_mapping(): buf = StringIO( -- 2.47.2