From d5a18b2097b3bb46fa63e179fc46dc4d16193dcc Mon Sep 17 00:00:00 2001 From: guzman-raphael Date: Wed, 6 May 2020 16:52:54 -0500 Subject: [PATCH 1/5] Minor fixes for compatibility and refactor tests for compatibility with R2016b. --- +dj/+store_plugins/S3.m | 53 ++++++++++--------- +tests/Main.m | 11 ---- {+tests => tests}/+lib/compareVersions.m | 0 tests/Main.m | 11 ++++ {+tests => tests}/Prep.m | 8 +-- {+tests => tests}/TestConfig.m | 45 +++++++++------- {+tests => tests}/TestConnection.m | 36 ++++++++++++- {+tests => tests}/TestERD.m | 2 +- {+tests => tests}/TestExternalFile.m | 18 +++---- {+tests => tests}/TestExternalS3.m | 10 ++-- {+tests => tests}/TestFetch.m | 10 ++-- {+tests => tests}/TestProjection.m | 2 +- {+tests => tests}/TestTls.m | 4 +- {+tests => tests}/TestUuid.m | 2 +- .../test_schemas/+External/Dimension.m | 0 .../test_schemas/+External/Image.m | 0 .../test_schemas/+University/All.m | 0 .../test_schemas/+University/Date.m | 0 .../test_schemas/+University/Float.m | 0 .../test_schemas/+University/Integer.m | 0 .../test_schemas/+University/Message.m | 0 .../test_schemas/+University/String.m | 0 .../test_schemas/+University/Student.m | 0 {+tests => tests}/test_schemas/config.json | 0 .../test_schemas/config_lite.json | 0 .../test_schemas/store_config.json | 0 26 files changed, 129 insertions(+), 83 deletions(-) delete mode 100644 +tests/Main.m rename {+tests => tests}/+lib/compareVersions.m (100%) create mode 100644 tests/Main.m rename {+tests => tests}/Prep.m (96%) rename {+tests => tests}/TestConfig.m (85%) rename {+tests => tests}/TestConnection.m (59%) rename {+tests => tests}/TestERD.m (96%) rename {+tests => tests}/TestExternalFile.m (92%) rename {+tests => tests}/TestExternalS3.m (85%) rename {+tests => tests}/TestFetch.m (97%) rename {+tests => tests}/TestProjection.m (96%) rename {+tests => tests}/TestTls.m (95%) rename {+tests => tests}/TestUuid.m (98%) rename {+tests => tests}/test_schemas/+External/Dimension.m (100%) rename {+tests => tests}/test_schemas/+External/Image.m (100%) rename {+tests => tests}/test_schemas/+University/All.m (100%) rename {+tests => tests}/test_schemas/+University/Date.m (100%) rename {+tests => tests}/test_schemas/+University/Float.m (100%) rename {+tests => tests}/test_schemas/+University/Integer.m (100%) rename {+tests => tests}/test_schemas/+University/Message.m (100%) rename {+tests => tests}/test_schemas/+University/String.m (100%) rename {+tests => tests}/test_schemas/+University/Student.m (100%) rename {+tests => tests}/test_schemas/config.json (100%) rename {+tests => tests}/test_schemas/config_lite.json (100%) rename {+tests => tests}/test_schemas/store_config.json (100%) diff --git a/+dj/+store_plugins/S3.m b/+dj/+store_plugins/S3.m index 14e7503c..8d27997e 100644 --- a/+dj/+store_plugins/S3.m +++ b/+dj/+store_plugins/S3.m @@ -193,8 +193,8 @@ function remove_object(self, external_filepath) credential_scope ', ' 'SignedHeaders=' signed_headers ', ' ... 'Signature=' signature]; url = [protocol host canonical_uri '?' canonical_querystring]; - - if ~strcmpi(method, 'head') + + try headers = {... 'content_type', content_type; ... 'host', host; ... @@ -207,6 +207,7 @@ function remove_object(self, external_filepath) 'HeaderFields', headers, ... 'RequestMethod', lower(method), ... 'Timeout', 60, ... + 'CertificateFilename', 'default', ... 'ContentType', 'binary', ... 'MediaType', content_type, ... 'CharacterEncoding', 'ISO-8859-1'... @@ -217,30 +218,34 @@ function remove_object(self, external_filepath) else data = webwrite(url, char(payload_bin'), options); end - else - headers = [... - matlab.net.http.HeaderField('content_type', content_type), ... - matlab.net.http.HeaderField('host', host), ... - matlab.net.http.HeaderField('X-Amz-Date', amzdate), ... - matlab.net.http.HeaderField('X-Amz-Content-Sha256', payload_hash), ... - matlab.net.http.HeaderField('Authorization', authorization_header), ... - matlab.net.http.field.AcceptField(... - [matlab.net.http.MediaType(content_type)]) ... - ]; - - request = matlab.net.http.RequestMessage(lower(method), headers, ... - matlab.net.http.MessageBody(payload_bin)); - response = request.send(url, matlab.net.http.HTTPOptions(... - 'ConnectTimeout', 60)); - if response.StatusCode ~= matlab.net.http.StatusCode.OK && ... - response.StatusCode ~= matlab.net.http.StatusCode.NoContent - error(['DataJoint:RequestError:' char(response.StatusCode)], ... - 'Request failed on route `%s` with status `%s`.', canonical_uri, ... - response.StatusLine); + catch ME + if strcmp(ME.identifier,'MATLAB:weboptions:unrecognizedStringChoice') + headers = [... + matlab.net.http.HeaderField('content_type', content_type), ... + matlab.net.http.HeaderField('host', host), ... + matlab.net.http.HeaderField('X-Amz-Date', amzdate), ... + matlab.net.http.HeaderField('X-Amz-Content-Sha256', payload_hash), ... + matlab.net.http.HeaderField('Authorization', authorization_header), ... + matlab.net.http.field.AcceptField(... + [matlab.net.http.MediaType(content_type)]) ... + ]; + + request = matlab.net.http.RequestMessage(lower(method), headers, ... + matlab.net.http.MessageBody(payload_bin)); + response = request.send(url, matlab.net.http.HTTPOptions(... + 'ConnectTimeout', 60, 'CertificateFilename', 'default')); + if response.StatusCode ~= matlab.net.http.StatusCode.OK && ... + response.StatusCode ~= matlab.net.http.StatusCode.NoContent + error(['DataJoint:RequestError:' char(response.StatusCode)], ... + 'Request failed on route `%s` with status `%s`.', canonical_uri, ... + response.StatusLine); + else + data = response.Body.Data; + end else - data = response.Body.Data; + rethrow(ME); end - end + end end end end diff --git a/+tests/Main.m b/+tests/Main.m deleted file mode 100644 index 81422c08..00000000 --- a/+tests/Main.m +++ /dev/null @@ -1,11 +0,0 @@ -classdef Main < ... - tests.TestConfig & ... - tests.TestConnection & ... - tests.TestERD & ... - tests.TestExternalFile & ... - tests.TestExternalS3 & ... - tests.TestFetch & ... - tests.TestProjection & ... - tests.TestTls & ... - tests.TestUuid -end \ No newline at end of file diff --git a/+tests/+lib/compareVersions.m b/tests/+lib/compareVersions.m similarity index 100% rename from +tests/+lib/compareVersions.m rename to tests/+lib/compareVersions.m diff --git a/tests/Main.m b/tests/Main.m new file mode 100644 index 00000000..f66a85b3 --- /dev/null +++ b/tests/Main.m @@ -0,0 +1,11 @@ +classdef Main < ... + TestConfig & ... + TestConnection & ... + TestERD & ... + TestExternalFile & ... + TestExternalS3 & ... + TestFetch & ... + TestProjection & ... + TestTls & ... + TestUuid +end \ No newline at end of file diff --git a/+tests/Prep.m b/tests/Prep.m similarity index 96% rename from +tests/Prep.m rename to tests/Prep.m index 2bbf9ef2..051ebffd 100644 --- a/+tests/Prep.m +++ b/tests/Prep.m @@ -23,9 +23,9 @@ methods function obj = Prep() % Initialize test_root - test_pkg_details = what('tests'); + test_pkg_details = what('dj'); [test_root, ~, ~] = fileparts(test_pkg_details.path); - obj.test_root = [test_root '/+tests']; + obj.test_root = [test_root '/tests']; if ispc obj.external_file_store_root = [getenv('TEMP') '\root']; else @@ -37,13 +37,14 @@ function init(testCase) disp('---------------INIT---------------'); clear functions; + addpath(testCase.test_root); addpath([testCase.test_root '/test_schemas']); curr_conn = dj.conn(testCase.CONN_INFO_ROOT.host, ... testCase.CONN_INFO_ROOT.user, testCase.CONN_INFO_ROOT.password,'',true); % create test users ver = curr_conn.query('select @@version as version').version; - if tests.lib.compareVersions(ver,'5.8') + if lib.compareVersions(ver,'5.8') cmd = {... 'CREATE USER IF NOT EXISTS ''datajoint''@''%%'' ' 'IDENTIFIED BY ''datajoint'';' @@ -154,6 +155,7 @@ function dispose(testCase) % delete(['test_schemas/+University/getSchema.m']) end rmpath([testCase.test_root '/test_schemas']); + % rmpath(testCase.test_root); warning('on','MATLAB:RMDIR:RemovedFromPath'); end end diff --git a/+tests/TestConfig.m b/tests/TestConfig.m similarity index 85% rename from +tests/TestConfig.m rename to tests/TestConfig.m index e56b13b3..58a79d33 100644 --- a/+tests/TestConfig.m +++ b/tests/TestConfig.m @@ -1,4 +1,4 @@ -classdef TestConfig < tests.Prep +classdef TestConfig < Prep % TestConfig tests scenarios related to initializing DJ config. methods (Static) function obj = TestConfig_configRemoveEnvVars(obj, type) @@ -49,7 +49,7 @@ function TestConfig_configSingleFileTest(test_instance, type, fname, base) end % load raw read_data = fileread(fname); - obj1 = tests.TestConfig.TestConfig_configRemoveEnvVars(jsondecode(read_data), 'file'); + obj1 = TestConfig.TestConfig_configRemoveEnvVars(jsondecode(read_data), 'file'); % optional merge from base if strcmpi(type, 'load-custom') tmp = rmfield(base, intersect(fieldnames(base), fieldnames(obj1))); @@ -60,7 +60,7 @@ function TestConfig_configSingleFileTest(test_instance, type, fname, base) % stringify file = jsonencode(obj1); % load config - obj2 = tests.TestConfig.TestConfig_configRemoveEnvVars(dj.config(), 'config'); + obj2 = TestConfig.TestConfig_configRemoveEnvVars(dj.config(), 'config'); curr = jsonencode(obj2); curr = regexprep(curr,'[a-z0-9][A-Z]','${$0(1)}_${lower($0(2))}'); % checks @@ -142,15 +142,20 @@ function TestConfig_testConfigChecks(testCase) disp(['---------------' st(1).name '---------------']); testCase.verifyError(@() dj.config(9), ... 'DataJoint:Config:InvalidType'); - d = testCase.verifyError(@() dj.config('none'), ... - 'DataJoint:Config:InvalidKey'); + try + d = dj.config('none'); + catch ME + if ~strcmp(ME.identifier,'DataJoint:Config:InvalidKey') + rethrow(ME); + end + end end function TestConfig_testRestore(testCase) st = dbstack; disp(['---------------' st(1).name '---------------']); dj.config.restore; - obj1 = tests.TestConfig.TestConfig_configRemoveEnvVars(dj.config(), 'config'); - obj2 = tests.TestConfig.TestConfig_configRemoveEnvVars( ... + obj1 = TestConfig.TestConfig_configRemoveEnvVars(dj.config(), 'config'); + obj2 = TestConfig.TestConfig_configRemoveEnvVars( ... orderfields(dj.internal.Settings.DEFAULTS), 'config'); testCase.verifyEqual(jsonencode(obj1), jsonencode(obj2)); end @@ -161,36 +166,36 @@ function TestConfig_testSave(testCase) % local dj.config('font', 10); - tests.TestConfig.TestConfig_configSingleFileTest(testCase, 'save-local'); + TestConfig.TestConfig_configSingleFileTest(testCase, 'save-local'); % global dj.config('font', 12); - tests.TestConfig.TestConfig_configSingleFileTest(testCase, 'save-global'); + TestConfig.TestConfig_configSingleFileTest(testCase, 'save-global'); % custom dj.config('font', 16); - tests.TestConfig.TestConfig_configSingleFileTest(testCase, 'save-custom', './config.json'); + TestConfig.TestConfig_configSingleFileTest(testCase, 'save-custom', './config.json'); dj.config.restore; end function TestConfig_testLoad(testCase) st = dbstack; disp(['---------------' st(1).name '---------------']); - pkg = what('tests'); + pkg_path = testCase.test_root; % generate default base - default_file = [pkg.path '/test_schemas/default.json']; + default_file = [pkg_path '/test_schemas/default.json']; dj.config.restore; dj.config.save(default_file); - defaults = tests.TestConfig.TestConfig_configRemoveEnvVars( ... + defaults = TestConfig.TestConfig_configRemoveEnvVars( ... jsondecode(fileread(default_file)), 'file'); delete(default_file); % load test config - tests.TestConfig.TestConfig_configSingleFileTest(testCase, 'load-custom', ... - [pkg.path '/test_schemas/config.json'], defaults); + TestConfig.TestConfig_configSingleFileTest(testCase, 'load-custom', ... + [pkg_path '/test_schemas/config.json'], defaults); % load new config on top of existing - base = tests.TestConfig.TestConfig_configRemoveEnvVars(dj.config, 'config'); + base = TestConfig.TestConfig_configRemoveEnvVars(dj.config, 'config'); base = jsonencode(base); base = regexprep(base,'[a-z0-9][A-Z]','${$0(1)}_${lower($0(2))}'); - tests.TestConfig.TestConfig_configSingleFileTest(testCase, 'load-custom', ... - [pkg.path '/test_schemas/config_lite.json'], jsondecode(base)); + TestConfig.TestConfig_configSingleFileTest(testCase, 'load-custom', ... + [pkg_path '/test_schemas/config_lite.json'], jsondecode(base)); % cleanup dj.config.restore; end @@ -210,14 +215,14 @@ function validateEnvVarConfig(type, values) testCase.verifyEqual(dj.config('databasePassword'), values{3}); testCase.verifyEqual(dj.config('connectionInit_function'), values{4}); end - pkg = what('tests'); + pkg_path = testCase.test_root; setenv('DJ_INIT', 'select @@version;'); dj.config.restore; % check pulling from env vars env = {getenv('DJ_HOST'), getenv('DJ_USER'), getenv('DJ_PASS'), getenv('DJ_INIT')}; validateEnvVarConfig('env', env); % check after load if env vars take precedence - dj.config.load([pkg.path '/test_schemas/config.json']); + dj.config.load([pkg_path '/test_schemas/config.json']); validateEnvVarConfig('env', env); % check if overriding env vars is persisted validateEnvVarConfig('set', ... diff --git a/+tests/TestConnection.m b/tests/TestConnection.m similarity index 59% rename from +tests/TestConnection.m rename to tests/TestConnection.m index 92b113a3..f36aaf73 100644 --- a/+tests/TestConnection.m +++ b/tests/TestConnection.m @@ -1,4 +1,4 @@ -classdef TestConnection < tests.Prep +classdef TestConnection < Prep % TestConnection tests typical connection scenarios. methods (Test) function TestConnection_testConnection(testCase) @@ -39,5 +39,39 @@ function TestConnection_testPort(testCase) testCase.CONN_INFO.password,'',true), ... 'MySQL:Error'); end + function TestConnection_testTransactionRollback(testCase) + st = dbstack; + disp(['---------------' st(1).name '---------------']); + package = 'University'; + + c1 = dj.conn(... + testCase.CONN_INFO.host,... + testCase.CONN_INFO.user,... + testCase.CONN_INFO.password,'',true); + dj.createSchema(package,[testCase.test_root '/test_schemas'], ... + [testCase.PREFIX '_university']); + schema = University.getSchema; + tmp = { + 20 'Henry' 'Jupyter' '2020-11-25 12:34:56' + 21 'Lacy' 'Mars' '2017-11-25 12:34:56' + }; + + insert(University.Student, tmp(1, :)); + + schema.conn.startTransaction + try + insert(University.Student, tmp(2, :)); + assert(false, 'Customer:Error', 'Message') + catch ME + schema.conn.cancelTransaction + if ~strcmp(ME.identifier,'Customer:Error') + rethrow(ME); + end + end + + q = University.Student & 'student_id in (20,21)'; + testCase.verifyEqual(q.count, 1); + testCase.verifyEqual(q.fetch1('student_id'), 20); + end end end \ No newline at end of file diff --git a/+tests/TestERD.m b/tests/TestERD.m similarity index 96% rename from +tests/TestERD.m rename to tests/TestERD.m index c400adf2..fae8b73e 100644 --- a/+tests/TestERD.m +++ b/tests/TestERD.m @@ -1,4 +1,4 @@ -classdef TestERD < tests.Prep +classdef TestERD < Prep % TestERD tests unusual ERD scenarios. methods (Test) function TestERD_testDraw(testCase) diff --git a/+tests/TestExternalFile.m b/tests/TestExternalFile.m similarity index 92% rename from +tests/TestExternalFile.m rename to tests/TestExternalFile.m index bcc27ed9..8a0051ab 100644 --- a/+tests/TestExternalFile.m +++ b/tests/TestExternalFile.m @@ -1,11 +1,11 @@ -classdef TestExternalFile < tests.Prep +classdef TestExternalFile < Prep % TestExternalFile tests scenarios related to external file store. methods (Static) function TestExternalFile_checks(test_instance, store, cache) % load config - pkg = what('tests'); + pkg_path = test_instance.test_root; ext_root = strrep(test_instance.external_file_store_root, '\', '/'); - dj.config.load([strrep(pkg.path, '\', '/') '/test_schemas/store_config.json']); + dj.config.load([strrep(pkg_path, '\', '/') '/test_schemas/store_config.json']); dj.config(['stores.' store '.location'], strrep(dj.config(... ['stores.' store '.location']), '{{external_file_store_root}}', ... ext_root)); @@ -61,7 +61,7 @@ function TestExternalFile_checks(test_instance, store, cache) '/' dj.config('stores.main.location')], ''); end subfold_path = strrep(subfold_path, ['/' schema.dbname '/'], ''); - subfold_cell = split(subfold_path, '/'); + subfold_cell = strsplit(subfold_path, '/'); if length(subfold_cell) > 1 subfold_cell = subfold_cell(1:end-1); subfold_path = ['/' strjoin(subfold_cell, '/')]; @@ -69,7 +69,7 @@ function TestExternalFile_checks(test_instance, store, cache) subfold_cell = {}; subfold_path = ''; end - test_instance.verifyEqual(cellfun(@(x) length(x), subfold_cell), ... + test_instance.verifyEqual(cellfun(@(x) length(x), subfold_cell)', ... schema.external.table('main').spec.type_config.subfolding); % delete value to rely on cache schema.external.table('main').spec.remove_object(uuid_path); @@ -131,23 +131,23 @@ function TestExternalFile_checks(test_instance, store, cache) function TestExternalFile_testLocal(testCase) st = dbstack; disp(['---------------' st(1).name '---------------']); - tests.TestExternalFile.TestExternalFile_checks(testCase, 'new_local', 'blobCache'); + TestExternalFile.TestExternalFile_checks(testCase, 'new_local', 'blobCache'); end function TestExternalFile_testLocalDefault(testCase) st = dbstack; disp(['---------------' st(1).name '---------------']); - tests.TestExternalFile.TestExternalFile_checks(testCase, 'new_local_default', ... + TestExternalFile.TestExternalFile_checks(testCase, 'new_local_default', ... 'blobCache'); end function TestExternalFile_testBackward(testCase) st = dbstack; disp(['---------------' st(1).name '---------------']); - tests.TestExternalFile.TestExternalFile_checks(testCase, 'local', 'cache'); + TestExternalFile.TestExternalFile_checks(testCase, 'local', 'cache'); end function TestExternalFile_testBackwardDefault(testCase) st = dbstack; disp(['---------------' st(1).name '---------------']); - tests.TestExternalFile.TestExternalFile_checks(testCase, 'local_default', 'cache'); + TestExternalFile.TestExternalFile_checks(testCase, 'local_default', 'cache'); end function TestExternalFile_testMD5Hash(testCase) st = dbstack; diff --git a/+tests/TestExternalS3.m b/tests/TestExternalS3.m similarity index 85% rename from +tests/TestExternalS3.m rename to tests/TestExternalS3.m index 1230ee2d..015dd5d9 100644 --- a/+tests/TestExternalS3.m +++ b/tests/TestExternalS3.m @@ -1,27 +1,27 @@ -classdef TestExternalS3 < tests.Prep +classdef TestExternalS3 < Prep % TestExternalS3 tests scenarios related to external S3 store. methods (Test) function TestExternalS3_testRemote(testCase) st = dbstack; disp(['---------------' st(1).name '---------------']); - tests.TestExternalFile.TestExternalFile_checks(testCase, 'new_remote', ... + TestExternalFile.TestExternalFile_checks(testCase, 'new_remote', ... 'blobCache'); end function TestExternalS3_testRemoteDefault(testCase) st = dbstack; disp(['---------------' st(1).name '---------------']); - tests.TestExternalFile.TestExternalFile_checks(testCase, 'new_remote_default', ... + TestExternalFile.TestExternalFile_checks(testCase, 'new_remote_default', ... 'blobCache'); end function TestExternalS3_testBackward(testCase) st = dbstack; disp(['---------------' st(1).name '---------------']); - tests.TestExternalFile.TestExternalFile_checks(testCase, 'remote', 'cache'); + TestExternalFile.TestExternalFile_checks(testCase, 'remote', 'cache'); end function TestExternalS3_testBackwardDefault(testCase) st = dbstack; disp(['---------------' st(1).name '---------------']); - tests.TestExternalFile.TestExternalFile_checks(testCase, 'remote_default', ... + TestExternalFile.TestExternalFile_checks(testCase, 'remote_default', ... 'cache'); end function TestExternalS3_testLocationFlexibility(testCase) diff --git a/+tests/TestFetch.m b/tests/TestFetch.m similarity index 97% rename from +tests/TestFetch.m rename to tests/TestFetch.m index 7acaa993..12eb3f3c 100644 --- a/+tests/TestFetch.m +++ b/tests/TestFetch.m @@ -1,4 +1,4 @@ -classdef TestFetch < tests.Prep +classdef TestFetch < Prep % TestFetch tests typical insert/fetch scenarios. methods (Static) function TestFetch_Generic(testCase, id, correct_value, null_value, wrong_value, ... @@ -264,7 +264,7 @@ function TestFetch_testString(testCase) dj.createSchema(package,[testCase.test_root '/test_schemas'], ... [testCase.PREFIX '_university']); - tests.TestFetch.TestFetch_Generic(testCase, 1, 'n', [], 5, ... + TestFetch.TestFetch_Generic(testCase, 1, 'n', [], 5, ... @(x) strcat(x, 'o'), University.String); end function TestFetch_testDate(testCase) @@ -280,7 +280,7 @@ function TestFetch_testDate(testCase) dj.createSchema(package,[testCase.test_root '/test_schemas'], ... [testCase.PREFIX '_university']); - tests.TestFetch.TestFetch_Generic(testCase, 1, '2020-01-01', [], 5, ... + TestFetch.TestFetch_Generic(testCase, 1, '2020-01-01', [], 5, ... @(x) datestr(addtodate(datenum(x), 1, 'day'), 'yyyy-mm-dd'), University.Date); end function TestFetch_testInteger(testCase) @@ -296,7 +296,7 @@ function TestFetch_testInteger(testCase) dj.createSchema(package,[testCase.test_root '/test_schemas'], ... [testCase.PREFIX '_university']); - tests.TestFetch.TestFetch_Generic(testCase, 1, 2, NaN, 'wrong', ... + TestFetch.TestFetch_Generic(testCase, 1, 2, NaN, 'wrong', ... @(x) x + 1, University.Integer); end function TestFetch_testFloat(testCase) @@ -312,7 +312,7 @@ function TestFetch_testFloat(testCase) dj.createSchema(package,[testCase.test_root '/test_schemas'], ... [testCase.PREFIX '_university']); - tests.TestFetch.TestFetch_Generic(testCase, 1, 1.01, NaN, 'wrong', ... + TestFetch.TestFetch_Generic(testCase, 1, 1.01, NaN, 'wrong', ... @(x) x + 0.01, University.Float); end end diff --git a/+tests/TestProjection.m b/tests/TestProjection.m similarity index 96% rename from +tests/TestProjection.m rename to tests/TestProjection.m index 0b0b2dac..55db3a6e 100644 --- a/+tests/TestProjection.m +++ b/tests/TestProjection.m @@ -1,4 +1,4 @@ -classdef TestProjection < tests.Prep +classdef TestProjection < Prep % TestProjection tests use of q.proj(...). methods (Test) function TestProjection_testDateConversion(testCase) diff --git a/+tests/TestTls.m b/tests/TestTls.m similarity index 95% rename from +tests/TestTls.m rename to tests/TestTls.m index a340afb6..04f84bd8 100644 --- a/+tests/TestTls.m +++ b/tests/TestTls.m @@ -1,4 +1,4 @@ -classdef TestTls < tests.Prep +classdef TestTls < Prep % TestTls tests TLS connection scenarios. methods (Test) function TestTls_testSecureConn(testCase) @@ -51,7 +51,7 @@ function TestTls_testRejectException(testCase) e = lasterror; testCase.verifyEqual(e.identifier, 'MySQL:Error'); testCase.verifyTrue(contains(e.message,... - ["requires secure connection","Access denied"])); %MySQL8,MySQL5 + {'requires secure connection','Access denied'})); %MySQL8,MySQL5 end end function TestTls_testStructException(testCase) diff --git a/+tests/TestUuid.m b/tests/TestUuid.m similarity index 98% rename from +tests/TestUuid.m rename to tests/TestUuid.m index 362b2b3b..946f836d 100644 --- a/+tests/TestUuid.m +++ b/tests/TestUuid.m @@ -1,4 +1,4 @@ -classdef TestUuid < tests.Prep +classdef TestUuid < Prep % TestUuid tests uuid scenarios. methods (Test) function TestUuid_testInsertFetch(testCase) diff --git a/+tests/test_schemas/+External/Dimension.m b/tests/test_schemas/+External/Dimension.m similarity index 100% rename from +tests/test_schemas/+External/Dimension.m rename to tests/test_schemas/+External/Dimension.m diff --git a/+tests/test_schemas/+External/Image.m b/tests/test_schemas/+External/Image.m similarity index 100% rename from +tests/test_schemas/+External/Image.m rename to tests/test_schemas/+External/Image.m diff --git a/+tests/test_schemas/+University/All.m b/tests/test_schemas/+University/All.m similarity index 100% rename from +tests/test_schemas/+University/All.m rename to tests/test_schemas/+University/All.m diff --git a/+tests/test_schemas/+University/Date.m b/tests/test_schemas/+University/Date.m similarity index 100% rename from +tests/test_schemas/+University/Date.m rename to tests/test_schemas/+University/Date.m diff --git a/+tests/test_schemas/+University/Float.m b/tests/test_schemas/+University/Float.m similarity index 100% rename from +tests/test_schemas/+University/Float.m rename to tests/test_schemas/+University/Float.m diff --git a/+tests/test_schemas/+University/Integer.m b/tests/test_schemas/+University/Integer.m similarity index 100% rename from +tests/test_schemas/+University/Integer.m rename to tests/test_schemas/+University/Integer.m diff --git a/+tests/test_schemas/+University/Message.m b/tests/test_schemas/+University/Message.m similarity index 100% rename from +tests/test_schemas/+University/Message.m rename to tests/test_schemas/+University/Message.m diff --git a/+tests/test_schemas/+University/String.m b/tests/test_schemas/+University/String.m similarity index 100% rename from +tests/test_schemas/+University/String.m rename to tests/test_schemas/+University/String.m diff --git a/+tests/test_schemas/+University/Student.m b/tests/test_schemas/+University/Student.m similarity index 100% rename from +tests/test_schemas/+University/Student.m rename to tests/test_schemas/+University/Student.m diff --git a/+tests/test_schemas/config.json b/tests/test_schemas/config.json similarity index 100% rename from +tests/test_schemas/config.json rename to tests/test_schemas/config.json diff --git a/+tests/test_schemas/config_lite.json b/tests/test_schemas/config_lite.json similarity index 100% rename from +tests/test_schemas/config_lite.json rename to tests/test_schemas/config_lite.json diff --git a/+tests/test_schemas/store_config.json b/tests/test_schemas/store_config.json similarity index 100% rename from +tests/test_schemas/store_config.json rename to tests/test_schemas/store_config.json From fea38090e8a4af69fe418153e6fbba755c37d8f9 Mon Sep 17 00:00:00 2001 From: guzman-raphael Date: Thu, 7 May 2020 12:54:04 -0500 Subject: [PATCH 2/5] Add travis R2016b test env. --- .travis.yml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index ab48adbc..ed7c6d16 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,25 +23,21 @@ jobs: include: - <<: *slim env: - - MATLAB_VERSION: R2018b + - MATLAB_VERSION: R2019a - MYSQL_TAG: 8.0 - <<: *slim env: - - MATLAB_VERSION: R2018b + - MATLAB_VERSION: R2019a - MYSQL_TAG: 5.7 - - <<: *slim - env: - - MATLAB_VERSION: R2018b - - MYSQL_TAG: 5.6 - <<: *slim env: - MATLAB_VERSION: R2019a - - MYSQL_TAG: 8.0 + - MYSQL_TAG: 5.6 - <<: *slim env: - - MATLAB_VERSION: R2019a + - MATLAB_VERSION: R2018b - MYSQL_TAG: 5.7 - <<: *slim env: - - MATLAB_VERSION: R2019a - - MYSQL_TAG: 5.6 \ No newline at end of file + - MATLAB_VERSION: R2016b + - MYSQL_TAG: 5.7 \ No newline at end of file From 17f128e5c3b4f54be3d3df89342968c583f6d1c9 Mon Sep 17 00:00:00 2001 From: guzman-raphael Date: Thu, 7 May 2020 13:33:00 -0500 Subject: [PATCH 3/5] Update test instruction doc. --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b8da6eb4..37462a77 100644 --- a/README.md +++ b/README.md @@ -20,14 +20,15 @@ MYSQL_TAG=5.7 * `cp local-docker-compose.yml docker-compose.yml` * `docker-compose up` (Note configured `JUPYTER_PASSWORD`) * Select a means of running MATLAB e.g. Jupyter Notebook, GUI, or Terminal (see bottom) +* Add `tests` directory to path e.g. in MATLAB, `addpath('tests')` * Run desired tests. Some examples are as follows: | Use Case | MATLAB Code | | ---------------------------- | ------------------------------------------------------------------------------ | -| Run all tests | `run(tests.Main)` | -| Run one class of tests | `run(tests.TestTls)` | -| Run one specific test | `runtests('tests.TestTls/testInsecureConn')` | -| Run tests based on test name | `import matlab.unittest.TestSuite;`
`import matlab.unittest.selectors.HasName;`
`import matlab.unittest.constraints.ContainsSubstring;`
`suite = TestSuite.fromClass(?tests.Main, ... `
    `HasName(ContainsSubstring('Conn')));`
`run(suite)`| +| Run all tests | `run(Main)` | +| Run one class of tests | `run(TestTls)` | +| Run one specific test | `runtests('TestTls/testInsecureConn')` | +| Run tests based on test name | `import matlab.unittest.TestSuite;`
`import matlab.unittest.selectors.HasName;`
`import matlab.unittest.constraints.ContainsSubstring;`
`suite = TestSuite.fromClass(?Main, ... `
    `HasName(ContainsSubstring('Conn')));`
`run(suite)`| Launch Jupyter Notebook From 31f17b9ef094af5395633eb3e564683e00b3cf7a Mon Sep 17 00:00:00 2001 From: guzman-raphael Date: Mon, 11 May 2020 12:42:03 -0500 Subject: [PATCH 4/5] Fix styling. --- +dj/+store_plugins/S3.m | 2 +- tests/TestConfig.m | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/+dj/+store_plugins/S3.m b/+dj/+store_plugins/S3.m index 8d27997e..2939b9b0 100644 --- a/+dj/+store_plugins/S3.m +++ b/+dj/+store_plugins/S3.m @@ -237,7 +237,7 @@ function remove_object(self, external_filepath) if response.StatusCode ~= matlab.net.http.StatusCode.OK && ... response.StatusCode ~= matlab.net.http.StatusCode.NoContent error(['DataJoint:RequestError:' char(response.StatusCode)], ... - 'Request failed on route `%s` with status `%s`.', canonical_uri, ... + 'Request failed on route `%s` with status `%s`.', canonical_uri,... response.StatusLine); else data = response.Body.Data; diff --git a/tests/TestConfig.m b/tests/TestConfig.m index 58a79d33..8ca7c91a 100644 --- a/tests/TestConfig.m +++ b/tests/TestConfig.m @@ -172,7 +172,8 @@ function TestConfig_testSave(testCase) TestConfig.TestConfig_configSingleFileTest(testCase, 'save-global'); % custom dj.config('font', 16); - TestConfig.TestConfig_configSingleFileTest(testCase, 'save-custom', './config.json'); + TestConfig.TestConfig_configSingleFileTest(... + testCase, 'save-custom', './config.json'); dj.config.restore; end From d8b5233f168cdec19ac1e9f56a70c5471a8ae3b9 Mon Sep 17 00:00:00 2001 From: guzman-raphael Date: Mon, 11 May 2020 12:54:07 -0500 Subject: [PATCH 5/5] Fix paths for travis. --- LNX-docker-compose.yml | 3 ++- local-docker-compose.yml | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/LNX-docker-compose.yml b/LNX-docker-compose.yml index f83eb01d..edf7c466 100644 --- a/LNX-docker-compose.yml +++ b/LNX-docker-compose.yml @@ -66,7 +66,8 @@ services: command: > /bin/bash -c " matlab -nodisplay -r \"\ - res=run(tests.Main);\ + addpath('/src/tests');\ + res=run(Main);\ disp(res);\ if all([res.Passed]) exit, else exit(1), end;\ \"; diff --git a/local-docker-compose.yml b/local-docker-compose.yml index 77adabe2..748f28c9 100644 --- a/local-docker-compose.yml +++ b/local-docker-compose.yml @@ -82,6 +82,7 @@ services: ## Set dj path matlab -nodisplay -r \"\ addpath('/src');\ + addpath('/src/tests');\ savepath;\ \"; ## Interactive Jupyter Notebook environment