Skip to content

Commit b9074e7

Browse files
committed
fix fasta compatibility test
1 parent 3caf2eb commit b9074e7

1 file changed

Lines changed: 32 additions & 25 deletions

File tree

‎tests/DPPOP.Tests/FastaCompatibilityTests.fs‎

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,42 @@ open Xunit
66
open BioFSharp
77
open 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

1721
type 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

Comments
 (0)