@@ -6,35 +6,42 @@ open Xunit
66open BioFSharp
77open DPPOP.CLI
88
9- module private TestPaths =
9+ module private FastaCompatibilityTestData =
1010
11- let repoRoot =
12- Path.GetFullPath ( Path.Combine ( AppContext.BaseDirectory , " .. " , " .. " , " .. " , " .. " , " .. " ) )
11+ let withTemporaryFasta contents run =
12+ let tempPath = Path.Combine ( Path.GetTempPath (), $ " {Guid.NewGuid():N}.fasta " )
1313
14- let testFasta =
15- Path.Combine( repoRoot, " src" , " BioFSharp.ML" , " Resources" , " test.fasta" )
14+ try
15+ File.WriteAllText( tempPath, contents)
16+ run tempPath
17+ finally
18+ if File.Exists( tempPath) then
19+ File.Delete( tempPath)
1620
1721type FastaCompatibilityTests () =
1822
1923 [<Fact>]
2024 member _. ``CLI input sanitation removes illegal characters and reports them`` () =
21- Assert.True(
22- File.Exists( TestPaths.testFasta),
23- $" Expected test FASTA at '{TestPaths.testFasta}'."
24- )
25-
26- let result = Input.readFastaWithSanitation TestPaths.testFasta
27-
28- Assert.True( result.EncounteredIllegalCharacters)
29- Assert.Single( result.Entries) |> ignore
30-
31- let sanitizedSequence =
32- result.Entries
33- |> Array.exactlyOne
34- |> fun entry -> entry.Sequence
35- |> Array.ofSeq
36- |> BioArray.toString
37-
38- Assert.DoesNotContain( " *" , sanitizedSequence)
39- Assert.DoesNotContain( " -" , sanitizedSequence)
40- Assert.EndsWith( " TTLS" , sanitizedSequence)
25+ let fastaContents =
26+ String.concat
27+ Environment.NewLine
28+ [|
29+ " >test-protein"
30+ " MDATSKADLPDYAADNRLPPWLLPDQEGKPAGRHLHYRPDILLIPSISLAAALNPDFVVLPSERDTIHIIEAGYTADTNHAAKQHEKAQQQQALAADLREAGWKVQYTPQSAISLGFAGTIRKDLHPLLTSLPTKPGSAATPYTTTQSPPSTT-LS*"
31+ |]
32+
33+ FastaCompatibilityTestData.withTemporaryFasta fastaContents <| fun fastaPath ->
34+ let result = Input.readFastaWithSanitation fastaPath
35+
36+ Assert.True( result.EncounteredIllegalCharacters)
37+
38+ let entry = Assert.Single( result.Entries)
39+
40+ let sanitizedSequence =
41+ entry.Sequence
42+ |> Array.ofSeq
43+ |> BioArray.toString
44+
45+ Assert.DoesNotContain( " *" , sanitizedSequence)
46+ Assert.DoesNotContain( " -" , sanitizedSequence)
47+ Assert.EndsWith( " TTLS" , sanitizedSequence)
0 commit comments