/usr/lib/R/site-library/Biobase/UnitTests/VersionedClass_test.R is in r-bioc-biobase 2.14.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 128 129 130 131 132 133 | nonvirtualClasses <- NULL
instanceDir <-
system.file("UnitTests", "VersionedClass_data", package="Biobase")
.setUp <- function() {
nms <- ls(getNamespace("Biobase"),all=TRUE)
classes <- gsub(".__C__", "", nms[grep(".__C__", nms)])
classes <- classes[!classes %in% "phenoData"]
isVirtual <- sapply(classes, function(nm) getClass(nm)@virtual)
nonvirtualClasses <<- classes[!isVirtual]
}
testNewVersioned <- function() {
new("Versioned")
new("VersionedBiobase")
## Biobase:::.unversionedObj
v <- new("Versioned", versions=list(x="1.0.0"))
checkTrue(classVersion(v)["x"]=="1.0.0")
## use class definition defined in RUnit.R
## a <- new("A")
## checkTrue(all(classVersion(a) == classVersion(new("VersionedBiobase", versions=list(A="1.0.1")))))
## checkTrue(all(a@x==10:1))
## a <- new("A", x=1:10)
## checkTrue(all(classVersion(a) == classVersion(new("VersionedBiobase", versions=list(A="1.0.1")))))
## checkTrue(all(a@x==1:10))
## a <- new("A", x=1:10, versions=list(x="1.0.1"))
## checkTrue(all(a@x==1:10))
## checkTrue(all(classVersion(a) == classVersion(new("VersionedBiobase", versions=list(A="1.0.1",x="1.0.1")))))
}
testIsVersioned <- function() {
checkTrue(isVersioned(new("VersionedBiobase")))
checkTrue(isVersioned("VersionedBiobase"))
checkTrue(!isVersioned(1:10))
}
testClassVersion <- function() {
classVersion(new("Versioned"))
classVersion(new("VersionedBiobase"))
checkTrue(is(classVersion(new("VersionedBiobase")),"Versions"))
checkTrue(all(classVersion("VersionedBiobase") == classVersion(new("VersionedBiobase"))))
}
testClassVersionReplace <- function() {
ref <- obj <- new("VersionedBiobase")
classVersion(obj)["x"] <- "1.0.0"
checkTrue(all(classVersion(obj)[names(classVersion(ref))] == classVersion(ref)))
checkTrue(classVersion(obj)["x"] == "1.0.0")
y <- new("Versions", y="1.0.1")
classVersion(obj)[names(y)] <- y
checkTrue(all(classVersion(obj)[names(classVersion(ref))] == classVersion(ref)))
checkTrue(classVersion(obj)["x"] == "1.0.0")
checkTrue(classVersion(obj)["y"] == "1.0.1")
checkTrue(classVersion(obj)["y"] != "1.0.0")
obj <- ref
classVersion(obj) <- y
checkTrue(classVersion(obj)["y"] == "1.0.1")
}
testClassVersionSubset <- function() {
obj <- new("Versions", x="1.0.0")
checkTrue(obj[1]=="1.0.0")
checkTrue(obj["x"]=="1.0.0")
checkException(obj["y"], silent=TRUE)
}
testClassVersionCompare <- function() {
obj <- new("Versions", x="1.0.0", y="2.0.1")
checkTrue(all(obj == c(x="1.0.0", y="2.0.1")))
checkTrue(all(obj == c(y="2.0.1", x="1.0.0")),
msg="versions in different order")
checkTrue(!any(obj == c(y="1.0.0", x="2.0.1")),
msg="incorrectly named elements")
checkTrue(!all(obj == c(y="1.0.0", x="1.0.0")),
msg="one element incorrect elements")
checkException(all(obj == c(x="1.0.0", z="2.0.1")),
msg="different version elements",
silent=TRUE)
checkException(obj == c(x="1.0.0"),
msg="different version lengths",
silent=TRUE)
## as above, but comparing version objects
checkTrue(all(obj == new("Versions", x="1.0.0", y="2.0.1")))
checkTrue(all(obj == new("Versions", y="2.0.1", x="1.0.0")))
checkTrue(!any(obj == new("Versions", x="2.0.1", y="1.0.0")))
checkTrue(!all(obj == new("Versions", x="1.0.0", y="1.0.0")))
checkException(all(obj == new("Versions", x="1.0.0", z="2.0.1")),
msg="different version elements",
silent=TRUE)
checkException(obj == new("Versions", x="1.0.0"),
msg="different version lengths",
silent=TRUE)
}
testIsCurrent <- function() {
checkTrue(is.na(isCurrent(1:10)))
checkTrue(all(isCurrent(new("VersionedBiobase"))))
}
testDevelInstanceArchived <- function() {
## archived devel instance?
instances <- sub(".Rda", "",
list.files(path=file.path(instanceDir, "devel"),
pattern=".*.Rda"))
checkTrue(all(nonvirtualClasses %in% instances),
msg=paste(nonvirtualClasses[!nonvirtualClasses %in% instances],
collapse=" "))
}
testDevelInstanceIsCurrent <- function() {
## overall class is current
instanceEnv <- new.env(parent=emptyenv())
lapply(nonvirtualClasses, function(cls) {
cls <- paste(cls, ".Rda", sep="")
load(file.path(instanceDir, "devel", cls), instanceEnv)
})
instances <-
sub(".Rda", "",
list.files(path=file.path(instanceDir, "devel"), pattern=".*.Rda"))
instances <- instances[!instances %in% "Versioned"]
current <- sapply(instances, function(obj) {
vers <- isCurrent(get(obj, env=instanceEnv))[c("S4", obj)]
all(vers[!is.na(vers)])
})
currentv <- current[!is.na(current)]
checkTrue(all(currentv), msg=paste(names(currentv)[!currentv], collapse=" "))
}
|