3636# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3737# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3838# SOFTWARE.
39+ import io
3940import os
4041import re
4142import shutil
@@ -87,7 +88,10 @@ class PipPatchingTest(unittest.TestCase):
8788 def setUpClass (cls ):
8889 cls .venv_dir = Path (tempfile .mkdtemp ()).resolve ()
8990 subprocess .check_output ([sys .executable , "-m" , "venv" , str (cls .venv_dir )])
90- cls .venv_python = str (cls .venv_dir / 'bin' / 'python' )
91+ if sys .platform != 'win32' :
92+ cls .venv_python = str (cls .venv_dir / 'bin' / 'python' )
93+ else :
94+ cls .venv_python = str (cls .venv_dir / 'Scripts' / 'python.exe' )
9195 subprocess .check_output ([cls .venv_python , '-m' , 'pip' , 'install' , 'wheel' , 'setuptools' ])
9296 cls .venv_template_dir = f'{ cls .venv_dir } .template'
9397 cls .venv_dir .rename (cls .venv_template_dir )
@@ -157,11 +161,12 @@ def run_venv_pip_install(self, package, extra_env=None, assert_stderr_matches=No
157161 env .update (extra_env )
158162 proc = subprocess .run (
159163 [
160- str (self .venv_dir / 'bin' / 'pip' ),
164+ str (self .venv_python ),
165+ '-m' , 'pip' ,
161166 '--isolated' ,
162167 'install' ,
163168 '--force-reinstall' ,
164- '--find-links' , self .index_dir ,
169+ '--find-links' , str ( self .index_dir ) ,
165170 '--no-index' ,
166171 '--no-cache-dir' ,
167172 package ,
@@ -171,6 +176,7 @@ def run_venv_pip_install(self, package, extra_env=None, assert_stderr_matches=No
171176 env = env ,
172177 universal_newlines = True ,
173178 )
179+ print (proc .stdout )
174180 print (proc .stderr )
175181 assert 'Applying GraalPy patch failed for' not in proc .stderr
176182 if assert_stderr_matches :
@@ -423,19 +429,31 @@ def test_broken_patches_path(self):
423429 def test_patches_file_url (self ):
424430 self .check_installing_with_patch_repo (urljoin ('file:' , pathname2url (str (self .patch_dir .absolute ()))))
425431
426- @unittest .skipIf (
427- __graalpython__ .posix_module_backend () == 'java' ,
428- "Server doesn't work properly under Java posix backend"
429- )
430432 def test_patches_http_url (self ):
431433 patch_dir = self .patch_dir
432434
433435 class Handler (SimpleHTTPRequestHandler ):
434436 def __init__ (self , * args , ** kwargs ):
435437 super ().__init__ (* args , directory = str (patch_dir ), ** kwargs )
436438
439+ def do_GET (self ):
440+ f = self .send_head ()
441+ if f :
442+ try :
443+ input_file = io .TextIOWrapper (f )
444+ # Always serve UTF-8 with unix line endings regardless of platform
445+ # to emulate what GitHub would serve from a patch branch
446+ output_file = io .TextIOWrapper (self .wfile , encoding = 'utf-8' , newline = '\n ' )
447+ shutil .copyfileobj (input_file , output_file )
448+ output_file .flush ()
449+ finally :
450+ f .close ()
451+
437452 try :
438453 with HTTPServer (('localhost' , 0 ), Handler ) as server :
454+ if not server .server_port :
455+ # Workaround for java posix backend limitation
456+ server .server_port = server .socket .getsockname ()[1 ]
439457 thread = threading .Thread (target = server .serve_forever )
440458 thread .start ()
441459 try :
0 commit comments