]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Python/Python-2.7.2/Lib/distutils/tests/test_text_file.py
c8316360eb1b307b7d07b61c25b6057d9b701041
1 """Tests for distutils.text_file."""
4 from distutils
.text_file
import TextFile
5 from distutils
.tests
import support
6 from test
.test_support
import run_unittest
8 TEST_DATA
= """# test file
12 continues on next line
15 class TextFileTestCase(support
.TempdirManager
, unittest
.TestCase
):
18 # old tests moved from text_file.__main__
19 # so they are really called by the buildbots
21 # result 1: no fancy options
22 result1
= ['# test file\n', '\n', 'line 3 \\\n',
23 '# intervening comment\n',
24 ' continues on next line\n']
26 # result 2: just strip comments
29 " continues on next line\n"]
31 # result 3: just strip blank lines
32 result3
= ["# test file\n",
34 "# intervening comment\n",
35 " continues on next line\n"]
37 # result 4: default, strip comments, blank lines,
38 # and trailing whitespace
39 result4
= ["line 3 \\",
40 " continues on next line"]
42 # result 5: strip comments and blanks, plus join lines (but don't
43 # "collapse" joined lines
44 result5
= ["line 3 continues on next line"]
46 # result 6: strip comments and blanks, plus join lines (and
47 # "collapse" joined lines
48 result6
= ["line 3 continues on next line"]
50 def test_input(count
, description
, file, expected_result
):
51 result
= file.readlines()
52 self
.assertEqual(result
, expected_result
)
54 tmpdir
= self
.mkdtemp()
55 filename
= os
.path
.join(tmpdir
, "test.txt")
56 out_file
= open(filename
, "w")
58 out_file
.write(TEST_DATA
)
62 in_file
= TextFile(filename
, strip_comments
=0, skip_blanks
=0,
63 lstrip_ws
=0, rstrip_ws
=0)
65 test_input(1, "no processing", in_file
, result1
)
69 in_file
= TextFile(filename
, strip_comments
=1, skip_blanks
=0,
70 lstrip_ws
=0, rstrip_ws
=0)
72 test_input(2, "strip comments", in_file
, result2
)
76 in_file
= TextFile(filename
, strip_comments
=0, skip_blanks
=1,
77 lstrip_ws
=0, rstrip_ws
=0)
79 test_input(3, "strip blanks", in_file
, result3
)
83 in_file
= TextFile(filename
)
85 test_input(4, "default processing", in_file
, result4
)
89 in_file
= TextFile(filename
, strip_comments
=1, skip_blanks
=1,
90 join_lines
=1, rstrip_ws
=1)
92 test_input(5, "join lines without collapsing", in_file
, result5
)
96 in_file
= TextFile(filename
, strip_comments
=1, skip_blanks
=1,
97 join_lines
=1, rstrip_ws
=1, collapse_join
=1)
99 test_input(6, "join lines with collapsing", in_file
, result6
)
104 return unittest
.makeSuite(TextFileTestCase
)
106 if __name__
== "__main__":
107 run_unittest(test_suite())