Skip to content

Commit

Permalink
Add cwl test
Browse files Browse the repository at this point in the history
  • Loading branch information
caroott authored and kMutagene committed Oct 21, 2024
1 parent 1932c44 commit 6ae8e47
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/ARCtrl/ARC.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module ARCAux =
|> FileSystem.create
fs.Union(tree)

let updateFSByCWL (cwl : CWL.CWL option) (fs : FileSystem) =
let updateFSByCWL (cwl : CWL.CWLProcessingUnits.CWLToolDescription option) (fs : FileSystem) =
let workflows = FileSystemTree.createWorkflowsFolder [||]
let runs = FileSystemTree.createRunsFolder [||]
let tree =
Expand All @@ -65,7 +65,7 @@ module ARCAux =


[<AttachMembers>]
type ARC(?isa : ArcInvestigation, ?cwl : CWL.CWL, ?fs : FileSystem.FileSystem) =
type ARC(?isa : ArcInvestigation, ?cwl : CWL.CWLProcessingUnits.CWLToolDescription, ?fs : FileSystem.FileSystem) =

let mutable _isa = isa
let mutable _cwl = cwl
Expand Down
3 changes: 1 addition & 2 deletions src/CWL/ARCtrl.CWL.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
<Compile Include="CWL.fs" />
<Compile Include="Decode.fs" />
<Compile Include="Encode.fs" />
<Compile Include="Library.fs" />
</ItemGroup>
<ItemGroup>
<None Include="../../build/logo.png" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="YAMLicious" Version="[0.0.2]" />
<PackageReference Include="DynamicObj" Version="[2.0.0]" />
<PackageReference Include="DynamicObj" Version="[3.1.0]" />
</ItemGroup>
<PropertyGroup>
<Authors>nfdi4plants</Authors>
Expand Down
3 changes: 0 additions & 3 deletions src/CWL/Library.fs

This file was deleted.

1 change: 1 addition & 0 deletions tests/CWL/ARCtrl.CWL.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="TestUtil.fs" />
<Compile Include="CWLObject.Tests.fs" />
<Compile Include="Main.fs" />
</ItemGroup>
<ItemGroup>
Expand Down
157 changes: 157 additions & 0 deletions tests/CWL/CWLObject.Tests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
module Tests.CWLObject

open ARCtrl.CWL
open ARCtrl.CWL.CWLTypes
open ARCtrl.CWL.Requirements
open ARCtrl.CWL.Inputs
open ARCtrl.CWL.Outputs
open YAMLicious
open TestingUtils


let decodeOutput =
TestUtil.outputs
|> Decode.read
|> Decode.outputsDecoder

let decodeInput =
TestUtil.inputs
|> Decode.read
|> Decode.inputsDecoder

let decodeRequirement =
TestUtil.requirements
|> Decode.read
|> Decode.requirementsDecoder

let decodeCWLToolDescription =
TestUtil.cwl
|> Decode.decodeAll

let testOutput =
testList "outputs with basetypes and array" [
testCase "Length" <| fun _ -> Expect.isTrue (4 = decodeOutput.Length) "Length of outputs is not 4"
testList "File" [
let fileItem = decodeOutput.[0]
testCase "Name" <| fun _ -> Expect.isTrue ("output" = fileItem.Name) "Name of output is not 'output'"
testCase "Type" <| fun _ -> Expect.isTrue ((File (FileInstance())) = fileItem.Type) "Type of output is not File"
testCase "OutputBinding" <| fun _ -> Expect.isTrue (Some {Glob = Some "./arc/runs/fsResult1/result.csv"} = fileItem.OutputBinding) "OutputBinding of output is not Some Pattern"
]
testList "Directory" [
let directoryItem = decodeOutput.[1]
testCase "Name" <| fun _ -> Expect.isTrue ("example" = directoryItem.Name) "Name of output is not 'example'"
testCase "Type" <| fun _ -> Expect.isTrue ((Directory (DirectoryInstance())) = directoryItem.Type) "Type of output is not Directory"
testCase "OutputBinding" <| fun _ -> Expect.isTrue (Some {Glob = Some "./arc/runs/fsResult1/example.csv"} = directoryItem.OutputBinding) "OutputBinding of output is not Some Pattern"
]
testList "File Array" [
let fileArrayItem = decodeOutput.[2]
testCase "Name" <| fun _ -> Expect.isTrue ("exampleArray1" = fileArrayItem.Name) "Name of output is not 'exampleArray1'"
testCase "Type" <| fun _ -> Expect.isTrue ((Array (File (FileInstance()))) = fileArrayItem.Type) "Type of output is not Array File"
testCase "OutputBinding" <| fun _ -> Expect.isTrue (Some {Glob = Some "./arc/runs/fsResult1/example.csv"} = fileArrayItem.OutputBinding) "OutputBinding of output is not Some Pattern"
]
testList "File Array 2" [
let fileArrayItem = decodeOutput.[3]
testCase "Name" <| fun _ -> Expect.isTrue ("exampleArray2" = fileArrayItem.Name) "Name of output is not 'exampleArray2'"
testCase "Type" <| fun _ -> Expect.isTrue ((Array (File (FileInstance()))) = fileArrayItem.Type) "Type of output is not Array File"
testCase "OutputBinding" <| fun _ -> Expect.isTrue (Some {Glob = Some "./arc/runs/fsResult1/example.csv"} = fileArrayItem.OutputBinding) "OutputBinding of output is not Some Pattern"
]
]

let testInput =
testList "inputs with Directory, File and string" [
testCase "Length" <| fun _ -> Expect.isTrue (3 = decodeInput.Length) "Length of inputs is not 3"
testList "Directory" [
let directoryItem = decodeInput.[0]
testCase "Name" <| fun _ -> Expect.isTrue ("arcDirectory" = directoryItem.Name) "Name of input is not 'arcDirectory'"
testCase "Type" <| fun _ -> Expect.isTrue ((Directory (DirectoryInstance())) = directoryItem.Type) "Type of input is not Directory"
]
testList "File" [
let fileItem = decodeInput.[1]
testCase "Name" <| fun _ -> Expect.isTrue ("firstArg" = fileItem.Name) "Name of input is not 'firstArg'"
testCase "Type" <| fun _ -> Expect.isTrue ((File (FileInstance())) = fileItem.Type) "Type of input is not File"
testCase "InputBinding" <| fun _ -> Expect.isTrue (Some {Position = Some 1; Prefix = Some "--example"; ItemSeparator = None; Separate = None} = fileItem.InputBinding) "InputBinding of input is not Some Pattern"
]
testList "String" [
let stringItem = decodeInput.[2]
testCase "Name" <| fun _ -> Expect.isTrue ("secondArg" = stringItem.Name) "Name of input is not 'secondArg'"
testCase "Type" <| fun _ -> Expect.isTrue (String = stringItem.Type) "Type of input is not String"
testCase "InputBinding" <| fun _ -> Expect.isTrue (Some {Position = Some 2; Prefix = None; ItemSeparator = None; Separate = Some false} = stringItem.InputBinding) "InputBinding of input is not Some Pattern"
]
]

let testRequirement =
testList "requirements with DockerRequirement, InitialWorkDirRequirement, EnvVarRequirement and NetworkAccess" [
testCase "Length" <| fun _ -> Expect.isTrue (4 = decodeRequirement.Length) "Length of requirements is not 4"
testList "DockerRequirement" [
let dockerItem = decodeRequirement.[0]
testCase "Class" <| fun _ -> Expect.isTrue (DockerRequirement {DockerPull = None; DockerFile = Some "FSharpArcCapsule/Dockerfile"; DockerImageId = Some "devcontainer"} = dockerItem) "Class of requirement is not DockerRequirement"
]
testList "InitialWorkDirRequirement" [
let initialWorkDirItem = decodeRequirement.[1]
testCase "Class" <| fun _ -> Expect.isTrue (InitialWorkDirRequirement [||] = initialWorkDirItem) "Class of requirement is not InitialWorkDirRequirement"
]
testList "EnvVarRequirement" [
let envVarItem = decodeRequirement.[2]
testCase "Class" <| fun _ -> Expect.isTrue (EnvVarRequirement {EnvName = ""; EnvValue = ""} = envVarItem) "Class of requirement is not EnvVarRequirement"
]
testList "NetworkAccess" [
let networkAccessItem = decodeRequirement.[3]
testCase "Class" <| fun _ -> Expect.isTrue (NetworkAccessRequirement = networkAccessItem) "Class of requirement is not NetworkAccess"
]
]

let testCWLToolDescription =
testList "CWLToolDescription" [
testCase "Class" <| fun _ -> Expect.isTrue (Class.CommandLineTool = decodeCWLToolDescription.Class) "Class of CWLToolDescription is not CommandLineTool"
testCase "CWLVersion" <| fun _ -> Expect.isTrue ("v1.2" = decodeCWLToolDescription.CWLVersion) "CWLVersion of CWLToolDescription is not v1.2"
testList "Hints" [
let hintsItem = decodeCWLToolDescription.Hints
testCase "DockerRequirement" <| fun _ -> Expect.isTrue (DockerRequirement {DockerPull = Some "mcr.microsoft.com/dotnet/sdk:6.0"; DockerFile = None; DockerImageId = None} = hintsItem.Value.[0]) "Class of hint is not DockerRequirement"
]
testList "Requirements" [
let requirementsItem = decodeCWLToolDescription.Requirements
testCase "InitialWorkDirRequirement" <| fun _ -> Expect.isTrue (InitialWorkDirRequirement [||] = requirementsItem.Value.[0]) "Class of requirement is not InitialWorkDirRequirement"
testCase "EnvVarRequirement" <| fun _ -> Expect.isTrue (EnvVarRequirement {EnvName = ""; EnvValue = ""} = requirementsItem.Value.[1]) "Class of requirement is not EnvVarRequirement"
testCase "NetworkAccessRequirement" <| fun _ -> Expect.isTrue (NetworkAccessRequirement = requirementsItem.Value.[2]) "Class of requirement is not NetworkAccessRequirement"
]
testList "Inputs" [
let inputsItem = decodeCWLToolDescription.Inputs.Value
testCase "Length" <| fun _ -> Expect.isTrue (2 = inputsItem.Length) "Length of inputs is not 2"
testList "File" [
let fileItem = inputsItem.[0]
testCase "Name" <| fun _ -> Expect.isTrue ("firstArg" = fileItem.Name) "Name of input is not 'firstArg'"
testCase "Type" <| fun _ -> Expect.isTrue ((File (FileInstance())) = fileItem.Type) "Type of input is not File"
testCase "InputBinding" <| fun _ -> Expect.isTrue (Some {Position = Some 1; Prefix = None; ItemSeparator = None; Separate = None} = fileItem.InputBinding) "InputBinding of input is not Some Pattern"
]
testList "String" [
let stringItem = inputsItem.[1]
testCase "Name" <| fun _ -> Expect.isTrue ("secondArg" = stringItem.Name) "Name of input is not 'secondArg'"
testCase "Type" <| fun _ -> Expect.isTrue (String = stringItem.Type) "Type of input is not String"
testCase "InputBinding" <| fun _ -> Expect.isTrue (Some {Position = Some 2; Prefix = None; ItemSeparator = None; Separate = None} = stringItem.InputBinding) "InputBinding of input is not Some Pattern"
]
]
testList "Outputs" [
let outputsItem = decodeCWLToolDescription.Outputs
testCase "Length" <| fun _ -> Expect.isTrue (2 = outputsItem.Length) "Length of outputs is not 2"
testList "Directory" [
let directoryItem = outputsItem.[0]
testCase "Name" <| fun _ -> Expect.isTrue ("output" = directoryItem.Name) "Name of output is not 'output'"
testCase "Type" <| fun _ -> Expect.isTrue ((Directory (DirectoryInstance())) = directoryItem.Type) "Type of output is not Directory"
testCase "OutputBinding" <| fun _ -> Expect.isTrue (Some {Glob = Some "$(runtime.outdir)/.nuget"} = directoryItem.OutputBinding) "OutputBinding of output is not Some Pattern"
]
testList "File" [
let fileItem = outputsItem.[1]
testCase "Name" <| fun _ -> Expect.isTrue ("output2" = fileItem.Name) "Name of output is not 'output2'"
testCase "Type" <| fun _ -> Expect.isTrue ((File (FileInstance())) = fileItem.Type) "Type of output is not File"
testCase "OutputBinding" <| fun _ -> Expect.isTrue (Some {Glob = Some "$(runtime.outdir)/*.csv"} = fileItem.OutputBinding) "OutputBinding of output is not Some Pattern"
]
]
]

let main =
testList "CWL" [
testOutput
testInput
testRequirement
testCWLToolDescription
]
5 changes: 3 additions & 2 deletions tests/CWL/Main.fs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module ARCtrl.CWL.Tests
module CWL.Tests

open Fable.Pyxpecto

let all = testSequenced <| testList "CWL" [
()
Tests.CWLObject.main

]

[<EntryPoint>]
Expand Down

0 comments on commit 6ae8e47

Please sign in to comment.