def test_generate_po_removes_old_messages_of_workflow(self): os.makedirs(os.path.dirname(EN_PO_PATH)) with open(EN_PO_PATH, 'w+') as po_file: po_file.write(PO_HEADER) po_file.write('\n\n') po_file.write(OLD_SIMPLE_WORKFLOW_MESSAGES) I18nBuilder(self.simple_workflow_spec_path).generate_po('en') I18nBuilder(self.simple_workflow_spec_path).generate_po('en') self.maxDiff = None self.assertMultiLineEqual( PO_HEADER + '\n\n' + SIMPLE_WORKFLOW_MESSAGES + '\n', read_file(EN_PO_PATH))
def test_validates_path(self): with self.assertRaises(ValueError) as cm: I18nBuilder('/tmp/invalid/path/specification.txt') self.assertEquals( 'Path "/tmp/invalid/path/specification.txt"' ' does not exist.', str(cm.exception))
def test_generate_po_generates_po_file(self): I18nBuilder(self.simple_workflow_spec_path).generate_po('en') self.maxDiff = None self.assertMultiLineEqual( PO_HEADER + '\n\n' + SIMPLE_WORKFLOW_MESSAGES + '\n', read_file(EN_PO_PATH))
def test_generate_pot_generates_pot_file(self): I18nBuilder(self.simple_workflow_spec_path).generate_pot() self.maxDiff = None self.assertMultiLineEqual( clear_msgstr(PO_HEADER + '\n\n' + SIMPLE_WORKFLOW_MESSAGES + '\n'), read_file(POT_PATH))
def test_get_locales_directory_not_found_returns_None(self): asset_path = os.path.join(os.path.dirname(__file__), 'assets', 'example.specification.txt') builder = I18nBuilder(asset_path) self.assertIsNone(builder.get_locales_directory_path(), 'There should no locales directory be found' ' because "profiles" is not in the path.')
def get_locales_directory(self): try: builder = I18nBuilder(self.get_spec_path()) except ConflictError: raise except Exception: # This happens when we have parsing errors, which we already # handle later with a status message - so we just skip here. return None return builder.get_locales_directory_path()
def test_generate_pot_removes_old_messages_of_workflow(self): with open(POT_PATH, 'w+') as po_file: po_file.write(PO_HEADER) po_file.write('\n\n') po_file.write(clear_msgstr(OLD_SIMPLE_WORKFLOW_MESSAGES)) I18nBuilder(self.simple_workflow_spec_path).generate_pot() self.maxDiff = None self.assertMultiLineEqual( clear_msgstr(PO_HEADER + '\n\n' + SIMPLE_WORKFLOW_MESSAGES + '\n'), read_file(POT_PATH))
def update_translations(self, specification_path, output_formatter=None): specification = self._get_specification( specification_path, output_formatter=output_formatter) if not specification: return False builder = I18nBuilder(specification_path) builder.generate(specification.language.code) if output_formatter: output_formatter( 'info', _(u'info_locales_updated', default=u'${id}: The translations were updated in your' u' locales directory. You should now run bin/i18n-build', mapping={'id': self._workflow_id(specification_path)})) return True
def test_generate_generates_pot_and_po_files(self): self.assertFalse(os.path.exists(POT_PATH)) self.assertFalse(os.path.exists(EN_PO_PATH)) I18nBuilder(self.simple_workflow_spec_path).generate('en') self.assertTrue(os.path.exists(POT_PATH)) self.assertTrue(os.path.exists(EN_PO_PATH))
def test_get_locales_directory(self): builder = I18nBuilder(self.simple_workflow_spec_path) locales_path = builder.get_locales_directory_path() self.assertEquals(os.path.join(I18N_ASSETS, 'locales'), locales_path)