1
- import pymdlsdk
1
+ import unittest
2
2
import os
3
3
4
+ # local testing only
5
+ import pymdlsdk
6
+ BindingModuleName : str = 'pymdlsdk'
7
+ BindingModule = pymdlsdk
8
+
9
+ # the unittest base class, in case testing system already needs a specializing
10
+ UnittestFrameworkBase = unittest .TestCase
11
+
12
+
4
13
class SDK ():
5
14
neuray : pymdlsdk .INeuray = None
6
15
transaction : pymdlsdk .ITransaction = None
7
16
mdlFactory : pymdlsdk .IMdl_factory = None
8
17
9
-
10
18
def _get_examples_search_path (self ):
11
19
"""Try to get the example search path or returns 'mdl' sub folder of the current directory if it failed."""
12
20
@@ -28,7 +36,6 @@ def _get_examples_search_path(self):
28
36
29
37
return os .path .abspath (example_sp )
30
38
31
-
32
39
def load (self , addExampleSearchPath : bool = True , loadImagePlugins : bool = True , loadDistillerPlugin : bool = False ):
33
40
"""Initialize the SDK and get some common interface for basic testing"""
34
41
@@ -61,6 +68,7 @@ def load(self, addExampleSearchPath: bool = True, loadImagePlugins: bool = True,
61
68
raise Exception ('Failed to load the \' mdl_distiller\' plugin.' )
62
69
63
70
# start neuray
71
+ print (f"Starting neuray of version: { self .neuray .get_version ()} " )
64
72
resultCode = self .neuray .start ()
65
73
if resultCode != 0 :
66
74
raise Exception ('Failed to initialize the SDK. Result code: ' + resultCode )
@@ -79,51 +87,10 @@ def unload(self, commitTransaction: bool = True):
79
87
self .transaction .commit ()
80
88
self .transaction = None
81
89
self .mdlFactory = None
90
+ self .neuray .shutdown ()
82
91
self .neuray = None
83
92
pymdlsdk ._print_open_handle_statistic ()
84
93
85
94
# Unload the MDL SDK
86
95
if not pymdlsdk .unload ():
87
96
raise Exception ('Failed to unload the SDK.' )
88
-
89
- def log_context_messages (self , context : pymdlsdk .IMdl_execution_context ) -> bool :
90
- """print all messages from the context. Return false if there have been errors"""
91
- if context .get_messages_count () == 0 :
92
- return True
93
- hasErrors : bool = context .get_error_messages_count () > 0
94
- for i in range (context .get_messages_count ()):
95
- message : pymdlsdk .IMessage = context .get_message (i )
96
- level : str = " "
97
- if message .get_severity () == 0 : # pymdlsdk.MESSAGE_SEVERITY_FATAL
98
- level = "fatal: "
99
- hasErrors = True
100
- elif message .get_severity () == 1 : # pymdlsdk.MESSAGE_SEVERITY_ERROR
101
- level = "error: "
102
- hasErrors = True
103
- elif message .get_severity () == 2 : # pymdlsdk.MESSAGE_SEVERITY_WARNING
104
- level = "warning: "
105
- elif message .get_severity () == 3 : # pymdlsdk.MESSAGE_SEVERITY_INFO
106
- level = "info: "
107
- elif message .get_severity () == 4 : # pymdlsdk.MESSAGE_SEVERITY_VERBOSE
108
- level = "verbose: "
109
- elif message .get_severity () == 5 : # pymdlsdk.MESSAGE_SEVERITY_DEBUG
110
- level = "debug: "
111
- print (f"{ level } { message .get_string ()} " )
112
- return not hasErrors
113
-
114
-
115
- def load_module (self , qualifiedModuleName : str ):
116
- """Load the module given its name.
117
- Returns the database name if loaded successfully otherwise empty string"""
118
-
119
- impExp : pymdlsdk .IMdl_impexp_api
120
- context : pymdlsdk .IMdl_execution_context
121
- with self .neuray .get_api_component (pymdlsdk .IMdl_impexp_api ) as impExp , \
122
- self .mdlFactory .create_execution_context () as context :
123
- res = impExp .load_module (self .transaction , qualifiedModuleName , context )
124
- if not self .log_context_messages (context ) or res < 0 :
125
- return ""
126
- dbName : pymdlsdk .IString = self .mdlFactory .get_db_module_name (qualifiedModuleName )
127
- if dbName .is_valid_interface ():
128
- return dbName .get_c_str ()
129
- return ""
0 commit comments