File tree Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Original file line number Diff line number Diff line change
1
+ import unittest
2
+ import os
3
+ import tempfile
4
+ from ..msgfmt import make
5
+
6
+ class TestMsgfmt (unittest .TestCase ):
7
+
8
+ def setUp (self ):
9
+ self .test_dir = tempfile .TemporaryDirectory ()
10
+ self .addCleanup (self .test_dir .cleanup )
11
+
12
+ def create_po_file (self , content ):
13
+ po_file_path = os .path .join (self .test_dir .name , 'test.po' )
14
+ with open (po_file_path , 'w' , encoding = 'utf-8' ) as f :
15
+ f .write (content )
16
+ return po_file_path
17
+
18
+ def test_make_creates_mo_file (self ):
19
+ po_content = '''
20
+ msgid ""
21
+ msgstr ""
22
+ "Content-Type: text/plain; charset=UTF-8\\ n"
23
+
24
+ msgid "Hello"
25
+ msgstr "Bonjour"
26
+ '''
27
+ po_file = self .create_po_file (po_content )
28
+ mo_file = os .path .splitext (po_file )[0 ] + '.mo'
29
+
30
+ make (po_file , mo_file )
31
+
32
+ self .assertTrue (os .path .exists (mo_file ))
33
+
34
+ def test_make_handles_fuzzy (self ):
35
+ po_content = '''
<
D79A
code> 36
+ msgid ""
37
+ msgstr ""
38
+ "Content-Type: text/plain; charset=UTF-8\\ n"
39
+
40
+ #, fuzzy
41
+ msgid "Hello"
42
+ msgstr "Bonjour"
43
+ '''
44
+ po_file = self .create_po_file (po_content )
45
+ mo_file = os .path .splitext (po_file )[0 ] + '.mo'
46
+
47
+ make (po_file , mo_file )
48
+
49
+ self .assertTrue (os .path .exists (mo_file ))
50
+
51
+ def test_make_invalid_po_file (self ):
52
+ po_content = '''
53
+ msgid "Hello"
54
+ msgstr "Bonjour"
55
+ msgid_plural "Hellos"
56
+ '''
57
+ po_file = self .create_po_file (po_content )
58
+ mo_file = os .path .splitext (po_file )[0 ] + '.mo'
59
+
60
+ with self .assertRaises (SystemExit ):
61
+ make (po_file , mo_file )
62
+
63
+ if __name__ == '__main__' :
64
+ unittest .main ()
You can’t perform that action at this time.
0 commit comments