16
16
EmptyLocalizationError , NotSupportedError , UnreadableReferenceError )
17
17
from fluent .migrate .util import ftl , ftl_resource_to_json , to_json
18
18
from fluent .migrate .context import MergeContext
19
- from fluent .migrate .transforms import COPY
19
+ from fluent .migrate .transforms import CONCAT , COPY
20
20
21
21
22
22
def here (* parts ):
@@ -251,7 +251,7 @@ def test_missing_reference_file(self):
251
251
252
252
253
253
@unittest .skipUnless (compare_locales , 'compare-locales requried' )
254
- class TestEmptyLocalization (unittest .TestCase ):
254
+ class TestMissingLocalizationFiles (unittest .TestCase ):
255
255
def setUp (self ):
256
256
# Silence all logging.
257
257
logging .disable (logging .CRITICAL )
@@ -266,7 +266,40 @@ def tearDown(self):
266
266
# Resume logging.
267
267
logging .disable (logging .NOTSET )
268
268
269
- def test_all_localization_missing (self ):
269
+ def test_missing_file (self ):
270
+ self .ctx .add_transforms ('aboutDownloads.ftl' , 'aboutDownloads.ftl' , [
271
+ FTL .Message (
272
+ id = FTL .Identifier ('title' ),
273
+ value = COPY (
274
+ 'aboutDownloads.dtd' ,
275
+ 'aboutDownloads.title'
276
+ )
277
+ ),
278
+ FTL .Message (
279
+ id = FTL .Identifier ('header' ),
280
+ value = COPY (
281
+ 'missing.dtd' ,
282
+ 'missing'
283
+ )
284
+ ),
285
+ ])
286
+
287
+ expected = {
288
+ 'aboutDownloads.ftl' : ftl_resource_to_json ('''
289
+ # This Source Code Form is subject to the terms of the Mozilla Public
290
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
291
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
292
+
293
+ title = Pobrane pliki
294
+ ''' )
295
+ }
296
+
297
+ self .assertDictEqual (
298
+ to_json (self .ctx .merge_changeset ()),
299
+ expected
300
+ )
301
+
302
+ def test_all_files_missing (self ):
270
303
pattern = ('No localization files were found' )
271
304
with self .assertRaisesRegexp (EmptyLocalizationError , pattern ):
272
305
self .ctx .add_transforms ('existing.ftl' , 'existing.ftl' , [
@@ -281,7 +314,9 @@ def test_all_localization_missing(self):
281
314
282
315
283
316
@unittest .skipUnless (compare_locales , 'compare-locales requried' )
284
- class TestIncompleteLocalization (unittest .TestCase ):
317
+ class TestMissingLocalizationStrings (unittest .TestCase ):
318
+ maxDiff = None
319
+
285
320
def setUp (self ):
286
321
# Silence all logging.
287
322
logging .disable (logging .CRITICAL )
@@ -296,20 +331,116 @@ def tearDown(self):
296
331
# Resume logging.
297
332
logging .disable (logging .NOTSET )
298
333
299
- def test_missing_localization_file (self ):
300
- self .ctx .add_transforms ('existing .ftl' , 'existing .ftl' , [
334
+ def test_missing_string_in_simple_value (self ):
335
+ self .ctx .add_transforms ('aboutDownloads .ftl' , 'aboutDownloads .ftl' , [
301
336
FTL .Message (
302
- id = FTL .Identifier ('foo ' ),
337
+ id = FTL .Identifier ('title ' ),
303
338
value = COPY (
304
- 'existing .dtd' ,
305
- 'foo '
339
+ 'aboutDownloads .dtd' ,
340
+ 'missing '
306
341
)
307
342
),
343
+ ])
344
+
345
+ self .assertDictEqual (
346
+ to_json (self .ctx .merge_changeset ()),
347
+ {}
348
+ )
349
+
350
+ def test_missing_string_in_only_variant (self ):
351
+ self .ctx .add_transforms ('aboutDownloads.ftl' , 'aboutDownloads.ftl' , [
308
352
FTL .Message (
309
- id = FTL .Identifier ('bar' ),
310
- value = COPY (
311
- 'missing.dtd' ,
312
- 'bar'
353
+ id = FTL .Identifier ('title' ),
354
+ value = CONCAT (
355
+ FTL .SelectExpression (
356
+ expression = FTL .CallExpression (
357
+ callee = FTL .Identifier ('PLATFORM' )
358
+ ),
359
+ variants = [
360
+ FTL .Variant (
361
+ key = FTL .VariantName ('other' ),
362
+ default = True ,
363
+ value = COPY (
364
+ 'aboutDownloads.dtd' ,
365
+ 'missing'
366
+ )
367
+ ),
368
+ ]
369
+ ),
370
+ )
371
+ ),
372
+ ])
373
+
374
+ self .assertDictEqual (
375
+ to_json (self .ctx .merge_changeset ()),
376
+ {}
377
+ )
378
+
379
+ def test_missing_string_in_all_variants (self ):
380
+ self .ctx .add_transforms ('aboutDownloads.ftl' , 'aboutDownloads.ftl' , [
381
+ FTL .Message (
382
+ id = FTL .Identifier ('title' ),
383
+ value = CONCAT (
384
+ FTL .SelectExpression (
385
+ expression = FTL .CallExpression (
386
+ callee = FTL .Identifier ('PLATFORM' )
387
+ ),
388
+ variants = [
389
+ FTL .Variant (
390
+ key = FTL .VariantName ('windows' ),
391
+ default = False ,
392
+ value = COPY (
393
+ 'aboutDownloads.dtd' ,
394
+ 'missing.windows'
395
+ )
396
+ ),
397
+ FTL .Variant (
398
+ key = FTL .VariantName ('other' ),
399
+ default = True ,
400
+ value = COPY (
401
+ 'aboutDownloads.dtd' ,
402
+ 'missing.other'
403
+ )
404
+ ),
405
+ ]
406
+ ),
407
+ )
408
+ ),
409
+ ])
410
+
411
+ self .assertDictEqual (
412
+ to_json (self .ctx .merge_changeset ()),
413
+ {}
414
+ )
415
+
416
+ def test_missing_string_in_one_of_variants (self ):
417
+ self .ctx .add_transforms ('aboutDownloads.ftl' , 'aboutDownloads.ftl' , [
418
+ FTL .Message (
419
+ id = FTL .Identifier ('title' ),
420
+ value = CONCAT (
421
+ FTL .SelectExpression (
422
+ expression = FTL .CallExpression (
423
+ callee = FTL .Identifier ('PLATFORM' )
424
+ ),
425
+ variants = [
426
+ FTL .Variant (
427
+ key = FTL .VariantName ('windows' ),
428
+ default = False ,
429
+ value = COPY (
430
+ 'aboutDownloads.dtd' ,
431
+ 'aboutDownloads.title'
432
+ )
433
+ ),
434
+ FTL .Variant (
435
+ key = FTL .VariantName ('other' ),
436
+ default = True ,
437
+ value = COPY (
438
+ 'aboutDownloads.dtd' ,
439
+ 'missing.other'
440
+ )
441
+ ),
442
+ ]
443
+ ),
313
444
)
314
445
),
315
446
])
@@ -319,6 +450,83 @@ def test_missing_localization_file(self):
319
450
{}
320
451
)
321
452
453
+ def test_missing_string_in_only_attribute (self ):
454
+ self .ctx .add_transforms ('aboutDownloads.ftl' , 'aboutDownloads.ftl' , [
455
+ FTL .Message (
456
+ id = FTL .Identifier ('title' ),
457
+ attributes = [
458
+ FTL .Attribute (
459
+ FTL .Identifier ('one' ),
460
+ COPY (
461
+ 'aboutDownloads.dtd' ,
462
+ 'missing'
463
+ )
464
+ ),
465
+ ]
466
+ ),
467
+ ])
468
+
469
+ self .assertDictEqual (
470
+ to_json (self .ctx .merge_changeset ()),
471
+ {}
472
+ )
473
+
474
+ def test_missing_string_in_all_attributes (self ):
475
+ self .ctx .add_transforms ('aboutDownloads.ftl' , 'aboutDownloads.ftl' , [
476
+ FTL .Message (
477
+ id = FTL .Identifier ('title' ),
478
+ attributes = [
479
+ FTL .Attribute (
480
+ FTL .Identifier ('one' ),
481
+ COPY (
482
+ 'aboutDownloads.dtd' ,
483
+ 'missing.one'
484
+ )
485
+ ),
486
+ FTL .Attribute (
487
+ FTL .Identifier ('two' ),
488
+ COPY (
489
+ 'aboutDownloads.dtd' ,
490
+ 'missing.two'
491
+ )
492
+ ),
493
+ ]
494
+ ),
495
+ ])
496
+
497
+ self .assertDictEqual (
498
+ to_json (self .ctx .merge_changeset ()),
499
+ {}
500
+ )
501
+
502
+ def test_missing_string_in_one_of_attributes (self ):
503
+ self .ctx .add_transforms ('aboutDownloads.ftl' , 'aboutDownloads.ftl' , [
504
+ FTL .Message (
505
+ id = FTL .Identifier ('title' ),
506
+ attributes = [
507
+ FTL .Attribute (
508
+ FTL .Identifier ('title' ),
509
+ COPY (
510
+ 'aboutDownloads.dtd' ,
511
+ 'aboutDownloads.title'
512
+ )
513
+ ),
514
+ FTL .Attribute (
515
+ FTL .Identifier ('missing' ),
516
+ COPY (
517
+ 'aboutDownloads.dtd' ,
518
+ 'missing'
519
+ )
520
+ ),
521
+ ]
522
+ ),
523
+ ])
524
+
525
+ self .assertDictEqual (
526
+ to_json (self .ctx .merge_changeset ()),
527
+ {}
528
+ )
529
+
322
530
323
531
@unittest .skipUnless (compare_locales , 'compare-locales requried' )
324
532
class TestExistingTarget (unittest .TestCase ):
@@ -360,7 +568,6 @@ def test_existing_target_ftl_missing_string(self):
360
568
''' )
361
569
}
362
570
363
- self .maxDiff = None
364
571
self .assertDictEqual (
365
572
to_json (self .ctx .merge_changeset ()),
366
573
expected
@@ -399,7 +606,6 @@ def test_existing_target_ftl_existing_string(self):
399
606
''' )
400
607
}
401
608
402
- self .maxDiff = None
403
609
self .assertDictEqual (
404
610
to_json (self .ctx .merge_changeset ()),
405
611
expected
0 commit comments