Beispiel #1
0
 def test_raise_error_hook(self):
     tr = Context.from_file(os.path.join(DIR, 'samples', 'numbers.l20n'),
                            error_hook=self.raise_error)
     self.assertRaises(NameError, tr, 'noSuchEntity')
Beispiel #2
0
 def test_error_hook_on_missing_variable(self):
     tr = Context.from_file(StringIO('<a "{{ $missing }}">'),
                            error_hook=self.store_error)
     self.assertTrue(tr('a'), '{{ $missing }}')
     self.assertTrue(isinstance(self.error, NameError))
Beispiel #3
0
 def test_unicode_load_by_path(self):
     tr = Context.from_file(os.path.join(DIR, 'samples', 'unicode-de.l20n'))
     self.assertEqual(tr('key'), u'Schl\xfcssel')
     self.assertEqual(tr('keyEscaped'), u'Schl\xfcssel')
Beispiel #4
0
 def test_load_by_file_like(self):
     f = StringIO('<entity "some value">')
     tr = Context.from_file(f)
     self.assertEqual(tr('entity'), "some value")
Beispiel #5
0
 def test_load_by_open_file(self):
     with open(os.path.join(DIR, 'samples', 'numbers.l20n')) as f:
         tr = Context.from_file(f)
     self.assertEqual(tr('pi'), '3.14')
Beispiel #6
0
 def test_load_by_path(self):
     tr = Context.from_file(os.path.join(DIR, 'samples', 'numbers.l20n'))
     self.assertEqual(tr('thousand'), '1000')