Skip to content

Commit 7776c65

Browse files
committed
Unwrap testcases with setup/teardown
1 parent 15911ec commit 7776c65

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):

tests/messages/frontend/test_compile.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212

1313
from __future__ import annotations
1414

15-
import os
16-
import unittest
17-
1815
import pytest
1916

2017
from babel.messages import frontend
@@ -23,27 +20,24 @@
2320
from tests.messages.utils import Distribution
2421

2522

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
3130

32-
self.dist = Distribution(TEST_PROJECT_DISTRIBUTION_DATA)
33-
self.cmd = frontend.CompileCatalog(self.dist)
34-
self.cmd.initialize_options()
3531

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

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

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

Comments
 (0)