11# Copyright (c) 2021, Thomas Aglassinger
22# All rights reserved. Distributed under the BSD 3-Clause License.
3- from unittest import TestCase
3+ import pytest
44
55from sanpo .sanitize import sanitize_file , sanitized_lines
66from tests ._common import PoFileTest
77
88
9- class SanitizationTest ( TestCase ):
10- def test_can_remove_pointless_lines ( self ):
11- source_lines = [
12- r'"Project-Id-Version: PACKAGE VERSION \n"' ,
13- r'"Report-Msgid-Bugs-To: \n"' ,
14- r'"POT-Creation -Date: 2021-01-01\\n"' ,
15- r'"PO-Revision-Date: 2021-01-01\ \n"' ,
16- r'"Last-Translator: FULL NAME EMAIL@ADDRESS \n"' ,
17- r'"Language-Team: LANGUAGE [email protected] \n"' ,
18- "PRESERVE" ,
19- ]
20- self . assertEqual ( list ( sanitized_lines ( source_lines )), [ "PRESERVE" ])
21-
22- def test_can_preserve_metadata_lines (self ):
23- source_lines = [
24- r'"Project-Id-Version: some 1.2.3\n"' ,
25- r'"Report-Msgid-Bugs-To: [email protected] \n"' ,
26- r'"Last-Translator: John Doe [email protected] \n"' ,
27- r'"Language-Team: en [email protected] \n"' ,
28- ]
29- self . assertEqual ( list (sanitized_lines (source_lines )), source_lines )
9+ def test_can_remove_pointless_lines ( ):
10+ source_lines = [
11+ r'"Project-Id-Version: PACKAGE VERSION\n"' ,
12+ r'"Report-Msgid-Bugs-To: \n"' ,
13+ r'"POT-Creation-Date: 2021-01-01\ \n"' ,
14+ r'"PO-Revision -Date: 2021-01-01\\n"' ,
15+ r'"Last-Translator: FULL NAME EMAIL@ADDRESS \n"' ,
16+ r'"Language-Team: LANGUAGE [email protected] \n"' ,
17+ "PRESERVE" ,
18+ ]
19+ assert list ( sanitized_lines ( source_lines )) == [ "PRESERVE" ]
20+
21+
22+ def test_can_preserve_metadata_lines ():
23+ source_lines = [
24+ r'"Project-Id-Version: some 1.2.3\n"' ,
25+ r'"Report-Msgid-Bugs-To: [email protected] \n"' ,
26+ r'"Last-Translator: John Doe [email protected] \n"' ,
27+ r'"Language-Team: en [email protected] \n"' ,
28+ ]
29+ assert list (sanitized_lines (source_lines )) == source_lines
3030
3131
3232class TransformFileTest (PoFileTest ):
@@ -35,4 +35,16 @@ def test_can_remove_pointless_lines_in_file(self):
3535 initial_po_lines = self .po_lines ()
3636 sanitize_file (self .po_path )
3737 transformed_po_lines = self .po_lines ()
38- self .assertNotEqual (initial_po_lines , transformed_po_lines )
38+ assert initial_po_lines != transformed_po_lines
39+
40+ def test_can_sanitize_str_path (self ):
41+ self .write_po_file (self .test_can_sanitize_str_path .__name__ )
42+ initial_po_lines = self .po_lines ()
43+ sanitize_file (str (self .po_path ))
44+ transformed_po_lines = self .po_lines ()
45+ assert initial_po_lines != transformed_po_lines
46+
47+
48+ def test_fails_on_int_po_file ():
49+ with pytest .raises (TypeError , match = "po_path must be a Path or str, but is <class 'int'>: 123" ):
50+ sanitize_file (123 )
0 commit comments