Ticket #5129: py3-execfile-5129.apply-to-r33601.diff
| File py3-execfile-5129.apply-to-r33601.diff, 3.0 KB (added by allenap, 13 months ago) |
|---|
-
twisted/test/test_compat.py
206 206 Tests for the Python 3-friendly L{execfile} implementation. 207 207 """ 208 208 209 def setUp(self): 210 self.script = FilePath(self.mktemp()) 211 self.script.setContent("foo += 1\n") 209 def writeScript(self, content): 210 """ 211 Write L{content} to a new temporary file, returning the L{FilePath} 212 for the new file. 213 """ 214 script = FilePath(self.mktemp()) 215 script.setContent(content.encode("ascii")) 216 return script 212 217 213 218 214 219 def test_execfileGlobals(self): 215 220 """ 216 221 L{execfile} executes the specified file in the given global namespace. 217 222 """ 223 script = self.writeScript("foo += 1\n") 218 224 globalNamespace = {"foo": 1} 219 execfile(s elf.script.path, globalNamespace)225 execfile(script.path, globalNamespace) 220 226 self.assertEqual(2, globalNamespace["foo"]) 221 227 222 228 … … 225 231 L{execfile} executes the specified file in the given global and local 226 232 namespaces. 227 233 """ 234 script = self.writeScript("foo += 1\n") 228 235 globalNamespace = {"foo": 10} 229 236 localNamespace = {"foo": 20} 230 execfile(s elf.script.path, globalNamespace, localNamespace)237 execfile(script.path, globalNamespace, localNamespace) 231 238 self.assertEqual(10, globalNamespace["foo"]) 232 239 self.assertEqual(21, localNamespace["foo"]) 240 241 242 def test_execfileUniversalNewlines(self): 243 """ 244 L{execfile} reads in the specified file using universal newlines so 245 that scripts written on one platform will work on another. 246 """ 247 for lineEnding in "\n", "\r", "\r\n": 248 script = self.writeScript("foo = 'okay'" + lineEnding) 249 globalNamespace = {"foo": None} 250 execfile(script.path, globalNamespace) 251 self.assertEqual("okay", globalNamespace["foo"]) -
twisted/python/compat.py
191 191 """ 192 192 if locals is None: 193 193 locals = globals 194 fin = open(filename, "rb ")194 fin = open(filename, "rbU") 195 195 try: 196 196 source = fin.read() 197 197 finally: -
twisted/python/test/test_dist.py
79 79 def writeSetup(self, name, *path): 80 80 """ 81 81 Write out a C{setup.py} file to a location determined by 82 L{self.basedir} and L{path}. L{self.setup _template} is used to82 L{self.basedir} and L{path}. L{self.setupTemplate} is used to 83 83 generate its contents. 84 84 """ 85 85 outdir = self.basedir.descendant(path)
