|
1 | 1 | from pathlib import Path |
| 2 | + |
| 3 | +import pytest |
2 | 4 | from paradox_localization_utils.keep_edited_lines_only import write_kept_lines |
3 | 5 |
|
4 | 6 |
|
5 | 7 | class TestWriteKeptLines: |
6 | | - def test_almost_empty_original(self, tmp_path: Path): |
| 8 | + # TODO Test empty file |
| 9 | + |
| 10 | + @pytest.mark.parametrize( |
| 11 | + "input_original_values_by_key, input_text_content", |
| 12 | + [ |
| 13 | + ({"l_english": ""}, "l_english:"), |
| 14 | + ({"\ufeffl_english": ""}, "l_english:"), |
| 15 | + ({"l_english": ""}, "\ufeffl_english:"), |
| 16 | + ({"\ufeffl_english": ""}, "\ufeffl_english:"), |
| 17 | + ], |
| 18 | + ids=[ |
| 19 | + "Original no BOM, new text no BOM", |
| 20 | + "Original with BOM, new text no BOM", |
| 21 | + "Original no BOM, new text with BOM", |
| 22 | + "Original with BOM, new text with BOM", |
| 23 | + ], |
| 24 | + ) |
| 25 | + def test_almost_empty_original( |
| 26 | + self, tmp_path: Path, input_original_values_by_key: dict[str, str], input_text_content: str |
| 27 | + ): |
7 | 28 | input_source_file_path = tmp_path / "toto_l_english.yml" |
8 | | - input_source_file_path.write_text("l_english:") |
9 | | - input_original_lines_by_key = {"l_english": "l_english:"} |
| 29 | + input_source_file_path.write_text(input_text_content, encoding="utf-8") |
10 | 30 |
|
11 | 31 | output_file_path = tmp_path / "replace toto_l_english.yml" |
12 | | - write_kept_lines(input_source_file_path, output_file_path, input_original_lines_by_key) |
| 32 | + write_kept_lines(input_source_file_path, output_file_path, input_original_values_by_key) |
13 | 33 |
|
14 | | - assert output_file_path.read_text() == "l_english:" |
| 34 | + assert output_file_path.read_text(encoding="utf-8") == input_text_content |
15 | 35 |
|
16 | 36 | def test_new_line(self, tmp_path: Path): |
17 | 37 | input_source_file_path = tmp_path / "toto_l_english.yml" |
18 | | - input_source_file_path.write_text("l_english:\nkey: value") |
19 | | - input_original_lines_by_key = {"l_english": "l_english:"} |
| 38 | + input_source_file_path.write_text('l_english:\nkey: "value"', encoding="utf-8") |
| 39 | + input_original_values_by_key = {"l_english": ""} |
20 | 40 |
|
21 | 41 | output_file_path = tmp_path / "replace toto_l_english.yml" |
22 | | - write_kept_lines(input_source_file_path, output_file_path, input_original_lines_by_key) |
| 42 | + write_kept_lines(input_source_file_path, output_file_path, input_original_values_by_key) |
23 | 43 |
|
24 | | - assert output_file_path.read_text() == "l_english:\nkey: value" |
| 44 | + assert output_file_path.read_text(encoding="utf-8") == 'l_english:\nkey: "value"' |
25 | 45 |
|
26 | 46 | def test_edited_line(self, tmp_path: Path): |
27 | 47 | input_source_file_path = tmp_path / "toto_l_english.yml" |
28 | | - input_source_file_path.write_text("l_english:\nkey: value2") |
29 | | - input_original_lines_by_key = {"l_english": "l_english:", "key": "key: value1"} |
| 48 | + input_source_file_path.write_text('l_english:\nkey: "value2"', encoding="utf-8") |
| 49 | + input_original_values_by_key = {"l_english": "l_english:", "key": "value1"} |
30 | 50 |
|
31 | 51 | output_file_path = tmp_path / "replace toto_l_english.yml" |
32 | | - write_kept_lines(input_source_file_path, output_file_path, input_original_lines_by_key) |
| 52 | + write_kept_lines(input_source_file_path, output_file_path, input_original_values_by_key) |
33 | 53 |
|
34 | | - assert output_file_path.read_text() == "l_english:\nkey: value2" |
| 54 | + assert output_file_path.read_text(encoding="utf-8") == 'l_english:\nkey: "value2"' |
35 | 55 |
|
36 | 56 | def test_unedited_line(self, tmp_path: Path): |
37 | 57 | input_source_file_path = tmp_path / "toto_l_english.yml" |
38 | | - input_source_file_path.write_text("l_english:\nkey: value") |
39 | | - input_original_lines_by_key = {"l_english": "l_english:", "key": "key: value"} |
| 58 | + input_source_file_path.write_text('l_english:\nkey: "value"', encoding="utf-8") |
| 59 | + input_original_values_by_key = {"l_english": "l_english:", "key": "value"} |
40 | 60 |
|
41 | 61 | output_file_path = tmp_path / "replace toto_l_english.yml" |
42 | | - write_kept_lines(input_source_file_path, output_file_path, input_original_lines_by_key) |
| 62 | + write_kept_lines(input_source_file_path, output_file_path, input_original_values_by_key) |
43 | 63 |
|
44 | | - assert output_file_path.read_text() == "l_english:\n" |
| 64 | + assert output_file_path.read_text(encoding="utf-8") == "l_english:\n" |
0 commit comments