aboutsummaryrefslogtreecommitdiff
path: root/unittests/helpers.py
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/helpers.py')
-rw-r--r--unittests/helpers.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/unittests/helpers.py b/unittests/helpers.py
index ac9d980..d3d1560 100644
--- a/unittests/helpers.py
+++ b/unittests/helpers.py
@@ -5,6 +5,7 @@ import unittest
import functools
import re
import typing as T
+import zipfile
from pathlib import Path
from contextlib import contextmanager
@@ -176,6 +177,22 @@ def get_rpath(fname: str) -> T.Optional[str]:
return None
return final
+def get_classpath(fname: str) -> T.Optional[str]:
+ with zipfile.ZipFile(fname) as zip:
+ with zip.open('META-INF/MANIFEST.MF') as member:
+ contents = member.read().decode().strip()
+ lines = []
+ for line in contents.splitlines():
+ if line.startswith(' '):
+ # continuation line
+ lines[-1] += line[1:]
+ else:
+ lines.append(line)
+ manifest = {
+ k.lower(): v.strip() for k, v in [l.split(':', 1) for l in lines]
+ }
+ return manifest.get('class-path')
+
def get_path_without_cmd(cmd: str, path: str) -> str:
pathsep = os.pathsep
paths = OrderedSet([Path(p).resolve() for p in path.split(pathsep)])