Skip to content

Commit

Permalink
Add tests for parsing procspec
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Gruson committed Nov 7, 2017
1 parent 110d2dd commit 0576313
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
1 change: 0 additions & 1 deletion R/getspec.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ getspec <- function(where = getwd(), ext = 'txt', lim = c(300, 700), decimal = "
message(length(files), ' files found; importing spectra:')

gsp <- function(ff){

if(grepl("\\.ProcSpec$", ff)){
# ProcSpec files differ too much from the other formats and need their own
# function.
Expand Down
Binary file added examplespec/OceanOptics_Linux.ProcSpec
Binary file not shown.
Binary file added examplespec/OceanOptics_Windows.ProcSpec
Binary file not shown.
Binary file added inst/testdata/OceanOptics_Linux.ProcSpec
Binary file not shown.
Binary file added inst/testdata/OceanOptics_Windows.ProcSpec
Binary file not shown.
25 changes: 14 additions & 11 deletions tests/testthat/test-import.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,33 @@ library(pavo)
context('import')

test_that('getspec', {

## Run through a bunch of file types
avantes1 <- suppressMessages(getspec(system.file("testdata", package = 'pavo'), ext = 'ttt'))
expect_is(avantes1, "rspec")

transmit <- suppressMessages(getspec(system.file("testdata", package = 'pavo'), ext = 'Transmission'))
expect_is(transmit, "rspec")

irr <- suppressMessages(getspec(system.file("testdata", package = 'pavo'), ext = 'IRR'))
expect_is(irr, "rspec")

jazspec <- suppressMessages(getspec(system.file("testdata", package = 'pavo'), ext = 'jaz'))
expect_is(jazspec, "rspec")

jazirrad <- suppressMessages(getspec(system.file("testdata", package = 'pavo'), ext = 'JazIrrad'))
expect_is(jazirrad, "rspec")


proc <- suppressMessages(getspec(system.file("testdata", package = 'pavo'), ext = 'ProcSpec'))
expect_is(proc, "rspec")

## Error handling
# should fail completely
expect_error(getspec(system.file("testdata", package = 'pavo'), ext = 'TRM', sep = ''))
expect_error(getspec(system.file("testdata", package = 'pavo'), ext = 'TRM', sep = ''))

# should partly succeed (1/2)
expect_warning(getspec(system.file("testdata", package = 'pavo'), ext = 'txt'), 'Could not import')
oceanview <- suppressWarnings(getspec(system.file("testdata", package = 'pavo'), ext = 'txt'))
oceanview <- suppressWarnings(getspec(system.file("testdata", package = 'pavo'), ext = 'txt'))
expect_is(oceanview, "rspec")
})

})

0 comments on commit 0576313

Please sign in to comment.