Skip to content

Commit

Permalink
Add fixtures & unit tests for ParamBasedParsers
Browse files Browse the repository at this point in the history
  • Loading branch information
omaus committed Jan 9, 2024
1 parent a34c207 commit d94eb63
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 6 deletions.
31 changes: 27 additions & 4 deletions playground.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
//File.Copy(dllBasePath + "/FsSpreadsheet.ExcelIO/bin/Debug/netstandard2.0/FsSpreadsheet.ExcelIO.dll", dllBasePath + "/FsSpreadsheet.ExcelIO/bin/Debug/netstandard2.0/FsSpreadsheet.ExcelIO_Copy.dll", true)
//File.Copy(@"C:\Repos\nfdi4plants\ArcGraphModel\src\ArcGraphModel\bin\Debug\net6.0\ArcGraphModel.dll", @"C:\Repos\nfdi4plants\ArcGraphModel\src\ArcGraphModel\bin\Debug\net6.0\ArcGraphModel_Copy.dll", true)

#r "nuget: DocumentFormat.OpenXml"
#r "nuget: FSharpAux"
#r "nuget: FsOboParser"
#r "nuget: FsSpreadsheet, 3.1.1"
#r "nuget: FsSpreadsheet.ExcelIO, 3.1.1"
#r "nuget: FSharp.FGL"
#r "nuget: FsSpreadsheet.ExcelIO, 4.1.0"
#r "nuget: FSharp.FGL.ArrayAdjacencyGraph"

open DocumentFormat.OpenXml
Expand Down Expand Up @@ -45,6 +42,32 @@ open FsOboParser
open ControlledVocabulary
open type ControlledVocabulary.ParamBase
open ARCTokenization
open ARCTokenization.StructuralOntology

System.IO.Directory.GetCurrentDirectory()
let fakePath = CvParam(cvTerm = AFSO.``File Path``, v = System.IO.Directory.GetCurrentDirectory() + "/tests/ARCTokenization.Tests/Fixtures/correct/investigation_simple.xlsx")

let fakePath = CvParam(cvTerm = AFSO.``File Path``, v = "tests/ARCTokenization.Tests/Fixtures/correct/assay_simple.xlsx")
let actual = ParamBasedParsers.parseIsaMetadataSheetFromCvp "assay_simple.xlsx" Assay.parseMetadataSheetFromFile [fakePath] |> Seq.head
actual.Length
let exp =
ARCMock.AssayMetadataTokens(
Assay_File_Name = [@"measurement1\isa.assay.xlsx"],
Assay_Performer_First_Name = ["Oliver"; "Marius"],
Assay_Performer_Last_Name = ["Maus"; "Katz"],
Assay_Performer_Mid_Initials = [""; "G."],
Assay_Performer_Email = ["[email protected]"],
Assay_Performer_Affiliation = ["RPTU University of Kaiserslautern"],
Assay_Performer_Roles = ["research assistant"],
Assay_Performer_Roles_Term_Accession_Number = ["http://purl.org/spar/scoro/research-assistant"],
Assay_Performer_Roles_Term_Source_REF = ["scoro"]
)
|> List.concat
exp.Length
actual |> List.fold (fun acc ip -> $"{acc}\n{ip.Name}") "" |> printfn "%s"
exp |> List.iter (fun ip -> printfn $"{ip.Name}")
for i = 0 to 33 do
printfn $"{List.tryItem i actual |> Option.map (fun x -> x.Name) |> Option.defaultValue System.String.Empty}\t{List.tryItem i exp |> Option.map (fun x -> x.Name) |> Option.defaultValue System.String.Empty}"

let testAccession1 = "TO:00000001"
let testName1 = "Test"
Expand Down
Binary file not shown.
Binary file not shown.
26 changes: 25 additions & 1 deletion tests/ARCTokenization.Tests/IntegrationTests/AssayMetadata.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,28 @@ module AssayMetadata =

let allExpectedMetadataTermsEmpty =
Terms.AssayMetadata.nonObsoleteNonRootCvTerms
|> List.map (fun p -> CvParam(p, ParamValue.CvValue (CvTerm.create(accession = "AGMO:00000001", name = "Metadata Section Key", ref = "AGMO")), []))
|> List.map (fun p -> CvParam(p, ParamValue.CvValue (CvTerm.create(accession = "AGMO:00000001", name = "Metadata Section Key", ref = "AGMO")), []))

open ARCTokenization.StructuralOntology

let allExpectedMetadataTermsFull =
ARCMock.AssayMetadataTokens(
Assay_File_Name = [@"measurement1\isa.assay.xlsx"],
Assay_Performer_First_Name = ["Oliver"; "Marius"],
Assay_Performer_Last_Name = ["Maus"; "Katz"],
Assay_Performer_Mid_Initials = [""; "G."],
Assay_Performer_Email = ["[email protected]"],
Assay_Performer_Affiliation = ["RPTU University of Kaiserslautern"],
Assay_Performer_Roles = ["research assistant"],
Assay_Performer_Roles_Term_Accession_Number = ["http://purl.org/spar/scoro/research-assistant"],
Assay_Performer_Roles_Term_Source_REF = ["scoro"]
)
|> List.concat // use flat list

[<Fact>]
let ``Simple study is parsed from filepath CvParam with all structural ontology terms in order`` () =
let fakePath = CvParam(cvTerm = AFSO.``File Path``, v = "Fixtures/correct/assay_simple.xlsx")
let actual = ParamBasedParsers.parseIsaMetadataSheetFromCvp "assay_simple.xlsx" Assay.parseMetadataSheetFromFile [fakePath] |> Seq.head
Assert.All((List.zip allExpectedMetadataTermsFull actual), (fun (expected,actual) ->
CvParam.structuralEquality (expected) (actual :?> CvParam)
))
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,14 @@ module InvestigationMetadata =
let ``Simple investigation is parsed with all structural ontology terms in order`` () =
Assert.All((List.zip allExpectedMetadataTermsFull parsedInvestigationMetadataSimple), (fun (expected,actual) ->
CvParam.structuralEquality (expected) (actual :?> CvParam)
))

open ARCTokenization.StructuralOntology

[<Fact>]
let ``Simple investigation is parsed from filepath CvParam with all structural ontology terms in order`` () =
let fakePath = CvParam(cvTerm = AFSO.``File Path``, v = "Fixtures/correct/investigation_simple.xlsx")
let actual = ParamBasedParsers.parseIsaMetadataSheetFromCvp "investigation_simple.xlsx" Investigation.parseMetadataSheetFromFile [fakePath] |> Seq.head
Assert.All((List.zip allExpectedMetadataTermsFull actual), (fun (expected,actual) ->
CvParam.structuralEquality (expected) (actual :?> CvParam)
))
21 changes: 20 additions & 1 deletion tests/ARCTokenization.Tests/IntegrationTests/StudyMetadata.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,23 @@ module StudyMetadata =

let allExpectedMetadataTermsEmpty =
Terms.StudyMetadata.nonObsoleteNonRootCvTerms
|> List.map (fun p -> CvParam(p, ParamValue.CvValue (CvTerm.create(accession = "AGMO:00000001", name = "Metadata Section Key", ref = "AGMO")), []))
|> List.map (fun p -> CvParam(p, ParamValue.CvValue (CvTerm.create(accession = "AGMO:00000001", name = "Metadata Section Key", ref = "AGMO")), []))

let allExpectedMetadataTermsFull =
ARCMock.StudyMetadataTokens(
Study_Identifier = ["experiment1_material"],
Study_Title = ["Prototype for experimental data"],
Study_Description = ["In this a devised study to have an exemplary experimental material description."],
Study_File_Name = [@"experiment1_material\isa.study.xlsx"]
)
|> List.concat // use flat list

open ARCTokenization.StructuralOntology

[<Fact>]
let ``Simple study is parsed from filepath CvParam with all structural ontology terms in order`` () =
let fakePath = CvParam(cvTerm = AFSO.``File Path``, v = "Fixtures/correct/study_simple.xlsx")
let actual = ParamBasedParsers.parseIsaMetadataSheetFromCvp "study_simple.xlsx" Study.parseMetadataSheetfromFile [fakePath] |> Seq.head
Assert.All((List.zip allExpectedMetadataTermsFull actual), (fun (expected,actual) ->
CvParam.structuralEquality (expected) (actual :?> CvParam)
))

0 comments on commit d94eb63

Please sign in to comment.