distribute / setuptools / tests / win_script_wrapper.txt

The branch 'default' does not exist.
Diff from to

setuptools/tests/win_script_wrapper.txt

     >>> import os, sys, tempfile
     >>> from setuptools.command.easy_install import nt_quote_arg
     >>> sample_directory = tempfile.mkdtemp()
-    >>> open(os.path.join(sample_directory, 'foo-script.py'), 'w').write(
+    >>> f = open(os.path.join(sample_directory, 'foo-script.py'), 'w')
+    >>> f.write(
     ... """#!%(python_exe)s
     ... import sys
     ... input = repr(sys.stdin.read())
     ... if __debug__:
     ...     print 'non-optimized'
     ... """ % dict(python_exe=nt_quote_arg(sys.executable)))
+    >>> f.close()
 
 Note that the script starts with a Unix-style '#!' line saying which
 Python executable to run.  The wrapper will use this to find the
 We'll also copy cli.exe to the sample-directory with the name foo.exe:
 
     >>> import pkg_resources
-    >>> open(os.path.join(sample_directory, 'foo.exe'), 'wb').write(
+    >>> f = open(os.path.join(sample_directory, 'foo.exe'), 'wb')
+    >>> f.write(
     ...     pkg_resources.resource_string('setuptools', 'cli.exe')
     ...     )
+    >>> f.close()
 
 When the copy of cli.exe, foo.exe in this example, runs, it examines
 the path name it was run with and computes a Python script path name
 options as usual. For example, to run in optimized mode and
 enter the interpreter after running the script, you could use -Oi:
 
-    >>> open(os.path.join(sample_directory, 'foo-script.py'), 'w').write(
+    >>> f = open(os.path.join(sample_directory, 'foo-script.py'), 'w')
+    >>> f.write(
     ... """#!%(python_exe)s  -Oi  
     ... import sys
     ... input = repr(sys.stdin.read())
     ...     print 'non-optimized'
     ... sys.ps1 = '---'
     ... """ % dict(python_exe=nt_quote_arg(sys.executable)))
+    >>> f.close()
 
     >>> input, output = os.popen4(nt_quote_arg(os.path.join(sample_directory, 'foo.exe')))
     >>> input.close()
     >>> import os, sys, tempfile
     >>> from setuptools.command.easy_install import nt_quote_arg
     >>> sample_directory = tempfile.mkdtemp()
-    >>> open(os.path.join(sample_directory, 'bar-script.pyw'), 'w').write(
+    >>> f = open(os.path.join(sample_directory, 'bar-script.pyw'), 'w')
+    >>> f.write(
     ... """#!%(python_exe)s
     ... import sys
-    ... open(sys.argv[1], 'wb').write(repr(sys.argv[2]))
+    ... f = open(sys.argv[1], 'wb')
+    ... f.write(repr(sys.argv[2]))
+    ... f.close()
     ... """ % dict(python_exe=nt_quote_arg(sys.executable)))
+    >>> f.close()
 
 We'll also copy gui.exe to the sample-directory with the name bar.exe:
 
     >>> import pkg_resources
-    >>> open(os.path.join(sample_directory, 'bar.exe'), 'wb').write(
+    >>> f = open(os.path.join(sample_directory, 'bar.exe'), 'wb')
+    >>> f.write(
     ...     pkg_resources.resource_string('setuptools', 'gui.exe')
     ...     )
+    >>> f.close()
 
 Finally, we'll run the script and check the result:
 
     >>> input.close()
     >>> print output.read()
     <BLANKLINE>
-    >>> print open(os.path.join(sample_directory, 'test_output.txt'), 'rb').read()
+    >>> f = open(os.path.join(sample_directory, 'test_output.txt'), 'rb')
+    >>> print f.read()
     'Test Argument'
+    >>> f.close()
 
 
 We're done with the sample_directory:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.