|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -import os |
4 | | -import unittest |
5 | | - |
6 | 3 | import pytest |
7 | 4 |
|
8 | 5 | from babel.messages import frontend |
|
11 | 8 | from tests.messages.utils import Distribution |
12 | 9 |
|
13 | 10 |
|
14 | | -class CompileCatalogTestCase(unittest.TestCase): |
15 | | - |
16 | | - def setUp(self): |
17 | | - self.olddir = os.getcwd() |
18 | | - os.chdir(data_dir) |
| 11 | +@pytest.fixture |
| 12 | +def compile_catalog_cmd(monkeypatch): |
| 13 | + monkeypatch.chdir(data_dir) |
| 14 | + dist = Distribution(TEST_PROJECT_DISTRIBUTION_DATA) |
| 15 | + cmd = frontend.CompileCatalog(dist) |
| 16 | + cmd.initialize_options() |
| 17 | + return cmd |
19 | 18 |
|
20 | | - self.dist = Distribution(TEST_PROJECT_DISTRIBUTION_DATA) |
21 | | - self.cmd = frontend.CompileCatalog(self.dist) |
22 | | - self.cmd.initialize_options() |
23 | 19 |
|
24 | | - def tearDown(self): |
25 | | - os.chdir(self.olddir) |
| 20 | +def test_no_directory_or_output_file_specified(compile_catalog_cmd): |
| 21 | + compile_catalog_cmd.locale = 'en_US' |
| 22 | + compile_catalog_cmd.input_file = 'dummy' |
| 23 | + with pytest.raises(OptionError): |
| 24 | + compile_catalog_cmd.finalize_options() |
26 | 25 |
|
27 | | - def test_no_directory_or_output_file_specified(self): |
28 | | - self.cmd.locale = 'en_US' |
29 | | - self.cmd.input_file = 'dummy' |
30 | | - with pytest.raises(OptionError): |
31 | | - self.cmd.finalize_options() |
32 | 26 |
|
33 | | - def test_no_directory_or_input_file_specified(self): |
34 | | - self.cmd.locale = 'en_US' |
35 | | - self.cmd.output_file = 'dummy' |
36 | | - with pytest.raises(OptionError): |
37 | | - self.cmd.finalize_options() |
| 27 | +def test_no_directory_or_input_file_specified(compile_catalog_cmd): |
| 28 | + compile_catalog_cmd.locale = 'en_US' |
| 29 | + compile_catalog_cmd.output_file = 'dummy' |
| 30 | + with pytest.raises(OptionError): |
| 31 | + compile_catalog_cmd.finalize_options() |
0 commit comments