Allow the tests to run outside of the build area
authorJulian Gilbey <jdg@debian.org>
Sun, 14 Aug 2022 07:56:26 +0000 (08:56 +0100)
committerPeter Michael Green <plugwash@raspbian.org>
Sun, 14 Aug 2022 07:56:26 +0000 (08:56 +0100)
Forwarded: not-needed
Last-Update: 2022-07-11

Gbp-Pq: Name allow-non-local-tests.patch

tests_python/debugger_unittest.py
tests_python/test_run.py
tests_python/test_utilities.py

index d7c77546342886b99bb01d8b8a576e9ee87e0dc9..e7f01ce6f692234bdf65bd56cbb4c2a4845735be 100644 (file)
@@ -751,14 +751,12 @@ class AbstractWriterThread(threading.Thread):
         return None
 
     def get_pydevd_file(self):
-        dirname = os.path.dirname(__file__)
-        dirname = os.path.dirname(dirname)
-        return os.path.abspath(os.path.join(dirname, 'pydevd.py'))
+        import pydevd
+        return pydevd.__file__
 
     def get_pydevconsole_file(self):
-        dirname = os.path.dirname(__file__)
-        dirname = os.path.dirname(dirname)
-        return os.path.abspath(os.path.join(dirname, 'pydevconsole.py'))
+        import pydevconsole
+        return pydevconsole.__file__
 
     def get_line_index_with_content(self, line_content, filename=None):
         '''
index 197223cb036a6a6509c451a8b3a0725ca3bb95c2..b6bd0d8a05715963e23fd3a9c827bd97fbadd1af 100644 (file)
@@ -33,11 +33,14 @@ def test_run(testdir_or_pytester):
     foo_module = 'tests_python.resources.launch.foo'
 
     pydevd_dir = os.path.dirname(os.path.dirname(__file__))
-    assert os.path.exists(os.path.join(pydevd_dir, 'pydevd.py'))
+    if os.path.exists(os.path.join(pydevd_dir, 'pydevd.py')):
+        append_path = 'sys.path.append(%r)' % pydevd_dir
+    else:
+        append_path = ''
 
     _run_and_check(testdir_or_pytester, testdir_or_pytester.makepyfile('''
 import sys
-sys.path.append(%(pydevd_dir)r)
+%(append_path)s
 import pydevd
 py_db = pydevd.PyDB()
 py_db.ready_to_run = True
@@ -46,7 +49,7 @@ py_db.run(%(foo_dir)r)
 
     _run_and_check(testdir_or_pytester, testdir_or_pytester.makepyfile('''
 import sys
-sys.path.append(%(pydevd_dir)r)
+%(append_path)s
 import pydevd
 py_db = pydevd.PyDB()
 py_db.run(%(foo_dir)r, set_trace=False)
@@ -58,7 +61,7 @@ py_db.run(%(foo_dir)r, set_trace=False)
 
     _run_and_check(testdir_or_pytester, testdir_or_pytester.makepyfile('''
 import sys
-sys.path.append(%(pydevd_dir)r)
+%(append_path)s
 sys.argv.append('--as-module')
 import pydevd
 py_db = pydevd.PyDB()
@@ -69,7 +72,7 @@ py_db.run(%(foo_module)r, is_module=True)
     _run_and_check(testdir_or_pytester, testdir_or_pytester.makepyfile('''
 import sys
 sys.argv.append('--as-module')
-sys.path.append(%(pydevd_dir)r)
+%(append_path)s
 import pydevd
 py_db = pydevd.PyDB()
 py_db.run(%(foo_module)r, is_module=True, set_trace=False)
@@ -81,7 +84,10 @@ def test_run_on_local_module_without_adding_to_pythonpath(testdir_or_pytester):
     import os
 
     pydevd_dir = os.path.dirname(os.path.dirname(__file__))
-    assert os.path.exists(os.path.join(pydevd_dir, 'pydevd.py'))
+    if os.path.exists(os.path.join(pydevd_dir, 'pydevd.py')):
+        append_path = 'sys.path.append(%r)' % pydevd_dir
+    else:
+        append_path = ''
 
     foo_module = 'local_foo'
     with open(os.path.join(os.getcwd(), 'local_foo.py'), 'w') as stream:
@@ -90,7 +96,7 @@ def test_run_on_local_module_without_adding_to_pythonpath(testdir_or_pytester):
     _run_and_check(testdir_or_pytester, testdir_or_pytester.makepyfile('''
 import sys
 import os
-sys.path.append(%(pydevd_dir)r)
+%(append_path)s
 sys.argv.append('--as-module')
 cwd = os.path.abspath(os.getcwd())
 while cwd in sys.path:
@@ -105,7 +111,7 @@ py_db.run(%(foo_module)r, is_module=True)
 import sys
 import os
 sys.argv.append('--as-module')
-sys.path.append(%(pydevd_dir)r)
+%(append_path)s
 cwd = os.path.abspath(os.getcwd())
 while cwd in sys.path:
     sys.path.remove(cwd)
index b9dfbe33c2e6721ebe0d522610d995f55662a9b0..5b44b592da714cf8b83386c8991e92bfec597948 100644 (file)
@@ -316,7 +316,7 @@ def _build_launch_env():
     cwd = os.path.abspath(os.path.dirname(__file__))
     assert os.path.isdir(cwd)
 
-    resources_dir = os.path.join(os.path.dirname(pydevd.__file__), 'tests_python', 'resources')
+    resources_dir = os.path.join(cwd, 'resources')
     assert os.path.isdir(resources_dir)
 
     attach_to_process_dir = os.path.join(os.path.dirname(pydevd.__file__), 'pydevd_attach_to_process')
@@ -399,7 +399,7 @@ def test_find_main_thread_id():
         cwd=cwd
     )
 
-    resources_dir = os.path.join(os.path.dirname(pydevd.__file__), 'tests_python', 'resources')
+    resources_dir = os.path.join(os.path.dirname(__file__), 'resources')
 
     subprocess.check_call(
         [sys.executable, os.path.join(resources_dir, '_pydevd_test_find_main_thread_id.py') ],