def setUp(self): self.en_us_ftl = parse(FTLParser, ftl(''' # This Source Code Form is subject to the terms of … # A generic comment. title = Downloads header = Your Downloads empty = No Downloads # A section comment. [[ Menu items ]] # A message comment. open-menuitem = [html/label] Open download-state-downloading = Downloading… ''')) self.ab_cd_ftl = parse(FTLParser, ftl(''' # This Source Code Form is subject to the terms of … empty = Brak pobranych plików ''')) ab_cd_dtd = parse(DTDParser, ''' <!ENTITY aboutDownloads.title "Pobrane pliki"> <!ENTITY aboutDownloads.open "Otwórz"> ''') ab_cd_prop = parse(PropertiesParser, ''' downloadState.downloading=Pobieranie… ''') self.ab_cd_legacy = { key: val for strings in (ab_cd_dtd, ab_cd_prop) for key, val in strings.items() } self.transforms = [ FTL.Entity( FTL.Identifier('title'), value=LITERAL_FROM(None, 'aboutDownloads.title') ), FTL.Entity( FTL.Identifier('open-menuitem'), traits=[ FTL.Member( FTL.Keyword('label', 'html'), LITERAL_FROM(None, 'aboutDownloads.open') ), ] ), FTL.Entity( FTL.Identifier('download-state-downloading'), value=LITERAL_FROM(None, 'downloadState.downloading') ) ]
def setUp(self): self.en_us_ftl = parse(FTLParser, ftl(''' title = Downloads header = Your Downloads empty = No Downloads about = About Downloads open-menuitem = [html/label] Open download-state-downloading = Downloading… ''')) self.ab_cd_ftl = parse(FTLParser, ftl(''' empty = Brak pobranych plików about = Previously Hardcoded Value ''')) ab_cd_dtd = parse(DTDParser, ''' <!ENTITY aboutDownloads.title "Pobrane pliki"> <!ENTITY aboutDownloads.open "Otwórz"> ''') ab_cd_prop = parse(PropertiesParser, ''' downloadState.downloading=Pobieranie… ''') self.ab_cd_legacy = { key: val for strings in (ab_cd_dtd, ab_cd_prop) for key, val in strings.items() } self.transforms = [ FTL.Entity( FTL.Identifier('title'), value=LITERAL_FROM(None, 'aboutDownloads.title') ), FTL.Entity( FTL.Identifier('about'), value=LITERAL('Hardcoded Value') ), FTL.Entity( FTL.Identifier('open-menuitem'), traits=[ FTL.Member( FTL.Keyword('label', 'html'), LITERAL_FROM(None, 'aboutDownloads.open') ), ] ), FTL.Entity( FTL.Identifier('download-state-downloading'), value=LITERAL_FROM(None, 'downloadState.downloading') ) ]
def test_serialize_changeset(self): self.ctx.add_transforms('aboutDownloads.ftl', [ FTL.Entity( id=FTL.Identifier('title'), value=LITERAL_FROM( 'aboutDownloads.dtd', 'aboutDownloads.title' ) ), FTL.Entity( id=FTL.Identifier('header'), value=LITERAL_FROM( 'aboutDownloads.dtd', 'aboutDownloads.header' ) ), ]) changesets = [ { ('aboutDownloads.dtd', 'aboutDownloads.title'), }, { ('aboutDownloads.dtd', 'aboutDownloads.header') } ] expected = iter([ { 'aboutDownloads.ftl': ftl(''' # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. title = Pobrane pliki ''') }, { 'aboutDownloads.ftl': ftl(''' # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. title = Pobrane pliki header = Twoje pobrane pliki ''') } ]) for changeset in changesets: serialized = self.ctx.serialize_changeset(changeset) self.assertEqual(serialized, next(expected))
def test_three_way_two_entities(self): ab_cd_ftl = parse(FTLParser, ftl(''' # This Source Code Form is subject to the terms of … empty = Brak pobranych plików ''')) subset = ('title', 'download-state-downloading') resource = merge_resource( self, self.en_us_ftl, ab_cd_ftl, self.transforms, in_changeset=lambda x: x in subset ) self.assertEqual( resource.toJSON(), ftl_resource_to_json(''' # This Source Code Form is subject to the terms of … # A generic comment. title = Pobrane pliki empty = Brak pobranych plików # A section comment. [[ Menu items ]] download-state-downloading = Pobieranie… ''') )
def test_three_way_one_entity_existing_section(self): ab_cd_ftl = parse(FTLParser, ftl(''' # This Source Code Form is subject to the terms of … empty = Brak pobranych plików # A section comment. [[ Menu items ]] # A message comment. open-menuitem = [html/label] Otwórz ''')) subset = ('title',) resource = merge_resource( self, self.en_us_ftl, ab_cd_ftl, self.transforms, in_changeset=lambda x: x in subset ) self.assertEqual( resource.toJSON(), ftl_resource_to_json(''' # This Source Code Form is subject to the terms of … # A generic comment. title = Pobrane pliki empty = Brak pobranych plików # A section comment. [[ Menu items ]] # A message comment. open-menuitem = [html/label] Otwórz ''') )
def test_three_way_one_entity(self): ab_cd_ftl = parse(FTLParser, ftl(''' # This Source Code Form is subject to the terms of … empty = Brak pobranych plików ''')) subset = ('title',) resource = merge_resource( self, self.en_us_ftl, ab_cd_ftl, self.transforms, in_changeset=lambda x: x in subset ) self.assertEqual( resource.toJSON(), ftl_resource_to_json(''' # This Source Code Form is subject to the terms of … # A generic comment. title = Pobrane pliki empty = Brak pobranych plików ''') )