Skip to content

Commit

Permalink
Adding path expansion tests for tractor.session
Browse files Browse the repository at this point in the history
  • Loading branch information
jonclayden committed Nov 7, 2023
1 parent 631a5d8 commit 2fbaff8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tractor.session/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Author: Jon Clayden and Kiran Seunarine
Maintainer: Jon Clayden <code@clayden.org>
Depends: R (>= 2.12.1), methods
Imports: ore, reportr, tractor.base, yaml
Suggests: mmand, RNiftyReg, tractor.reg, tractor.track
Suggests: mmand, RNiftyReg, tractor.reg, tractor.track, tinytest
Description: The tractor.session package provides functions for working with TractoR sessions, which are file hierarchies which represent an MRI scan session. It also provides wrapper functions for interacting between the TractoR bundle and the FMRIB Software Library (FSL; see http://www.fmrib.ox.ac.uk/fsl/) and Camino (http://www.camino.org.uk). The package exposes to R several FSL and Camino tools employed in a typical tractography workflow.
Encoding: UTF-8
License: GPL-2
Expand Down
35 changes: 35 additions & 0 deletions tractor.session/inst/tinytest/test_paths.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
reportr::setOutputLevel(Info)
options(reportrStderrLevel=reportr::OL$Fatal)

# Fake session path (including tractor subdirectory to reduce repetition)
fsp <- normalizePath(tempdir())
fstp <- file.path(fsp, "tractor")
dir.create(fstp, recursive=TRUE)

resolvePath <- function (path, ...) {
path <- gsub("FSP", fsp, path, perl=TRUE)
structure(tractor.base::resolvePath(path, ...), names=NULL)
}

wd <- getwd()
on.exit(setwd(wd))

# Unambiguous image name
expect_equal(resolvePath("FSP@fa"), file.path(fstp,"diffusion","dti_FA"))

# Indexed image name
expect_equal(resolvePath("FSP@eigenvalue",index=2), file.path(fstp,"diffusion","dti_eigval2"))

# Directory path
expect_equal(resolvePath("FSP@diffusion/"), file.path(fstp,"diffusion"))

# Ambiguous image name, requiring subdirectory to be specified
expect_equal(resolvePath("FSP@diffusion/data"), file.path(fstp,"diffusion","data"))
expect_equal(resolvePath("FSP@functional/data"), file.path(fstp,"functional","data"))

# Non-image path, relying on fallback
expect_equal(resolvePath("FSP@diffusion/directions.txt",index=2), file.path(fstp,"diffusion","directions.txt"))

# Shorthand for when the session directory is the current directory
setwd(fsp)
expect_equal(resolvePath("@MD"), file.path(fstp,"diffusion","dti_MD"))
5 changes: 5 additions & 0 deletions tractor.session/tests/tinytest.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

if ( requireNamespace("tinytest", quietly=TRUE) ){
tinytest::test_package("tractor.session")
}

0 comments on commit 2fbaff8

Please sign in to comment.