CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
test_text_file.py128 linesDownload Raw Back to tests
1"""Tests for distutils.text_file."""2 3from distutils.tests import support4from distutils.text_file import TextFile5 6import jaraco.path7import path8 9TEST_DATA = """# test file10 11line 3 \\12# intervening comment13  continues on next line14"""15 16 17class TestTextFile(support.TempdirManager):18    def test_class(self):19        # old tests moved from text_file.__main__20        # so they are really called by the buildbots21 22        # result 1: no fancy options23        result1 = [24            '# test file\n',25            '\n',26            'line 3 \\\n',27            '# intervening comment\n',28            '  continues on next line\n',29        ]30 31        # result 2: just strip comments32        result2 = ["\n", "line 3 \\\n", "  continues on next line\n"]33 34        # result 3: just strip blank lines35        result3 = [36            "# test file\n",37            "line 3 \\\n",38            "# intervening comment\n",39            "  continues on next line\n",40        ]41 42        # result 4: default, strip comments, blank lines,43        # and trailing whitespace44        result4 = ["line 3 \\", "  continues on next line"]45 46        # result 5: strip comments and blanks, plus join lines (but don't47        # "collapse" joined lines48        result5 = ["line 3   continues on next line"]49 50        # result 6: strip comments and blanks, plus join lines (and51        # "collapse" joined lines52        result6 = ["line 3 continues on next line"]53 54        def test_input(count, description, file, expected_result):55            result = file.readlines()56            assert result == expected_result57 58        tmp_path = path.Path(self.mkdtemp())59        filename = tmp_path / 'test.txt'60        jaraco.path.build({filename.name: TEST_DATA}, tmp_path)61 62        in_file = TextFile(63            filename,64            strip_comments=False,65            skip_blanks=False,66            lstrip_ws=False,67            rstrip_ws=False,68        )69        try:70            test_input(1, "no processing", in_file, result1)71        finally:72            in_file.close()73 74        in_file = TextFile(75            filename,76            strip_comments=True,77            skip_blanks=False,78            lstrip_ws=False,79            rstrip_ws=False,80        )81        try:82            test_input(2, "strip comments", in_file, result2)83        finally:84            in_file.close()85 86        in_file = TextFile(87            filename,88            strip_comments=False,89            skip_blanks=True,90            lstrip_ws=False,91            rstrip_ws=False,92        )93        try:94            test_input(3, "strip blanks", in_file, result3)95        finally:96            in_file.close()97 98        in_file = TextFile(filename)99        try:100            test_input(4, "default processing", in_file, result4)101        finally:102            in_file.close()103 104        in_file = TextFile(105            filename,106            strip_comments=True,107            skip_blanks=True,108            join_lines=True,109            rstrip_ws=True,110        )111        try:112            test_input(5, "join lines without collapsing", in_file, result5)113        finally:114            in_file.close()115 116        in_file = TextFile(117            filename,118            strip_comments=True,119            skip_blanks=True,120            join_lines=True,121            rstrip_ws=True,122            collapse_join=True,123        )124        try:125            test_input(6, "join lines with collapsing", in_file, result6)126        finally:127            in_file.close()128 
Aluode/PerceptionLabPortable · CoolFace