def setUpClass(cls): with cls.lock: if cls.instances == 0: gc.collect() from tempfile import mkdtemp if getenv("TEST_DISTRIBUTED_TREES") is not None: treepath = "thread://tree::%s" else: treepath = "%s" cls.tmpdir = mkdtemp() cls.root = os.path.dirname(os.path.realpath(__file__)) cls.topsrc = os.path.realpath(cls.root + "%s..%s..%s.." % tuple([os.sep] * 3)) cls.env = dict((k, str(v)) for k, v in os.environ.items()) cls.envx = {} cls._setenv('PyLib', getenv('PyLib')) cls._setenv("MDS_PYDEVICE_PATH", '%s/pydevices;%s/devices' % (cls.topsrc, cls.root)) trees = cls.trees if cls.tree is None else set( cls.trees).union([cls.tree]) for treename in trees: cls._setenv("%s_path" % treename, treepath % cls.tmpdir) if getenv("testing_path") is None: cls._setenv("testing_path", "%s/trees" % cls.root) cls.instances += 1
def _setup_mdsip(server_env,port_env,default_port,fix0): host = getenv(server_env,'') if len(host)>0: return host,0 port = int(getenv(port_env,default_port)) if port==0: if fix0: port = default_port else: return None,0 return 'localhost:%d'%(port,),port
def MDSDEVICES(): with lock: if cache[0] is None: from MDSplus import Device,tdi,version,getenv from numpy import array def importDevices(name): bname = version.tobytes(name) try: module = __import__(name) ans = [[version.tobytes(k),bname] for k,v in module.__dict__.items() if isinstance(v,int.__class__) and issubclass(v,Device)] except (ImportError, ImportWarning): ans = [] tdidev = tdi("if_error(%s(),*)"%name) if tdidev is None: return ans tdidev = [[k.rstrip(), v.rstrip()] for k,v in tdidev.value.reshape((int(tdidev.value.size/2),2)).tolist()] return tdidev+ans ans = [[version.tobytes(d),b'pydevice'] for d in Device.findPyDevices()] mdsdevs=getenv('MDS_DEVICES') if mdsdevs is not None: modules=mdsdevs.split(':') else: modules=["KbsiDevices","MitDevices","RfxDevices","W7xDevices"] for module in modules: ans += importDevices(module) ans = array(list(dict(ans).items())) ans.view('%s,%s'%(ans.dtype,ans.dtype)).sort(order=['f0'], axis=0) cache[0] = ans return cache[0]
def setUpClass(cls): with cls.lock: if cls.instances == 0: import gc gc.collect() from tempfile import mkdtemp if getenv("TEST_DISTRIBUTED_TREES") is not None: treepath = "localhost::%s" else: treepath = "%s" cls.tmpdir = mkdtemp() cls.root = os.path.dirname(os.path.realpath(__file__)) cls.env = dict((k, str(v)) for k, v in os.environ.items()) cls.envx = {} cls._setenv('PyLib', getenv('PyLib')) cls._setenv("MDS_PYDEVICE_PATH", '%s/devices' % cls.root) cls._setenv("pytree_path", treepath % cls.tmpdir) with Tree('pytree', -1, 'new') as pytree: Device.PyDevice('TestDevice').Add(pytree, 'TESTDEVICE') pytree.write() cls.instances += 1
def setUpClass(cls): with cls.lock: if cls.instances == 0: from tempfile import mkdtemp if getenv("TEST_DISTRIBUTED_TREES") is not None: treepath = "localhost::%s" else: treepath = "%s" cls.tmpdir = mkdtemp() cls.root = os.path.dirname(os.path.realpath(__file__)) cls.env = dict((k, str(v)) for k, v in os.environ.items()) cls.envx = {} cls._setenv('PyLib', getenv('PyLib')) cls._setenv("MDS_PYDEVICE_PATH", '%s/devices' % cls.root) cls._setenv("pytree_path", treepath % cls.tmpdir) cls._setenv("pytreesub_path", treepath % cls.tmpdir) if getenv("testing_path") is None: cls._setenv("testing_path", "%s/trees" % cls.root) cls.instances += 1 if cls.inThread: print('threads up: %d' % (cls.instances, ))
def check_arch(file_name): module_name = os.path.basename(file_name) if not ts.check_unittest_version(module_name): ts.skip_test(module_name,'Unfit unittest version < 2.7') try: ts.check_load_lib("MdsShr") except: ts.skip_test(module_name,'Unable to load mdsplus lib "MdsShr"') if module_name.startswith('dcl'): from MDSplus import getenv try: pylib = getenv('PyLib') print('PyLib="%s"'%pylib) if not pylib: ts.skip_test(module_name,'Invalid/unset PyLib env.') ts.check_load_lib(pylib) except Exception: ts.skip_test(module_name,'Unable to load python lib "%s"'%(pylib,))
def test_all(*arg): if getenv('waitdbg') is not None: print("Hit return after gdb is connected\n") sys.stdin.readline() testSuites = [ 'dataUnitTest', 'dclUnitTest', 'devicesUnitTest', 'exceptionUnitTest', 'segmentsUnitTest', 'treeUnitTest', 'threadsUnitTest', ] #testSuites += ['connectionUnitTest'] tests = [] for suite in testSuites: try: tests.append(_mimportSuite(suite)()) except Exception as e: print("Could not import %s\n%s" % (suite, e.message)) return TestSuite(tests)
from unittest import TestCase, TestSuite, TextTestRunner from MDSplus import Tree, getenv, setenv, tcl, Connection from MDSplus import checkStatus, TreeWRITEFIRST, TreeNOT_OPEN import traceback import threading import re import gc import os import sys import time from MDSplus.mdsExceptions import MDSplusException iswin = sys.platform.startswith('win') MDSIP_PROTOCOL = getenv('MDSIP_PROTOCOL', 'TCP') class logger(object): """wrapper class to force flush on each write""" def __init__(self, filename): self.__f = open(filename, 'w+') def write(self, *a, **kv): self.__f.write(*a, **kv) self.__f.flush() def __enter__(self, *a, **kv): return self def __exit__(self, *a, **kv):