|
12 | 12 |
|
13 | 13 | from __future__ import annotations |
14 | 14 |
|
15 | | -import os |
16 | | -import unittest |
17 | | - |
18 | 15 | import pytest |
19 | 16 |
|
20 | 17 | from babel.messages import frontend |
|
23 | 20 | from tests.messages.utils import Distribution |
24 | 21 |
|
25 | 22 |
|
26 | | -class CompileCatalogTestCase(unittest.TestCase): |
27 | | - |
28 | | - def setUp(self): |
29 | | - self.olddir = os.getcwd() |
30 | | - os.chdir(data_dir) |
| 23 | +@pytest.fixture |
| 24 | +def compile_catalog_cmd(monkeypatch): |
| 25 | + monkeypatch.chdir(data_dir) |
| 26 | + dist = Distribution(TEST_PROJECT_DISTRIBUTION_DATA) |
| 27 | + cmd = frontend.CompileCatalog(dist) |
| 28 | + cmd.initialize_options() |
| 29 | + return cmd |
31 | 30 |
|
32 | | - self.dist = Distribution(TEST_PROJECT_DISTRIBUTION_DATA) |
33 | | - self.cmd = frontend.CompileCatalog(self.dist) |
34 | | - self.cmd.initialize_options() |
35 | 31 |
|
36 | | - def tearDown(self): |
37 | | - os.chdir(self.olddir) |
| 32 | +def test_no_directory_or_output_file_specified(compile_catalog_cmd): |
| 33 | + compile_catalog_cmd.locale = 'en_US' |
| 34 | + compile_catalog_cmd.input_file = 'dummy' |
| 35 | + with pytest.raises(OptionError): |
| 36 | + compile_catalog_cmd.finalize_options() |
38 | 37 |
|
39 | | - def test_no_directory_or_output_file_specified(self): |
40 | | - self.cmd.locale = 'en_US' |
41 | | - self.cmd.input_file = 'dummy' |
42 | | - with pytest.raises(OptionError): |
43 | | - self.cmd.finalize_options() |
44 | 38 |
|
45 | | - def test_no_directory_or_input_file_specified(self): |
46 | | - self.cmd.locale = 'en_US' |
47 | | - self.cmd.output_file = 'dummy' |
48 | | - with pytest.raises(OptionError): |
49 | | - self.cmd.finalize_options() |
| 39 | +def test_no_directory_or_input_file_specified(compile_catalog_cmd): |
| 40 | + compile_catalog_cmd.locale = 'en_US' |
| 41 | + compile_catalog_cmd.output_file = 'dummy' |
| 42 | + with pytest.raises(OptionError): |
| 43 | + compile_catalog_cmd.finalize_options() |
0 commit comments