Commit 57098570 authored by Siebers, Michael's avatar Siebers, Michael
Browse files

Merge branch '63-endpoint-irrelevant-file-returns-500' into 'master'

Fix exceptions in `irrelvance_common` predicates

Closes #63

See merge request cogsys/dare2del/demonstrator!29
parents cf8dff21 776f0c5d
...@@ -430,13 +430,11 @@ system_test:endpoint_irrelevant@file: ...@@ -430,13 +430,11 @@ system_test:endpoint_irrelevant@file:
extends: .system_test:run_with_data_and_db extends: .system_test:run_with_data_and_db
variables: variables:
TEST_NAME: endpoint_irrelevant@file TEST_NAME: endpoint_irrelevant@file
allow_failure: true # see issue #63
system_test:endpoint_explain: system_test:endpoint_explain:
extends: .system_test:run_with_data_and_db extends: .system_test:run_with_data_and_db
variables: variables:
TEST_NAME: endpoint_explain TEST_NAME: endpoint_explain
allow_failure: true # see issue #63
system_test:robust against wrong method: system_test:robust against wrong method:
extends: .system_test:run_with_data extends: .system_test:run_with_data
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
* - media_type": "img": the media type of the file * - media_type": "img": the media type of the file
* *
* *
* For a _directory_ the following information is avalable: * For a _directory_ the following information is available:
* - abs_path (atom): the absolute path of the file * - abs_path (atom): the absolute path of the file
* - creation_time (integer): the time the file was created as seconds since * - creation_time (integer): the time the file was created as seconds since
* epoch (1970-07-07) * epoch (1970-07-07)
...@@ -47,7 +47,7 @@ abs_path(Item, Path) :- theory_bg:item(Item, Dict), Path=Dict.abs_path, !. ...@@ -47,7 +47,7 @@ abs_path(Item, Path) :- theory_bg:item(Item, Dict), Path=Dict.abs_path, !.
%! file_size(+Item, -Size) is semidet. %! file_size(+Item, -Size) is semidet.
% %
% Extract the file size of a file. Fails is Item is a directory. % Extract the file size of a file. Fails is Item is a directory.
file_size(Item, Size) :- theory_bg:item(Item, Dict), !, Size=Dict.file_size. file_size(Item, Size) :- theory_bg:item(Item, Dict), !, Size=Dict.get(file_size).
%! directory(?Item) is semidet. %! directory(?Item) is semidet.
...@@ -59,7 +59,7 @@ directory(Item) :- theory_bg:item(Item, Dict), is_dict(Dict,directory). ...@@ -59,7 +59,7 @@ directory(Item) :- theory_bg:item(Item, Dict), is_dict(Dict,directory).
%! in_directory(+Item,?Directory) is semidet. %! in_directory(+Item,?Directory) is semidet.
% %
% Extracts the base directory of an item. Only holds if the base directory is % Extracts the base directory of an item. Only holds if the base directory is
% Also in the background knowledge. % also in the background knowledge.
in_directory(Item, Directory) :- in_directory(Item, Directory) :-
abs_path(Item, ItemPath), abs_path(Item, ItemPath),
ItemPath \= '/', % Per POSIX definition '/' is in path '/'. ItemPath \= '/', % Per POSIX definition '/' is in path '/'.
...@@ -121,26 +121,29 @@ item_split_(Item,Basename,Ext) :- ...@@ -121,26 +121,29 @@ item_split_(Item,Basename,Ext) :-
%! creation_time(++Item, -Timestamp) is semidet. %! creation_time(++Item, -Timestamp) is semidet.
% %
% Returns the creation time of the item. % Returns the creation time of the item.
creation_time(Item,Time) :- theory_bg:item(Item, Dict), !, creation_time(Item, Time) :- theory_bg:item(Item, Dict), !,
Time=Dict.creation_time. Time=Dict.get(creation_time).
%! change_time(++Item, -Timestamp) is semidet. %! change_time(++File, -Timestamp) is semidet.
% %
% Returns the change time of the item. % Returns the change time of the a file. File is the absolute
change_time(Item,Time) :- theory_bg:item(Item, Dict), !, % path of the file. Fails if File is a directory.
Time=Dict.change_time. change_time(File, Time) :- theory_bg:item(File, Dict), !,
Time=Dict.get(change_time).
%! modification_time(++Item, -Timestamp) is semidet. %! modification_time(++File, -Timestamp) is semidet.
% %
% Returns the modification time of the item. % Returns the modification time of a file. File is the absolute
modification_time(Item,Time) :- theory_bg:item(Item, Dict), !, % path of the file. Fails if File is a directory.
Time=Dict.modification_time. modification_time(File, Time) :- theory_bg:item(File, Dict), !,
Time=Dict.get(modification_time).
%! access_time(++Item, -Timestamp) is semidet. %! access_time(++File, -Timestamp) is semidet.
% %
% Returns the access time of the item. % Returns the access time of the a file. File is the absolute
access_time(Item,Time) :- theory_bg:item(Item, Dict), !, % path of the file. Fails if File is a directory.
Time=Dict.access_time. access_time(File, Time) :- theory_bg:item(File, Dict), !,
Time=Dict.get(access_time).
%! newer(++File1, ++File2) is semidet. %! newer(++File1, ++File2) is semidet.
......
...@@ -27,7 +27,7 @@ test(file_findall, [true(Fs == TrueFs), setup(findall(TF, theory_bg:file(TF),Tru ...@@ -27,7 +27,7 @@ test(file_findall, [true(Fs == TrueFs), setup(findall(TF, theory_bg:file(TF),Tru
%% %%
%% abs_path/1 %% abs_path/2
%% %%
% abs_path(+Item,+Path) is semidet. % abs_path(+Item,+Path) is semidet.
...@@ -39,20 +39,50 @@ test(abs_path_semibound, forall(theory_bg:abs_path(TrueItemId,TrueAbsPath))) :- ...@@ -39,20 +39,50 @@ test(abs_path_semibound, forall(theory_bg:abs_path(TrueItemId,TrueAbsPath))) :-
% abs_path(+Item, -Path) det if item is known, false else % abs_path(+Item, -Path) det if item is known, false else
test(abs_path_semidet) :- test(abs_path_semidet) :-
semidet_for_item(abs_path/2). semidet_for_item(abs_path/2).
%%
%% file_size/2
%% %%
%% file_size/1
%%
% file_size(+Item,+Size) is semidet.
% file_size(+Item,-Size) is semidet. % file_size(+Item,-Size) is semidet.
test(file_size_semibound, forall(theory_bg:file_size(TrueFileId,TrueSize))) :- test(file_size_unbound_semidet_true, [forall(theory_bg:file(FileId))]) :-
first_bound(file_size/2, [TrueFileId, TrueSize]). file_size(FileId, _Size).
test(file_size_unbound_semidet_false,
% file_fize(+File, -Size) det if file is known, false else [forall(theory_bg:item_false(UnknownId)), fail]) :-
test(file_size_semidet) :- file_size(UnknownId, _Size).
semidet_for_file(file_size/2).
% file_size(+File, -Size) correct
test(file_size_correct,
[forall(theory_bg:file_size(FileId, ExpectedSize)),
true(Size == ExpectedSize)
]) :- file_size(FileId, Size).
% file_size(+File, +Size) is semidet.
test(file_size_bound_semidet_true,
[forall(theory_bg:file_size(FileId, ExpectedSize))]) :-
file_size(FileId, ExpectedSize).
test(file_size_bound_semidet_false,
[forall(theory_bg:file_size(FileId, ExpectedSize)),
setup(WrongSize is ExpectedSize + 10),
fail]) :-
file_size(FileId, WrongSize).
% file_size(+Directory, -Size) fails
test(file_size_fails_for_directory_unbound,
[forall(theory_bg:file_false(DirId)), fail]) :-
file_size(DirId, _Size).
% file_size(+Directory, +Size) fails
test(file_size_fails_for_directory_bound,
[forall((
theory_bg:file_false(DirId),
member(AnySize, [-123456, 0, 18, 1024, 1700000000])
)),
fail]) :-
file_size(DirId, AnySize).
%% %%
%% directory/1 %% directory/1
%% %%
...@@ -127,41 +157,162 @@ test(item_base_name_semidet) :- ...@@ -127,41 +157,162 @@ test(item_base_name_semidet) :-
semidet_for_file(item_base_name/2). semidet_for_file(item_base_name/2).
% access_time(+Item,-Time) is semidet. %%
% change_time(+Item,-Time) is semidet. %% creation_time/2
% creation_time(+Item,-Time) is semidet. %%
% modification_time(+Item,-Time) is semidet.
test(time_semibound, forall( % creation_time(+Item, -Time) is semidet.
( member(TimePred, [ test(creation_time_unbound_semidet_true,
access_time, [forall(theory_bg:item(KnownId))]) :-
change_time, creation_time(KnownId, _Time).
creation_time, test(creation_time_unbound_semidet_false,
modification_time [forall(theory_bg:item_false(UnknownId)), fail]) :-
]), creation_time(UnknownId, _Time).
call(theory_bg:TimePred,TrueItemId,TrueTime)
)
)) :- % creation_time(+Item, -Time) correct
first_bound(TimePred/2, [TrueItemId, TrueTime]). test(creation_time_correct,
[forall(theory_bg:creation_time(ItemId, ExpectedTime)),
true(Time == ExpectedTime)
]) :- creation_time(ItemId, Time).
% creation_time(+Item, +Time) is semidet.
test(modification_time_bound_semidet_true,
[forall(theory_bg:creation_time(ItemId, ExpectedTime))]) :-
creation_time(ItemId, ExpectedTime).
test(modification_time_bound_semidet_false,
[forall(theory_bg:creation_time(ItemId, ExpectedTime)),
setup(WrongTime is ExpectedTime + 10),
fail]) :-
creation_time(ItemId, WrongTime).
%%
%% modification_time/2
%%
% modification_time(+File, -Time) is semidet.
test(modification_time_unbound_semidet_true, [forall(theory_bg:file(FileId))]) :-
modification_time(FileId, _Time).
test(modification_time_unbound_semidet_false,
[forall(theory_bg:item_false(UnknownId)), fail]) :-
modification_time(UnknownId, _Time).
% modification_time(+File, -Time) correct
test(modification_time_correct,
[forall(theory_bg:modification_time(FileId, ExpectedTime)),
true(Time == ExpectedTime)
]) :- modification_time(FileId, Time).
% modification_time(+File, +Time) is semidet.
test(modification_time_bound_semidet_true,
[forall(theory_bg:modification_time(FileId, ExpectedTime))]) :-
modification_time(FileId, ExpectedTime).
test(modification_time_bound_semidet_false,
[forall(theory_bg:modification_time(FileId, ExpectedTime)),
setup(WrongTime is ExpectedTime + 10),
fail]) :-
modification_time(FileId, WrongTime).
% modification_time(+Directory, -Size) fails
test(modification_time_fails_for_directory_unbound,
[forall(theory_bg:file_false(DirId)), fail]) :-
modification_time(DirId, _Time).
% modification_time(+Directory, +Size) fails
test(modification_time_fails_for_directory_bound,
[forall((
theory_bg:file_false(DirId),
member(AnyTime, [-123456, 0, 18, 1024, 1700000000])
)),
fail]) :-
modification_time(DirId, AnyTime).
%%
%% access_time/2
%%
% access_time(+File, -Time) is semidet.
test(access_time_unbound_semidet_true, [forall(theory_bg:file(FileId))]) :-
access_time(FileId, _Time).
test(access_time_unbound_semidet_false,
[forall(theory_bg:item_false(UnknownId)), fail]) :-
access_time(UnknownId, _Time).
% access_time(+File, -Time) correct
test(access_time_correct,
[forall(theory_bg:access_time(FileId, ExpectedTime)),
true(Time == ExpectedTime)
]) :- access_time(FileId, Time).
% access_time(+File, +Time) is semidet.
test(access_time_bound_semidet_true,
[forall(theory_bg:access_time(FileId, ExpectedTime))]) :-
access_time(FileId, ExpectedTime).
test(access_time_bound_semidet_false,
[forall(theory_bg:access_time(FileId, ExpectedTime)),
setup(WrongTime is ExpectedTime + 10),
fail]) :-
access_time(FileId, WrongTime).
% access_time(+Directory, -Size) fails
test(access_time_fails_for_directory_unbound,
[forall(theory_bg:file_false(DirId)), fail]) :-
access_time(DirId, _Time).
% access_time(+Directory, +Size) fails
test(access_time_fails_for_directory_bound,
[forall((
theory_bg:file_false(DirId),
member(AnyTime, [-123456, 0, 18, 1024, 1700000000])
)),
fail]) :-
access_time(DirId, AnyTime).
%%
%% change_time/2
%%
% change_time(+File, -Time) is semidet.
test(change_time_unbound_semidet_true, [forall(theory_bg:file(FileId))]) :-
change_time(FileId, _Time).
test(change_time_unbound_semidet_false,
[forall(theory_bg:item_false(UnknownId)), fail]) :-
change_time(UnknownId, _Time).
% change_time(+File, -Time) correct
test(change_time_correct,
[forall(theory_bg:change_time(FileId, ExpectedTime)),
true(Time == ExpectedTime)
]) :- change_time(FileId, Time).
% change_time(+File, +Time) is semidet.
test(change_time_bound_semidet_true,
[forall(theory_bg:change_time(FileId, ExpectedTime))]) :-
change_time(FileId, ExpectedTime).
test(change_time_bound_semidet_false,
[forall(theory_bg:change_time(FileId, ExpectedTime)),
setup(WrongTime is ExpectedTime + 10),
fail]) :-
change_time(FileId, WrongTime).
% change_time(+Directory, -Size) fails
test(change_time_fails_for_directory_unbound,
[forall(theory_bg:file_false(DirId)), fail]) :-
change_time(DirId, _Time).
% change_time(+Directory, +Size) fails
test(change_time_fails_for_directory_bound,
[forall((
theory_bg:file_false(DirId),
member(AnyTime, [-123456, 0, 18, 1024, 1700000000])
)),
fail]) :-
change_time(DirId, AnyTime).
% creation_time(+Item, -Time) det if Item is known, false else
test(creation_time_semidet) :-
semidet_for_item(creation_time/2).
% access_time(+File, -Time) det if file is known, false else
% change_time(+File, -Time) det if file is known, false else
% modification_time(+File, -Time) det if file is known, false else
test(creation_time_semidet, forall(member(TimePred, [
access_time,
change_time,
modification_time
]))
) :-
semidet_for_file(TimePred/2).
%% %%
%% newer/2 %% newer/2
%% %%
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment