Skip to content

Commit

Permalink
adding some unit/integration tests for matpyuda
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Dixon authored and Stephen Dixon committed Jul 26, 2023
1 parent c14a157 commit 6c84291
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@
end

function set_property(obj, name, value)
obj.python_client.set_property(string(name), string(value));
if class(value) == "logical"
obj.python_client.set_property(string(name), py.bool(value));
else
obj.python_client.set_property(string(name), string(value));
end
end

function reset_connection(obj)
Expand Down
6 changes: 3 additions & 3 deletions source/wrappers/matlab/pyuda_interface/+matpyuda/MastClient.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
classdef MastClient < matpyuda.Client
methods
function obj = MastClient()
c0 = py.pyuda.Client();
c1 = py.mast.MastClient(c0);
obj = obj@matpyuda.Client(c1);
c0 = py.matpyuda.MastClient();
// c1 = py.mast.MastClient(c0);
obj = obj@matpyuda.Client(c0);
end

function result = list(obj, options)
Expand Down
148 changes: 148 additions & 0 deletions source/wrappers/matlab/pyuda_interface/TestMatpyudaMast.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
function tests = TestMatpyudaMast
tests = functiontests(localfunctions);
end

function test_base_client_constructor(testCase)
try
client = matpyuda.Client();
verifyInstanceOf(testCase, client, ?matpyuda.Client);
catch(ME)
verifyFail(testCase);
end
end

function test_get_port(testCase)
client = matpyuda.Client();
port = client.port();
verifyClass(testCase, port, ?int32);
end

function test_getset_port(testCase)
client = matpyuda.Client();
client.port = 12345;
port = client.port();
verifyEqual(testCase, port, int32(12345));
end

function test_get_server(testCase)
client = matpyuda.Client();
server = client.server();
verifyClass(testCase, server, ?string);
end

function test_getset_server(testCase)
client = matpyuda.Client();
client.server = "madeup.server.addr";
server = client.server();
verifyEqual(testCase, server, "madeup.server.addr");
end

function test_get_property_logical(testCase)
client = matpyuda.Client();
p = client.get_property("get_meta");
verifyTrue(testCase, islogical(p));
end

function test_getset_property_logical(testCase)
client = matpyuda.Client();
client.set_property('get_meta', py.False);
p(1) = client.get_property("get_meta");
client.set_property('get_meta', py.True);
p(2) = client.get_property("get_meta");
verifyEqual(testCase, p, [false, true]);
end

function test_get_property_val(testCase)
client = matpyuda.Client();
p = client.get_property("timeout");
verifyTrue(testCase, isnumeric(p));
end

function test_getset_property_val(testCase)
client = matpyuda.Client();
client.set_property('timeout', 0);
p(1) = client.get_property("timeout");
client.set_property('timeout', 600);
p(2) = client.get_property("timeout");
verifyEqual(testCase, p, int32([0, 600]));
end

function test_get_string(testCase)
client = matpyuda.Client();
client.port =56565;
client.server ="uda2.mast.l";

s = client.get("help::help()", "");
verifyClass(testCase, s, ?string);

end

function test_get_1d_double_signal(testCase)
client = matpyuda.Client();
client.port = 56565;
client.server= "uda2.mast.l";
client.set_property('get_meta', py.True);

ip = client.get('ip', '30420');
assertClass(testCase, ip, ?matpyuda.Signal);
verifyEqual(testCase, length(ip.data), 30000);
verifyEqual(testCase, length(ip.dims), 1);
verifyEqual(testCase, length(ip.dims.data), 30000);
verifyEqual(testCase, length(ip.errors), 30000);

verifyEqual(testCase, ip.label, "Plasma Current");
verifyEqual(testCase, ip.units, "kA");
verifyEqual(testCase, ip.description, "");

assertClass(testCase, ip.meta, ?struct);
verifyEqual(testCase, ip.meta.exp_number, int32(30420));
end

%function test_get_signal_meta(testCase)
%
%end

%function test_get_2d_double_signal(testCase)
%
%end

%function test_get_1d_int_signal(testCase)
%
%end

%function test_get_2d_int_signal(testCase)
%
%end

%function test_get_structured(testCase)
%
%end

%function test_get_video(testCase)
%
%end

% FOLLOWING TESTS REQUIRE MastClient IMPLEMENTATION TO BE UNCOMMENTED IN MATPYUDA PYTOHN PACKAGE
% ... mast specific stuff eventually needs to move out of this main repo ...

%function test_mast_client_constructor(testCase)
% try
% client = matpyuda.MastClient();
% verifyInstanceOf(testCase, client, ?matpyuda.Client);
% catch(ME)
% verifyFail(testCase);
% end
%end

%function test_mast_list_signals(testCase)
% client = matpyuda.MastClient();
% client.port = 56565;
% client.server = "uda2.mast.l";
%
% python_list = client.python_client.list_signals(alias='ane', shot='27999');
% matlab_list = client.list_signals(alias='ane', shot='27999');
%
% verifyEqual(testCase, length(matlab_list), length(python_list));
% verifyEqual(testCase, matlab_list(1).signal_name, string(python_list{1}.signal_name));
%
%end
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .matpyuda import Client
from .matpyuda import Client #, MastClient
36 changes: 31 additions & 5 deletions source/wrappers/matlab/pyuda_interface/matpyuda/matpyuda.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import pyuda
# import mast
# from mast.geom.geometryClient import GeomClient
# from mast import MastClient


def void_display(*args, **kwargs):
Expand All @@ -17,8 +14,6 @@ def void_display(*args, **kwargs):
class Client(pyuda.Client):
def __init__(self):
pyuda.Client.__init__(self)
# MastClient.__init__(self, pyuda.Client())
# GeomClient.__init__(self, pyuda.Client())

def set_port(self, number):
pyuda.Client.port = number
Expand All @@ -36,3 +31,34 @@ def get_matlab_batch(self, signals_mstring, sources_mstring):
signals = signals_mstring.split(",")
sources = sources_mstring.split(",")
return pyuda.Client.get_batch(signals, sources)


# ... mast specific stuff eventually needs to move out of this main repo ...
# from mast.geom.geometryClient import GeomClient
# from mast import MastClient

# class MastClient(pyuda.Client, MastClient, GeomClient):

# def __init__(self):
# from mast.geom.geometryClient import GeomClient
# from mast import MastClient
# pyuda.Client.__init__(self)
# MastClient.__init__(self, pyuda.Client())
# GeomClient.__init__(self, pyuda.Client())

# def set_port(self, number):
# pyuda.Client.port = number

# def get_port(self):
# return pyuda.Client.port

# def set_server(self, address):
# pyuda.Client.server = address

# def get_server(self):
# return pyuda.Client.server

# def get_matlab_batch(self, signals_mstring, sources_mstring):
# signals = signals_mstring.split(",")
# sources = sources_mstring.split(",")
# return pyuda.Client.get_batch(signals, sources)

0 comments on commit 6c84291

Please sign in to comment.