summaryrefslogtreecommitdiff
blob: 203e34c838f18f2a581f891ec1c2b5cec4203205 (plain)
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
Upstream-PR: https://github.com/manugarg/pacparser/pull/137
From 351b8f837ebbdf6e6fa4978a70287899436890eb Mon Sep 17 00:00:00 2001
From: orbea <orbea@riseup.net>
Date: Sat, 14 May 2022 01:46:25 -0700
Subject: [PATCH] tests: Fix python path in runtests.py

In Gentoo the runtests.py script fails when it fails to determine the
pacparser path.

This happens because 'py_ver' expands to '3.9' when the expected
directory ends in '39'. This can be solved by replacing any periods in
the string.

python ../tests/runtests.py
Traceback (most recent call last):
  File "/tmp/pacparser/src/../tests/runtests.py", line 31, in runtests
    pacparser_module_path = glob.glob(os.path.join(
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/pacparser/src/../tests/runtests.py", line 81, in <module>
    main()
  File "/tmp/pacparser/src/../tests/runtests.py", line 78, in main
    runtests(pacfile, testdata, tests_dir)
  File "/tmp/pacparser/src/../tests/runtests.py", line 34, in runtests
    raise Exception('Tests failed. Could not determine pacparser path.')
Exception: Tests failed. Could not determine pacparser path.
---
 tests/runtests.py | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/tests/runtests.py b/tests/runtests.py
index 9760300..a5377d1 100644
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -26,10 +26,20 @@
 import sys
 
 def runtests(pacfile, testdata, tests_dir):
-  py_ver = '.'.join([str(x) for x in sys.version_info[0:2]])
+  ver = '.'.join([str(x) for x in sys.version_info[0:2]])
+  py_ver = [ver, ver.replace('.', '')]
   try:
-    pacparser_module_path = glob.glob(os.path.join(
-      tests_dir, '..', 'src', 'pymod', 'build', 'lib*%s' % py_ver))[0]
+    module_path = glob.glob(os.path.join(
+      tests_dir, '..', 'src', 'pymod', 'build', 'lib*'))
+    module_found = False
+    for module in module_path:
+      for version in py_ver:
+        if module.endswith(version):
+          module_found = True
+          break
+      if module_found:
+        pacparser_module_path = module
+        break
   except Exception:
     raise Exception('Tests failed. Could not determine pacparser path.')
   if 'DEBUG' in os.environ: print('Pacparser module path: %s' %