From 9ea4ae7e192b5489a38aeec1a41f3e2c02336a04 Mon Sep 17 00:00:00 2001 From: Daniel <d.hornung@indiscale.com> Date: Thu, 12 Aug 2021 14:16:29 +0200 Subject: [PATCH] ENH: Tests for queries. --- .docker/Dockerfile | 2 +- ...{caosdb-client.json => caosdb_client.json} | 0 .miss_hit | 7 ++++ test/Run_Test.m | 7 ++-- test/test_caosdb.m | 34 +++++++++++++------ 5 files changed, 36 insertions(+), 14 deletions(-) rename .docker/{caosdb-client.json => caosdb_client.json} (100%) create mode 100644 .miss_hit diff --git a/.docker/Dockerfile b/.docker/Dockerfile index 58037e1..085d3cd 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -11,7 +11,7 @@ COPY . /caosdb-octaveinttest WORKDIR /caosdb-octaveinttest RUN rm -rf .git -COPY .docker/caosdb-client.json /caosdb-client.json +COPY .docker/caosdb_client.json /caosdb_client.json # build and install octave-lib WORKDIR /caosdb-octavelib diff --git a/.docker/caosdb-client.json b/.docker/caosdb_client.json similarity index 100% rename from .docker/caosdb-client.json rename to .docker/caosdb_client.json diff --git a/.miss_hit b/.miss_hit new file mode 100644 index 0000000..f15ccfe --- /dev/null +++ b/.miss_hit @@ -0,0 +1,7 @@ +# -*- mode:conf; -*- +# See https://florianschanda.github.io/miss_hit/style_checker.html + +line_length: 100 +regex_function_name: "[a-z]+(_[a-z]+)*" +suppress_rule: "whitespace_comments" +tab_width: 2 diff --git a/test/Run_Test.m b/test/Run_Test.m index b698325..702f75f 100644 --- a/test/Run_Test.m +++ b/test/Run_Test.m @@ -17,7 +17,10 @@ % along with this program. If not, see <https://www.gnu.org/licenses/>. pkg load caosdb; -test_result = moxunit_runtests("-verbose", "test_caosdb.m"); -if not(test_result) + +all_tests = true; +all_tests &= moxunit_runtests("-verbose", "test_caosdb.m"); + +if not(all_tests) exit(1); end diff --git a/test/test_caosdb.m b/test/test_caosdb.m index 15bab29..0c0bf37 100644 --- a/test/test_caosdb.m +++ b/test/test_caosdb.m @@ -63,7 +63,7 @@ function test_retrieve_single() c = Caosdb(); % Retrieve a single entity - violin = c.retrieve("120"){1}; + violin = c.retrieve_by_id("120"){1}; % Check content assertEqual(violin.name, "Sherlock Holmes' violin"); @@ -82,8 +82,8 @@ end function test_retrieve_multiple() % Retrieve two entities c = Caosdb(); - violin = c.retrieve("120"){1}; - collection = c.retrieve({"120", "119"}); + violin = c.retrieve_by_id("120"){1}; + collection = c.retrieve_by_id({"120", "119"}); assertEqual(length(collection), 2); assertEqual(numel(collection), 2); @@ -99,24 +99,36 @@ function test_retrieve_multiple() assertEqual(props{2}.value, 7.68315); end +%% Test query execution +function test_execute_query() + c = Caosdb(); + violin = c.query("FIND Record Violin WITH name=\"Sherlock Holmes' violin\""){1}; + props = violin.get_properties(); + assertEqual(props{1}.name, "price"); + assertEqual(props{1}.value, 814873.0); + assertEqual(props{2}.name, "Manufacturer"); + assertEqual(props{2}.value, "119"); +end + +% Error handling tests %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %% Test retrieval with errors function test_retrieve_failure() % Default connection configuration is sufficient. c = Caosdb(); % Retrieve a non-existing entity. - does_not_exist = c.retrieve("i-do-not-exist"){1}; + does_not_exist = c.retrieve_by_id("i-do-not-exist"){1}; assertTrue(does_not_exist.has_errors()); error = does_not_exist.get_errors(){1}; assertEqual(typeinfo(error.code), "int64 scalar"); assertEqual(error.code, int64(2)); assertEqual(error.description, "Entity does not exist."); +end - % Call retrieve with wrong arguments. - % (Only m file level, no invalid arguments should make it to the mex function.) - assertExceptionThrown(@()c.retrieve(120), "maox:InvalidArgument"); - assertExceptionThrown(@()c.retrieve({120}), "maox:InvalidArgument"); - assertExceptionThrown(@()c.retrieve({"120"}, {}), "maox:InvalidArgument"); - assertExceptionThrown(@()c.retrieve({"120"}, {120}), "maox:InvalidArgument"); - assertExceptionThrown(@()c.retrieve({"120"}, {"120", 120}), "maox:InvalidArgument"); +%% Test querying with errors +function test_execute_query_failure() + c = Caosdb(); + results = c.query("FIND Record I-Do-Not-Exist"); % Must not segfault. + assertTrue(isempty(results)); end -- GitLab