Skip to content

Commit e42ee44

Browse files
committed
Switch from unittest to pytest
1 parent ca85030 commit e42ee44

27 files changed

Lines changed: 1911 additions & 2089 deletions

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ jobs:
3131
with:
3232
python-version: ${{ matrix.python-version }}
3333
- run: uv sync --dev --all-packages
34-
- run: uv run python -m unittest discover -s fluent.syntax
35-
- run: uv run python -m unittest discover -s fluent.runtime
34+
- run: uv run pytest fluent.syntax
35+
- run: uv run pytest fluent.runtime
3636

3737
# Test fluent.runtime's compatibility with a range of fluent.syntax versions.
3838
compatibility:
@@ -52,4 +52,4 @@ jobs:
5252
- run: uv venv
5353
- run: uv pip install ${{ matrix.fluent-syntax }}
5454
- run: uv pip install ./fluent.runtime
55-
- run: uv run python -m unittest discover -s fluent.runtime
55+
- run: uv run pytest fluent.runtime
Lines changed: 40 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,61 @@
1-
import unittest
1+
import pytest
22

33
from fluent.runtime import FluentBundle, FluentResource
44

55
from ..utils import dedent_ftl
66

77

8-
class TestNumbersInValues(unittest.TestCase):
9-
def setUp(self):
10-
self.bundle = FluentBundle(["en-US"], use_isolating=False)
11-
self.bundle.add_resource(
8+
class TestNumbersInValues:
9+
@pytest.fixture
10+
def bundle(self):
11+
bundle = FluentBundle(["en-US"], use_isolating=False)
12+
bundle.add_resource(
1213
FluentResource(
1314
dedent_ftl(
1415
"""
15-
foo = Foo { $num }
16-
bar = { foo }
17-
baz =
18-
.attr = Baz Attribute { $num }
19-
qux = { "a" ->
20-
*[a] Baz Variant A { $num }
21-
}
22-
"""
16+
foo = Foo { $num }
17+
bar = { foo }
18+
baz =
19+
.attr = Baz Attribute { $num }
20+
qux = { "a" ->
21+
*[a] Baz Variant A { $num }
22+
}
23+
"""
2324
)
2425
)
2526
)
27+
return bundle
2628

27-
def test_can_be_used_in_the_message_value(self):
28-
val, errs = self.bundle.format_pattern(
29-
self.bundle.get_message("foo").value, {"num": 3}
30-
)
31-
self.assertEqual(val, "Foo 3")
32-
self.assertEqual(len(errs), 0)
33-
34-
def test_can_be_used_in_the_message_value_which_is_referenced(self):
35-
val, errs = self.bundle.format_pattern(
36-
self.bundle.get_message("bar").value, {"num": 3}
37-
)
38-
self.assertEqual(val, "Foo 3")
39-
self.assertEqual(len(errs), 0)
29+
def test_can_be_used_in_the_message_value(self, bundle):
30+
val, errs = bundle.format_pattern(bundle.get_message("foo").value, {"num": 3})
31+
assert val == "Foo 3"
32+
assert len(errs) == 0
4033

41-
def test_can_be_used_in_an_attribute(self):
42-
val, errs = self.bundle.format_pattern(
43-
self.bundle.get_message("baz").attributes["attr"], {"num": 3}
44-
)
45-
self.assertEqual(val, "Baz Attribute 3")
46-
self.assertEqual(len(errs), 0)
34+
def test_can_be_used_in_the_message_value_which_is_referenced(self, bundle):
35+
val, errs = bundle.format_pattern(bundle.get_message("bar").value, {"num": 3})
36+
assert val == "Foo 3"
37+
assert len(errs) == 0
4738

48-
def test_can_be_used_in_a_variant(self):
49-
val, errs = self.bundle.format_pattern(
50-
self.bundle.get_message("qux").value, {"num": 3}
39+
def test_can_be_used_in_an_attribute(self, bundle):
40+
val, errs = bundle.format_pattern(
41+
bundle.get_message("baz").attributes["attr"], {"num": 3}
5142
)
52-
self.assertEqual(val, "Baz Variant A 3")
53-
self.assertEqual(len(errs), 0)
43+
assert val == "Baz Attribute 3"
44+
assert len(errs) == 0
5445

46+
def test_can_be_used_in_a_variant(self, bundle):
47+
val, errs = bundle.format_pattern(bundle.get_message("qux").value, {"num": 3})
48+
assert val == "Baz Variant A 3"
49+
assert len(errs) == 0
5550

56-
class TestStrings(unittest.TestCase):
57-
def setUp(self):
58-
self.bundle = FluentBundle(["en-US"], use_isolating=False)
59-
self.bundle.add_resource(
60-
FluentResource(
61-
dedent_ftl(
62-
"""
63-
foo = { $arg }
64-
"""
65-
)
66-
)
67-
)
6851

52+
class TestStrings:
6953
def test_can_be_a_string(self):
70-
val, errs = self.bundle.format_pattern(
71-
self.bundle.get_message("foo").value, {"arg": "Argument"}
54+
bundle = FluentBundle(["en-US"], use_isolating=False)
55+
bundle.add_resource(FluentResource("foo = { $arg }"))
56+
57+
val, errs = bundle.format_pattern(
58+
bundle.get_message("foo").value, {"arg": "Argument"}
7259
)
73-
self.assertEqual(val, "Argument")
74-
self.assertEqual(len(errs), 0)
60+
assert val == "Argument"
61+
assert len(errs) == 0

0 commit comments

Comments
 (0)