Skip to content

Commit 2fc5b93

Browse files
committed
Add import guard
1 parent aee6369 commit 2fc5b93

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

Lib/test/test_tools/test_msgfmt.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,70 @@
11
import unittest
22
import os
33
import tempfile
4-
from test.test_tools import imports_under_tool
4+
from test.test_tools import imports_under_tool, skip_if_missing
55

6-
with imports_under_tool('i18n'):
6+
skip_if_missing("i18n")
7+
with imports_under_tool("i18n"):
78
from msgfmt import make
89

10+
911
class TestMsgfmt(unittest.TestCase):
1012

1113
def setUp(self):
1214
self.test_dir = tempfile.TemporaryDirectory()
1315
self.addCleanup(self.test_dir.cleanup)
1416

1517
def create_po_file(self, content):
16-
po_file_path = os.path.join(self.test_dir.name, 'test.po')
17-
with open(po_file_path, 'w', encoding='utf-8') as f:
18+
po_file_path = os.path.join(self.test_dir.name, "test.po")
19+
with open(po_file_path, "w", encoding="utf-8") as f:
1820
f.write(content)
1921
return po_file_path
2022

2123
def test_make_creates_mo_file(self):
22-
po_content = '''
24+
po_content = """
2325
msgid ""
2426
msgstr ""
2527
"Content-Type: text/plain; charset=UTF-8\\n"
2628
2729
msgid "Hello"
2830
msgstr "Bonjour"
29-
'''
31+
"""
3032
po_file = self.create_po_file(po_content)
31-
mo_file = os.path.splitext(po_file)[0] + '.mo'
33+
mo_file = os.path.splitext(po_file)[0] + ".mo"
3234

3335
make(po_file, mo_file)
3436

3537
self.assertTrue(os.path.exists(mo_file))
3638

3739
def test_make_handles_fuzzy(self):
38-
po_content = '''
40+
po_content = """
3941
msgid ""
4042
msgstr ""
4143
"Content-Type: text/plain; charset=UTF-8\\n"
4244
4345
#, fuzzy
4446
msgid "Hello"
4547
msgstr "Bonjour"
46-
'''
48+
"""
4749
po_file = self.create_po_file(po_content)
48-
mo_file = os.path.splitext(po_file)[0] + '.mo'
50+
mo_file = os.path.splitext(po_file)[0] + ".mo"
4951

5052
make(po_file, mo_file)
5153

5254
self.assertTrue(os.path.exists(mo_file))
5355

5456
def test_make_invalid_po_file(self):
55-
po_content = '''
57+
po_content = """
5658
msgid "Hello"
5759
msgstr "Bonjour"
5860
msgid_plural "Hellos"
59-
'''
61+
"""
6062
po_file = self.create_po_file(po_content)
61-
mo_file = os.path.splitext(po_file)[0] + '.mo'
63+
mo_file = os.path.splitext(po_file)[0] + ".mo"
6264

6365
with self.assertRaises(SystemExit):
6466
make(po_file, mo_file)
6567

66-
if __name__ == '__main__':
68+
69+
if __name__ == "__main__":
6770
unittest.main()

0 commit comments

Comments
 (0)