Skip to content

Commit 29e23b6

Browse files
committed
Unwrap testcases with setup/teardown
1 parent f968a6a commit 29e23b6

4 files changed

Lines changed: 309 additions & 312 deletions

File tree

tests/messages/consts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
data_dir = os.path.join(this_dir, 'data')
1010
project_dir = os.path.join(data_dir, 'project')
1111
i18n_dir = os.path.join(project_dir, 'i18n')
12-
pot_file = os.path.join(i18n_dir, 'temp.pot')
12+
pot_file = os.path.join(i18n_dir, 'temp.pot') # TODO: this should not be global
1313

1414

1515
def get_po_file_path(locale):
Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
from __future__ import annotations
22

3-
import os
4-
import unittest
5-
63
import pytest
74

85
from babel.messages import frontend
@@ -11,27 +8,24 @@
118
from tests.messages.utils import Distribution
129

1310

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
1918

20-
self.dist = Distribution(TEST_PROJECT_DISTRIBUTION_DATA)
21-
self.cmd = frontend.CompileCatalog(self.dist)
22-
self.cmd.initialize_options()
2319

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()
2625

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()
3226

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

Comments
 (0)