]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Lib/distutils/tests/test_text_file.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / distutils / tests / test_text_file.py
CommitLineData
4710c53d 1"""Tests for distutils.text_file."""\r
2import os\r
3import unittest\r
4from distutils.text_file import TextFile\r
5from distutils.tests import support\r
6from test.test_support import run_unittest\r
7\r
8TEST_DATA = """# test file\r
9\r
10line 3 \\\r
11# intervening comment\r
12 continues on next line\r
13"""\r
14\r
15class TextFileTestCase(support.TempdirManager, unittest.TestCase):\r
16\r
17 def test_class(self):\r
18 # old tests moved from text_file.__main__\r
19 # so they are really called by the buildbots\r
20\r
21 # result 1: no fancy options\r
22 result1 = ['# test file\n', '\n', 'line 3 \\\n',\r
23 '# intervening comment\n',\r
24 ' continues on next line\n']\r
25\r
26 # result 2: just strip comments\r
27 result2 = ["\n",\r
28 "line 3 \\\n",\r
29 " continues on next line\n"]\r
30\r
31 # result 3: just strip blank lines\r
32 result3 = ["# test file\n",\r
33 "line 3 \\\n",\r
34 "# intervening comment\n",\r
35 " continues on next line\n"]\r
36\r
37 # result 4: default, strip comments, blank lines,\r
38 # and trailing whitespace\r
39 result4 = ["line 3 \\",\r
40 " continues on next line"]\r
41\r
42 # result 5: strip comments and blanks, plus join lines (but don't\r
43 # "collapse" joined lines\r
44 result5 = ["line 3 continues on next line"]\r
45\r
46 # result 6: strip comments and blanks, plus join lines (and\r
47 # "collapse" joined lines\r
48 result6 = ["line 3 continues on next line"]\r
49\r
50 def test_input(count, description, file, expected_result):\r
51 result = file.readlines()\r
52 self.assertEqual(result, expected_result)\r
53\r
54 tmpdir = self.mkdtemp()\r
55 filename = os.path.join(tmpdir, "test.txt")\r
56 out_file = open(filename, "w")\r
57 try:\r
58 out_file.write(TEST_DATA)\r
59 finally:\r
60 out_file.close()\r
61\r
62 in_file = TextFile(filename, strip_comments=0, skip_blanks=0,\r
63 lstrip_ws=0, rstrip_ws=0)\r
64 try:\r
65 test_input(1, "no processing", in_file, result1)\r
66 finally:\r
67 in_file.close()\r
68\r
69 in_file = TextFile(filename, strip_comments=1, skip_blanks=0,\r
70 lstrip_ws=0, rstrip_ws=0)\r
71 try:\r
72 test_input(2, "strip comments", in_file, result2)\r
73 finally:\r
74 in_file.close()\r
75\r
76 in_file = TextFile(filename, strip_comments=0, skip_blanks=1,\r
77 lstrip_ws=0, rstrip_ws=0)\r
78 try:\r
79 test_input(3, "strip blanks", in_file, result3)\r
80 finally:\r
81 in_file.close()\r
82\r
83 in_file = TextFile(filename)\r
84 try:\r
85 test_input(4, "default processing", in_file, result4)\r
86 finally:\r
87 in_file.close()\r
88\r
89 in_file = TextFile(filename, strip_comments=1, skip_blanks=1,\r
90 join_lines=1, rstrip_ws=1)\r
91 try:\r
92 test_input(5, "join lines without collapsing", in_file, result5)\r
93 finally:\r
94 in_file.close()\r
95\r
96 in_file = TextFile(filename, strip_comments=1, skip_blanks=1,\r
97 join_lines=1, rstrip_ws=1, collapse_join=1)\r
98 try:\r
99 test_input(6, "join lines with collapsing", in_file, result6)\r
100 finally:\r
101 in_file.close()\r
102\r
103def test_suite():\r
104 return unittest.makeSuite(TextFileTestCase)\r
105\r
106if __name__ == "__main__":\r
107 run_unittest(test_suite())\r