File: 0001-Allow-tests-to-run-with-non-default-Python.patch

package info (click to toggle)
plastex 3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,132 kB
  • sloc: python: 23,341; xml: 18,076; javascript: 7,755; ansic: 46; makefile: 40; sh: 26
file content (81 lines) | stat: -rw-r--r-- 2,582 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
From: Debian Python Team <team+python@tracker.debian.org>
Date: Mon, 11 Nov 2024 17:14:38 +1100
Subject: Allow tests to run with non-default Python

---
 unittests/CustomRenderer.py  | 18 ++++++++++++++----
 unittests/FunctionalTests.py | 11 +++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/unittests/CustomRenderer.py b/unittests/CustomRenderer.py
index c5db320..5df9650 100644
--- a/unittests/CustomRenderer.py
+++ b/unittests/CustomRenderer.py
@@ -3,7 +3,6 @@ import subprocess
 from pathlib import Path
 
 plastex_dir = str(Path(__file__).absolute().parent.parent)
-sys.path.append(plastex_dir)
 
 def test_custom_renderer(tmpdir):
     try:
@@ -31,7 +30,14 @@ class Renderer(BaseRenderer):
 """)
 
 
-    os.environ["PYTHONPATH"] = plastex_dir
+    ppath = ':'.join([
+        os.environ.get('PYTHONPATH', ''),
+        str(plastex_dir),
+        str(tmpdir)
+    ])
+    env = os.environ.copy()
+    env['PYTHONPATH'] = ppath
+
     # We check the return code manually instead of setting check=True for more
     # readable error
     ret = subprocess.run(["plastex", "--renderer=CustomRenderer", "test.tex"], cwd=str(tmpdir), check=False)
@@ -61,8 +67,12 @@ class Renderer(BaseRenderer):
 \end{document}
 """)
 
-    ppath = ':'.join(sys.path + [str(tmpdir)])
-    env = os.environ
+    ppath = ':'.join([
+        os.environ.get('PYTHONPATH', ''),
+        str(plastex_dir),
+        str(tmpdir)
+    ])
+    env = os.environ.copy()
     env['PYTHONPATH'] = ppath
     # We check the return code manually instead of setting check=True for more
     # readable error
diff --git a/unittests/FunctionalTests.py b/unittests/FunctionalTests.py
index 7230085..1e2fa80 100755
--- a/unittests/FunctionalTests.py
+++ b/unittests/FunctionalTests.py
@@ -22,6 +22,9 @@ from pathlib import Path
 import pytest
 
 
+plastex_dir = str(Path(__file__).absolute().parent.parent)
+
+
 def which(name, path=None, exts=('',)):
     """
     Search PATH for a binary.
@@ -51,6 +54,14 @@ class Process(object):
             kwargs['stdout'] = subprocess.PIPE
         if 'stderr' not in kwargs:
             kwargs['stderr'] = subprocess.STDOUT
+        if 'env' not in kwargs:
+            ppath = ':'.join([
+                os.environ.get('PYTHONPATH', ''),
+                str(plastex_dir),
+            ])
+            env = os.environ.copy()
+            env['PYTHONPATH'] = ppath
+            kwargs['env'] = env
         self.process = subprocess.Popen(args, **kwargs)
         self.log = self.process.stdout.read().decode('utf8')
         self.process.wait()