forked from umple/umple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImportModules.py
36 lines (29 loc) · 960 Bytes
/
ImportModules.py
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
import unittest
# Import source generated test files
import os, sys, inspect
import importlib
def importModules(modules, local_path):
# Get current folder
current_dir = os.path.dirname(
os.path.abspath(inspect.getfile(inspect.currentframe()))
)
# Go up one folder
parent_dir = os.path.dirname(current_dir)
path_separator = ""
if os.name == "nt":
parent_dir += "\\src-gen-umple\\cruise\\"
path_separator = "\\"
else:
parent_dir += "/src-gen-umple/cruise/"
path_separator = "/"
# OS specific folder locations
while len(local_path) > 0:
parent_dir += local_path.pop(0)
if len(local_path) > 0:
parent_dir += path_separator
sys.path.insert(0, parent_dir)
for m in modules:
try:
globals()[m] = importlib.import_module(m)
except Exception as e:
raise ImportError("Error occurred importing module: " + m)