aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2016-02-04 18:06:15 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2016-02-04 18:06:15 +0100
commitd14923ae1ac023c8f8f5ae8b5c0884f4247f764b (patch)
tree98cbafd22f11944e26fc39126096d59c64adc2d0 /pkg
parent98a706373107188496a1df295697e739e51d6b06 (diff)
Test reading .out files and close connections
Diffstat (limited to 'pkg')
-rw-r--r--pkg/R/TOXSWA_cwa.R5
-rw-r--r--pkg/man/PEC_sw_drift.Rd2
-rw-r--r--pkg/man/PEC_sw_sed.Rd2
-rw-r--r--pkg/tests/testthat/EXSW2_R1_stream_printed.txt10
-rw-r--r--pkg/tests/testthat/test_TOXSWA_cwa.R13
5 files changed, 27 insertions, 5 deletions
diff --git a/pkg/R/TOXSWA_cwa.R b/pkg/R/TOXSWA_cwa.R
index a693dc1..d2720a9 100644
--- a/pkg/R/TOXSWA_cwa.R
+++ b/pkg/R/TOXSWA_cwa.R
@@ -187,6 +187,7 @@ TOXSWA_cwa <- R6Class("TOXSWA_cwa",
"integer", rep("numeric", 5)),
col.names = c("datetime", "t", "segment",
"xcd", "cwa_tot", "cwa", "Xss", "Xmp")))
+
if (is.null(zipfile)) close(file_connection) # only needed for files
if (!inherits(cwa_all_segments, "try-error")) {
@@ -219,9 +220,7 @@ TOXSWA_cwa <- R6Class("TOXSWA_cwa",
# out file from FOCUS TOXSWA 4 (TOXSWA 4.4.2 or similar)
outfile <- try(readLines(file_connection))
- if (is.null(zipfile)) {
- close(file_connection) # only needed for files
- }
+ close(file_connection) # only needed for files
if (inherits(outfile, "try-error")) {
stop("Could not read ", filename)
diff --git a/pkg/man/PEC_sw_drift.Rd b/pkg/man/PEC_sw_drift.Rd
index 6a1b935..c486831 100644
--- a/pkg/man/PEC_sw_drift.Rd
+++ b/pkg/man/PEC_sw_drift.Rd
@@ -6,7 +6,7 @@
\usage{
PEC_sw_drift(rate, applications = 1, water_depth = 30, drift_data = "JKI",
crop = "Ackerbau", distances = c(1, 5, 10, 20), rate_units = "g/ha",
- PEC_units = "<U+00B5>g/L")
+ PEC_units = "µg/L")
}
\arguments{
\item{rate}{Application rate in units specified below}
diff --git a/pkg/man/PEC_sw_sed.Rd b/pkg/man/PEC_sw_sed.Rd
index d0e2ec6..3140eb0 100644
--- a/pkg/man/PEC_sw_sed.Rd
+++ b/pkg/man/PEC_sw_sed.Rd
@@ -7,7 +7,7 @@ water concentrations}
\usage{
PEC_sw_sed(PEC_sw, percentage = 100, method = "percentage",
sediment_depth = 5, water_depth = 30, sediment_density = 1.3,
- PEC_sed_units = c("<U+00B5>g/kg", "mg/kg"))
+ PEC_sed_units = c("µg/kg", "mg/kg"))
}
\arguments{
\item{PEC_sw}{Numeric vector or matrix of surface water concentrations in µg/L for
diff --git a/pkg/tests/testthat/EXSW2_R1_stream_printed.txt b/pkg/tests/testthat/EXSW2_R1_stream_printed.txt
new file mode 100644
index 0000000..f4e0a10
--- /dev/null
+++ b/pkg/tests/testthat/EXSW2_R1_stream_printed.txt
@@ -0,0 +1,10 @@
+<TOXSWA_cwa> data from file 3.out segment 20
+ datetime t t_firstjan t_rel_to_max cwa_mug_per_L
+1 1978-10-01 00:30:00 0.021 273.0208 -55.292 0
+2 1978-10-01 01:30:00 0.063 273.0625 -55.250 0
+3 1978-10-01 02:30:00 0.104 273.1042 -55.209 0
+4 1978-10-01 03:30:00 0.146 273.1458 -55.167 0
+5 1978-10-01 04:30:00 0.188 273.1875 -55.125 0
+6 1978-10-01 05:30:00 0.229 273.2292 -55.084 0
+Moving window analysis
+NULL
diff --git a/pkg/tests/testthat/test_TOXSWA_cwa.R b/pkg/tests/testthat/test_TOXSWA_cwa.R
index 407a7a1..7c9a73c 100644
--- a/pkg/tests/testthat/test_TOXSWA_cwa.R
+++ b/pkg/tests/testthat/test_TOXSWA_cwa.R
@@ -12,6 +12,13 @@ H_sw_R1_stream <- read.TOXSWA_cwa("00003s_pa.cwa",
basedir = basedir_test,
zipfile = zipfile_test)
+basedir_test_2 = "SwashProjects/Project_1/TOXSWA"
+
+EXSW2_R1_stream <- read.TOXSWA_cwa("3.out",
+ basedir = basedir_test_2,
+ zipfile = zipfile_test)
+
+
test_that("TOXSWA cwa file is correctly read and printed", {
@@ -29,6 +36,12 @@ test_that("TOXSWA cwa file is correctly read and printed", {
# The basedir is not printed, therefore tested separately
expect_equal(H_sw_D4_pond$basedir, basedir_test)
+
+ EXSW2_R1_stream_printed <- capture.output(print(EXSW2_R1_stream))
+ expect_equal(EXSW2_R1_stream_printed, readLines("EXSW2_R1_stream_printed.txt"))
+
+ # The basedir is not printed, therefore tested separately
+ expect_equal(H_sw_D4_pond$basedir, basedir_test)
})
test_that("Getting events and moving window analysis works", {

Contact - Imprint