Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Side by Side Diff: Lib/test/test_support.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_subprocess.py ('k') | Lib/test/test_sys.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2
3 import sys
4 import os
5 import unittest
6 import socket
7 import tempfile
8 import errno
9 from test import support
10
11 TESTFN = support.TESTFN
12 TESTDIRN = os.path.basename(tempfile.mkdtemp(dir='.'))
13
14
15 class TestSupport(unittest.TestCase):
16 def setUp(self):
17 support.unlink(TESTFN)
18 support.rmtree(TESTDIRN)
19 tearDown = setUp
20
21 def test_import_module(self):
22 support.import_module("ftplib")
23 self.assertRaises(unittest.SkipTest, support.import_module, "foo")
24
25 def test_import_fresh_module(self):
26 support.import_fresh_module("ftplib")
27
28 def test_get_attribute(self):
29 self.assertEqual(support.get_attribute(self, "test_get_attribute"),
30 self.test_get_attribute)
31 self.assertRaises(unittest.SkipTest, support.get_attribute, self, "foo")
32
33 @unittest.skip("failing buildbots")
34 def test_get_original_stdout(self):
35 self.assertEqual(support.get_original_stdout(), sys.stdout)
36
37 def test_unload(self):
38 import sched
39 self.assertIn("sched", sys.modules)
40 support.unload("sched")
41 self.assertNotIn("sched", sys.modules)
42
43 def test_unlink(self):
44 with open(TESTFN, "w") as f:
45 pass
46 support.unlink(TESTFN)
47 self.assertFalse(os.path.exists(TESTFN))
48 support.unlink(TESTFN)
49
50 def test_rmtree(self):
51 os.mkdir(TESTDIRN)
52 os.mkdir(os.path.join(TESTDIRN, TESTDIRN))
53 support.rmtree(TESTDIRN)
54 self.assertFalse(os.path.exists(TESTDIRN))
55 support.rmtree(TESTDIRN)
56
57 def test_forget(self):
58 import smtplib
59 support.forget("smtplib")
60 self.assertNotIn("smtplib", sys.modules)
61
62 def test_HOST(self):
63 s = socket.socket()
64 s.bind((support.HOST, 0))
65 s.close()
66
67 def test_find_unused_port(self):
68 port = support.find_unused_port()
69 s = socket.socket()
70 s.bind((support.HOST, port))
71 s.close()
72
73 def test_bind_port(self):
74 s = socket.socket()
75 support.bind_port(s)
76 s.listen(1)
77 s.close()
78
79 def test_temp_cwd(self):
80 here = os.getcwd()
81 with support.temp_cwd(name=TESTFN):
82 self.assertEqual(os.path.basename(os.getcwd()), TESTFN)
83 self.assertFalse(os.path.exists(TESTFN))
84 self.assertTrue(os.path.basename(os.getcwd()), here)
85
86 def test_sortdict(self):
87 self.assertEqual(support.sortdict({3:3, 2:2, 1:1}), "{1: 1, 2: 2, 3: 3}" )
88
89 def test_make_bad_fd(self):
90 fd = support.make_bad_fd()
91 with self.assertRaises(OSError) as cm:
92 os.write(fd, b"foo")
93 self.assertEqual(cm.exception.errno, errno.EBADF)
94
95 def test_check_syntax_error(self):
96 support.check_syntax_error(self, "def class")
97 self.assertRaises(AssertionError, support.check_syntax_error, self, "1")
98
99 def test_CleanImport(self):
100 import importlib
101 with support.CleanImport("asyncore"):
102 importlib.import_module("asyncore")
103
104 def test_DirsOnSysPath(self):
105 with support.DirsOnSysPath('foo', 'bar'):
106 self.assertIn("foo", sys.path)
107 self.assertIn("bar", sys.path)
108 self.assertNotIn("foo", sys.path)
109 self.assertNotIn("bar", sys.path)
110
111 def test_captured_stdout(self):
112 with support.captured_stdout() as s:
113 print("hello")
114 self.assertEqual(s.getvalue(), "hello\n")
115
116 def test_captured_stderr(self):
117 with support.captured_stderr() as s:
118 print("hello", file=sys.stderr)
119 self.assertEqual(s.getvalue(), "hello\n")
120
121 def test_captured_stdin(self):
122 with support.captured_stdin() as s:
123 print("hello", file=sys.stdin)
124 self.assertEqual(s.getvalue(), "hello\n")
125
126 def test_gc_collect(self):
127 support.gc_collect()
128
129 def test_python_is_optimized(self):
130 self.assertIsInstance(support.python_is_optimized(), bool)
131
132 def test_swap_attr(self):
133 class Obj:
134 x = 1
135 obj = Obj()
136 with support.swap_attr(obj, "x", 5):
137 self.assertEqual(obj.x, 5)
138 self.assertEqual(obj.x, 1)
139
140 def test_swap_item(self):
141 D = {"item":1}
142 with support.swap_item(D, "item", 5):
143 self.assertEqual(D["item"], 5)
144 self.assertEqual(D["item"], 1)
145
146 # XXX -follows a list of untested API
147 # make_legacy_pyc
148 # is_resource_enabled
149 # requires
150 # fcmp
151 # umaks
152 # findfile
153 # check_warnings
154 # EnvironmentVarGuard
155 # TransientResource
156 # transient_internet
157 # run_with_locale
158 # set_memlimit
159 # bigmemtest
160 # precisionbigmemtest
161 # bigaddrspacetest
162 # requires_resource
163 # run_doctest
164 # threading_cleanup
165 # reap_threads
166 # reap_children
167 # strip_python_stderr
168 # args_from_interpreter_flags
169 # can_symlink
170 # skip_unless_symlink
171
172
173 def test_main():
174 tests = [TestSupport]
175 support.run_unittest(*tests)
176
177 if __name__ == '__main__':
178 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_subprocess.py ('k') | Lib/test/test_sys.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+