diff options
| author | Arfrever Frehtes Taifersar Arahesis <Arfrever.FTA@GMail.Com> | 2012-12-29 06:23:09 +0100 |
|---|---|---|
| committer | Arfrever Frehtes Taifersar Arahesis <Arfrever.FTA@GMail.Com> | 2012-12-29 06:23:09 +0100 |
| commit | 721559fe76a1cda3de639ee2aaa446595169d26b (patch) | |
| tree | a33afb83c609e4124c7f78fa79ded12f9f139f8a /setuptools/tests/win_script_wrapper.txt | |
| parent | 5f6ebc0579291a7dd316e2a64466e688ef7bdb69 (diff) | |
| download | external_python_setuptools-721559fe76a1cda3de639ee2aaa446595169d26b.tar.gz external_python_setuptools-721559fe76a1cda3de639ee2aaa446595169d26b.tar.bz2 external_python_setuptools-721559fe76a1cda3de639ee2aaa446595169d26b.zip | |
Fix some ResourceWarnings.
--HG--
branch : distribute
extra : rebase_source : 31ac3f0135d8cfe0fabc274f1649d1c99eba2868
Diffstat (limited to 'setuptools/tests/win_script_wrapper.txt')
| -rw-r--r-- | setuptools/tests/win_script_wrapper.txt | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/setuptools/tests/win_script_wrapper.txt b/setuptools/tests/win_script_wrapper.txt index 2e1bff74..9f7c81d6 100644 --- a/setuptools/tests/win_script_wrapper.txt +++ b/setuptools/tests/win_script_wrapper.txt @@ -16,7 +16,8 @@ Let's create a simple script, foo-script.py: >>> 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()) @@ -26,6 +27,7 @@ Let's create a simple script, foo-script.py: ... 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 @@ -34,9 +36,11 @@ correct Python executable. 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 @@ -77,7 +81,8 @@ to start the interactive interpreter. You can combine multiple 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()) @@ -88,6 +93,7 @@ enter the interpreter after running the script, you could use -Oi: ... 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() @@ -105,18 +111,24 @@ Now let's test the GUI version with the simple scipt, bar-script.py: >>> 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: @@ -126,8 +138,10 @@ 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: |
