|
9 | 9 | import ass |
10 | 10 |
|
11 | 11 | folder = Path(__file__).parent |
| 12 | +test_ass_path = Path(folder, "test.ass") |
12 | 13 |
|
13 | 14 |
|
14 | | -class TestDocument: |
| 15 | +@pytest.fixture |
| 16 | +def example_ass(): |
| 17 | + with test_ass_path.open("r", encoding='utf_8_sig') as f: |
| 18 | + return f.read() |
15 | 19 |
|
16 | | - test_ass = Path(folder, "test.ass") |
17 | 20 |
|
18 | | - def test_parse_dump(self): |
19 | | - with self.test_ass.open("r", encoding='utf_8_sig') as f: |
20 | | - contents = f.read() |
| 21 | +@pytest.fixture |
| 22 | +def example_doc(example_ass): |
| 23 | + return ass.parse(StringIO(example_ass)) |
21 | 24 |
|
22 | | - doc = ass.parse(StringIO(contents)) |
23 | | - out = StringIO() |
24 | | - doc.dump_file(out) |
25 | 25 |
|
26 | | - assert out.getvalue() == contents |
| 26 | +class TestDocument: |
| 27 | + |
| 28 | + def test_parse_dump(self, example_doc, example_ass): |
| 29 | + out = StringIO() |
| 30 | + example_doc.dump_file(out) |
| 31 | + assert out.getvalue() == example_ass |
27 | 32 |
|
28 | | - def test_parse_encoding(self): |
29 | | - with self.test_ass.open("r", encoding='utf_8') as f: |
| 33 | + def test_parse_encoding_utf8(self): |
| 34 | + with test_ass_path.open("r", encoding='utf_8') as f: |
30 | 35 | with pytest.raises(ValueError): |
31 | 36 | ass.parse(f) |
32 | 37 |
|
33 | | - with self.test_ass.open("r", encoding='ascii') as f: |
| 38 | + def test_parse_encoding_ascii(self): |
| 39 | + with test_ass_path.open("r", encoding='ascii') as f: |
34 | 40 | with pytest.raises(ValueError): |
35 | 41 | ass.parse(f) |
36 | 42 |
|
37 | | - def test_dump_encoding(self): |
38 | | - for encoding in ('utf_8_sig', 'utf-8-sig'): |
39 | | - with self.test_ass.open("r", encoding=encoding) as f: |
40 | | - doc = ass.parse(f) |
41 | | - |
42 | | - with self.test_ass.open("r", encoding=encoding.upper()) as f: |
43 | | - doc = ass.parse(f) |
44 | | - |
| 43 | + def test_dump_encoding(self, example_doc): |
45 | 44 | import tempfile |
46 | 45 | with tempfile.TemporaryFile(mode='w', encoding='utf_8') as f: |
47 | 46 | with pytest.warns(UserWarning): |
48 | | - doc.dump_file(f) |
| 47 | + example_doc.dump_file(f) |
49 | 48 |
|
50 | 49 |
|
51 | 50 | class TestSections: |
@@ -80,9 +79,22 @@ def test_script_info(self): |
80 | 79 | assert copy["Arbitrary Field"] == "hi" |
81 | 80 | assert doc.play_res_x == 500 |
82 | 81 |
|
83 | | - @pytest.mark.skip("Unimplemented") |
84 | | - def test_styles(self): |
85 | | - pass |
| 82 | + def test_styles(self, example_doc): |
| 83 | + assert len(example_doc.styles) == 2 |
| 84 | + default_style, alternative_style = example_doc.styles |
| 85 | + |
| 86 | + assert default_style.name == "Default" |
| 87 | + assert alternative_style.name == "Alternative" |
| 88 | + |
| 89 | + assert default_style.bold is False |
| 90 | + assert default_style.italic is False |
| 91 | + assert default_style.underline is False |
| 92 | + assert default_style.strike_out is False |
| 93 | + |
| 94 | + assert alternative_style.bold is True |
| 95 | + assert alternative_style.italic is True |
| 96 | + assert alternative_style.underline is True |
| 97 | + assert alternative_style.strike_out is True |
86 | 98 |
|
87 | 99 | @pytest.mark.skip("Unimplemented") |
88 | 100 | def test_events(self): |
|
0 commit comments