56 elif msgctxt is not None: |
56 elif msgctxt is not None: |
57 msgctxt += line[1:-1] |
57 msgctxt += line[1:-1] |
58 return msgs |
58 return msgs |
59 |
59 |
60 |
60 |
61 TESTCUBE_DIR = osp.join(DATADIR, 'cubes', 'i18ntestcube') |
61 TESTCUBE_DIR = osp.join(DATADIR, 'libpython', 'cubicweb_i18ntestcube') |
62 |
62 |
63 |
63 |
64 class cubePotGeneratorTC(TestCase): |
64 class cubePotGeneratorTC(TestCase): |
65 """test case for i18n pot file generator""" |
65 """test case for i18n pot file generator""" |
66 |
66 |
70 env['PYTHONPATH'] += os.pathsep |
70 env['PYTHONPATH'] += os.pathsep |
71 else: |
71 else: |
72 env['PYTHONPATH'] = '' |
72 env['PYTHONPATH'] = '' |
73 env['PYTHONPATH'] += osp.join(DATADIR, 'libpython') |
73 env['PYTHONPATH'] += osp.join(DATADIR, 'libpython') |
74 cubedir = osp.join(DATADIR, 'libpython', 'cubicweb_i18ntestcube') |
74 cubedir = osp.join(DATADIR, 'libpython', 'cubicweb_i18ntestcube') |
75 self._check(cubedir, env) |
|
76 |
|
77 def test_i18ncube_legacy_layout(self): |
|
78 env = os.environ.copy() |
|
79 env['CW_CUBES_PATH'] = osp.join(DATADIR, 'cubes') |
|
80 if 'PYTHONPATH' in env: |
|
81 env['PYTHONPATH'] += os.pathsep |
|
82 else: |
|
83 env['PYTHONPATH'] = '' |
|
84 env['PYTHONPATH'] += DATADIR |
|
85 cubedir = osp.join(DATADIR, 'cubes', 'i18ntestcube') |
|
86 self._check(cubedir, env) |
75 self._check(cubedir, env) |
87 |
76 |
88 def _check(self, cubedir, env): |
77 def _check(self, cubedir, env): |
89 cmd = [sys.executable, '-m', 'cubicweb', 'i18ncube', 'i18ntestcube'] |
78 cmd = [sys.executable, '-m', 'cubicweb', 'i18ncube', 'i18ntestcube'] |
90 proc = Popen(cmd, env=env, stdout=PIPE, stderr=STDOUT) |
79 proc = Popen(cmd, env=env, stdout=PIPE, stderr=STDOUT) |
135 return None |
124 return None |
136 |
125 |
137 @patch('pkg_resources.load_entry_point', return_value=FakeMessageExtractor) |
126 @patch('pkg_resources.load_entry_point', return_value=FakeMessageExtractor) |
138 def test_cube_custom_extractor(self, mock_load_entry_point): |
127 def test_cube_custom_extractor(self, mock_load_entry_point): |
139 distname = 'cubicweb_i18ntestcube' # same for new and legacy layout |
128 distname = 'cubicweb_i18ntestcube' # same for new and legacy layout |
140 for cubedir in [ |
129 cubedir = osp.join(DATADIR, 'libpython', 'cubicweb_i18ntestcube') |
141 osp.join(DATADIR, 'libpython', 'cubicweb_i18ntestcube'), |
130 with capture_stdout() as stream: |
142 # Legacy cubes. |
131 devctl.update_cube_catalogs(cubedir) |
143 osp.join(DATADIR, 'cubes', 'i18ntestcube'), |
132 self.assertIn(u'no message catalog for cube i18ntestcube', |
144 ]: |
133 stream.read()) |
145 with self.subTest(cubedir=cubedir): |
134 mock_load_entry_point.assert_called_once_with( |
146 with capture_stdout() as stream: |
135 distname, 'cubicweb.i18ncube', 'i18ntestcube') |
147 devctl.update_cube_catalogs(cubedir) |
136 mock_load_entry_point.reset_mock() |
148 self.assertIn(u'no message catalog for cube i18ntestcube', |
|
149 stream.read()) |
|
150 mock_load_entry_point.assert_called_once_with( |
|
151 distname, 'cubicweb.i18ncube', 'i18ntestcube') |
|
152 mock_load_entry_point.reset_mock() |
|
153 |
137 |
154 |
138 |
155 if __name__ == '__main__': |
139 if __name__ == '__main__': |
156 main() |
140 main() |