forked from animint/animint2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-compiler-chunk-vars.R
127 lines (119 loc) · 4.85 KB
/
test-compiler-chunk-vars.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
acontext("chunk vars")
test_that("produce as many chunk files as specified", {
viz <- list(iris=a_plot()+
a_geom_point(a_aes(Petal.Width, Sepal.Length),
showSelected="Species",
data=iris, chunk_vars="Species",
validate_params = FALSE))
tdir <- tempfile()
dir.create(tdir)
tsv.files <- Sys.glob(file.path(tdir, "*.tsv"))
expect_equal(length(tsv.files), 0)
animint2dir(viz, tdir, open.browser=FALSE)
tsv.files <- Sys.glob(file.path(tdir, "*.tsv"))
expect_equal(length(tsv.files), 3)
viz <- list(iris=a_plot()+
a_geom_point(a_aes(Petal.Width, Sepal.Length),
showSelected="Species",
data=iris, chunk_vars=character(), validate_params = FALSE))
tdir <- tempfile()
dir.create(tdir)
tsv.files <- Sys.glob(file.path(tdir, "*.tsv"))
expect_equal(length(tsv.files), 0)
animint2dir(viz, tdir, open.browser=FALSE)
tsv.files <- Sys.glob(file.path(tdir, "*.tsv"))
expect_equal(length(tsv.files), 1)
})
test_that("produce informative errors for bad chunk_vars", {
viz <- list(iris=a_plot()+
a_geom_point(a_aes(Petal.Width, Sepal.Length),
showSelected="Species",
data=iris, chunk_vars="species", validate_params = FALSE))
expect_error({
animint2dir(viz, open.browser=FALSE)
}, "invalid chunk_vars species; possible showSelected variables: Species")
viz <- list(iris=a_plot()+
a_geom_point(a_aes(Petal.Width, Sepal.Length),
showSelected="Species",
data=iris, chunk_vars=NA, validate_params = FALSE))
expect_error({
animint2dir(viz, open.browser=FALSE)
}, paste("chunk_vars must be a character vector;",
"use chunk_vars=character() to specify 1 chunk"), fixed=TRUE)
})
data(breakpoints, package = "animint2")
only.error <- subset(breakpoints$error,type=="E")
only.segments <- subset(only.error,bases.per.probe==bases.per.probe[1])
signal.colors <- c(estimate="#0adb0a",
latent="#0098ef")
breakpointError <-
list(signal=a_plot()+
a_geom_point(a_aes(position, signal),
showSelected="bases.per.probe",
data=breakpoints$signals)+
a_geom_line(a_aes(position, signal), colour=signal.colors[["latent"]],
data=breakpoints$imprecision)+
a_geom_segment(a_aes(first.base, mean, xend=last.base, yend=mean),
showSelected=c("segments", "bases.per.probe"),
colour=signal.colors[["estimate"]],
data=breakpoints$segments)+
a_geom_vline(a_aes(xintercept=base),
showSelected=c("segments", "bases.per.probe"),
colour=signal.colors[["estimate"]],
linetype="dashed",
data=breakpoints$breaks),
error=a_plot()+
a_geom_vline(a_aes(xintercept=segments),
clickSelects="segments",
data=only.segments, lwd=17, alpha=1/2)+
a_geom_line(a_aes(segments, error, group=bases.per.probe),
clickSelects="bases.per.probe",
data=only.error, lwd=4))
bytes.used <- function(file.vec, apparent.size = FALSE){
## Note: the apparent.size flag gives sizes that are consistent
## with file.info, but those sizes actually under-estimate the
## actual amount of space used on disk.
file.str <- paste(file.vec, collapse=" ")
if(apparent.size){
cmd <- paste("ls -l", file.str, "| awk '{print $5}'")
} else{
cmd <- paste("du -k", file.str, "| awk '{print $1 * 1024}'")
}
tryCatch({
du.lines <- system(cmd, intern=TRUE)
as.integer(sub("\t.*", "", du.lines))
}, error=function(e){
rep(NA_integer_, length(file.vec))
})
}
test.paths <-
c(tempfile=tempfile(),
HOME=file.path(Sys.getenv("HOME"), "ANIMINT_TEST_FOO"),
getwd=file.path(getwd(),"ANIMINT_TEST_FOO"))
for(f in test.paths){
unlink(f)
cat("foo", file=f)
}
du.bytes <- bytes.used(test.paths)
apparent.bytes <- bytes.used(test.paths, apparent.size = TRUE)
byte.df <- data.frame(du.bytes, apparent.bytes,
file.size=file.size(test.paths),
test.paths)
test_that("default chunks are at least 4KB", {
tdir <- tempfile()
dir.create(tdir)
tsv.files <- Sys.glob(file.path(tdir, "*.tsv"))
expect_equal(length(tsv.files), 0)
expect_no_warning({
animint2dir(breakpointError, tdir, open.browser=FALSE)
})
tsv.files <- Sys.glob(file.path(tdir, ".+chunk[0-9]+.tsv")) # exclude common tsv
a_geom <- sub("_.*", "", basename(tsv.files))
files.by.a_geom <- split(tsv.files, a_geom)
for(files in files.by.a_geom){
if(length(files) > 1){
info <- file.info(files)
expect_true(all(4096 < info$size))
}
}
})