Home > testing > unit_tests > importExportTests.m

importExportTests

PURPOSE ^

run this test case with the command

SYNOPSIS ^

function tests = importExportTests

DESCRIPTION ^

run this test case with the command
results = runtests('importExportTests.m')

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %run this test case with the command
0002 %results = runtests('importExportTests.m')
0003 function tests = importExportTests
0004 tests = functiontests(localfunctions);
0005 end
0006 
0007 function testExcelImport(testCase)
0008 sourceDir=fileparts(fileparts(fileparts(which(mfilename))));
0009 excelFile=fullfile(sourceDir,'tutorial','empty.xlsx');
0010 %%Prepare test results, uncomment and run when new reference is needed
0011 % modelExcel=importExcelModel(excelFile);
0012 % sbmlFile=fullfile(sourceDir,'tutorial','empty.xml');
0013 % modelSBML=importModel(sbmlFile);
0014 % save(fullfile(sourceDir,'testing','unit_tests','test_data','importExportResults.mat'),'modelExcel','modelSBML');
0015 evalc('model=importExcelModel(excelFile)'); % Repress warnings
0016 load(fullfile(sourceDir,'testing','unit_tests','test_data','importExportResults.mat'), 'modelExcel');
0017 verifyEqual(testCase,model,modelExcel)
0018 end
0019 
0020 function testSBMLImport(testCase)
0021 sourceDir=fileparts(fileparts(fileparts(which(mfilename))));
0022 sbmlFile=fullfile(sourceDir,'tutorial','empty.xml');
0023 evalc('model=importModel(sbmlFile)'); % Repress warnings
0024 load(fullfile(sourceDir,'testing','unit_tests','test_data','importExportResults.mat'), 'modelSBML');
0025 verifyEqual(testCase,model,modelSBML)
0026 end
0027 
0028 function testYAMLimport(testCase)
0029 sourceDir=fileparts(fileparts(fileparts(which(mfilename))));
0030 yamlFile=fullfile(sourceDir,'tutorial','empty.yml');
0031 evalc('model=readYAMLmodel(yamlFile)'); % Repress warnings
0032 load(fullfile(sourceDir,'testing','unit_tests','test_data','importExportResults.mat'), 'modelYAML');
0033 verifyEqual(testCase,model,modelYAML)
0034 end
0035 
0036 function testExcelExport(testCase)
0037 sourceDir=fileparts(fileparts(fileparts(which(mfilename))));
0038 load(fullfile(sourceDir,'testing','unit_tests','test_data','ecoli_textbook.mat'), 'model');
0039 evalc('exportToExcelFormat(model,fullfile(sourceDir,''testing'',''unit_tests'',''test_data'',''_test.xlsx''))');
0040 %File will not be exactly equal as it contains the current date and time,
0041 %so md5 or similar would not work. Just check whether file is reasonably
0042 %sized.
0043 s = dir(fullfile(sourceDir,'testing','unit_tests','test_data','_test.xlsx'));         
0044 filesize = s.bytes;
0045 verifyTrue(testCase,filesize>17000);
0046 delete(fullfile(sourceDir,'testing','unit_tests','test_data','_test.xlsx'));
0047 end
0048 
0049 function testSBMLExport(testCase)
0050 sourceDir=fileparts(fileparts(fileparts(which(mfilename))));
0051 load(fullfile(sourceDir,'testing','unit_tests','test_data','ecoli_textbook.mat'), 'model');
0052 evalc('exportModel(model,fullfile(sourceDir,''testing'',''unit_tests'',''test_data'',''_test.xml''))');
0053 %File will not be exactly equal as it contains the current date and time,
0054 %so md5 or similar would not work. Just check whether file is reasonably
0055 %sized.
0056 s = dir(fullfile(sourceDir,'testing','unit_tests','test_data','_test.xml'));         
0057 filesize = s.bytes;
0058 verifyTrue(testCase,filesize>18500);
0059 delete(fullfile(sourceDir,'testing','unit_tests','test_data','_test.xml'));
0060 end
0061 
0062 function testSBMLExportNestedSubSystems(testCase)
0063 %Regression test: a model where reactions have differing numbers of
0064 %subsystems (nested cell-of-cells, e.g. one reaction in two subsystems and
0065 %others in one) must be exportable to SBML. Previously exportModel failed
0066 %with "Dimensions of arrays being concatenated are not consistent" because
0067 %the subSystems flattening could not concatenate entries of unequal length.
0068 sourceDir=fileparts(fileparts(fileparts(which(mfilename))));
0069 load(fullfile(sourceDir,'testing','unit_tests','test_data','ecoli_textbook.mat'), 'model');
0070 
0071 %Assign nested subSystems: most reactions get a single subsystem, but a few
0072 %get multiple, which is the scenario that triggered the bug.
0073 nRxns=numel(model.rxns);
0074 model.subSystems=repmat({{'Subsystem A'}},nRxns,1);
0075 model.subSystems{1}={'Subsystem A','Subsystem B'};
0076 model.subSystems{2}={'Subsystem B','Subsystem C'};
0077 
0078 tmpFile=fullfile(sourceDir,'testing','unit_tests','test_data','_testNested.xml');
0079 %This call previously errored; verify it completes and round-trips.
0080 evalc('exportModel(model,tmpFile)');
0081 evalc('modelImported=importModel(tmpFile)');
0082 delete(tmpFile);
0083 
0084 %Subsystems should be preserved (order within a reaction is not guaranteed)
0085 srt=@(c) sort(reshape(c,1,[]));
0086 for i=1:3
0087     j=find(strcmp(modelImported.rxns,model.rxns{i}));
0088     verifyEqual(testCase,srt(modelImported.subSystems{j}),srt(model.subSystems{i}));
0089 end
0090 end
0091 
0092 function testYAMLexport(testCase)
0093 sourceDir=fileparts(fileparts(fileparts(which(mfilename))));
0094 load(fullfile(sourceDir,'tutorial','empty.mat'), 'emptyModel');
0095 evalc('writeYAMLmodel(emptyModel,fullfile(sourceDir,''testing'',''unit_tests'',''test_data'',''_test.yml''))');
0096 %File will not be exactly equal as it contains the current date and time,
0097 %so md5 or similar would not work. Just check whether file is reasonably
0098 %sized.
0099 s = dir(fullfile(sourceDir,'testing','unit_tests','test_data','_test.yml'));         
0100 filesize = s.bytes;
0101 verifyTrue(testCase,filesize>1290);
0102 delete(fullfile(sourceDir,'testing','unit_tests','test_data','_test.yml'));
0103 end

Generated by m2html © 2005