-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest-rdf_storage.R
116 lines (92 loc) · 3.71 KB
/
test-rdf_storage.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
testthat::context("RDF Storage")
testthat::test_that("SQLite Backend", {
testthat::skip_if_not(rdf_storage("sqlite", new_db = TRUE,
check_only = TRUE, name = "rdflib.sqlite"))
testthat::expect_silent(r <- rdf(storage="sqlite",
new_db = TRUE,
name="rdflib.sqlite"))
rdf_add(r, "", "dc:name", "bob")
testthat::expect_match(format(r, "nquads"), "bob")
testthat::expect_is(r, "rdf")
rdf_free(r)
unlink("rdflib.sqlite")
})
testthat::test_that("Postgres Backend", {
testthat::skip_on_travis()
testthat::skip_if_not(rdf_storage("postgres",
host="postgres", user="postgres",
password="rdflib", new_db = TRUE,
check_only = TRUE))
testthat::expect_silent(
rdf <- rdf(storage="postgres", host = "postgres",
user="postgres", password="rdflib", new_db = TRUE)
)
rdf_add(rdf, "", "dc:name", "bob")
testthat::expect_match(format(rdf, "nquads"), "bob")
testthat::expect_is(rdf, "rdf")
rdf_free(rdf)
})
## Note: `mysql` is the name default database created by mariadb
testthat::test_that("MySQL Backend", {
testthat::skip_on_travis()
testthat::skip_if_not(rdf_storage("mysql", host = "mariadb",
user="root", password="rdflib",
database = "mysql",
new_db=TRUE, check_only = TRUE ))
testthat::expect_silent(
rdf <- rdf(storage="mysql", host = "mariadb",
user="root", password="rdflib",
database = "mysql",
new_db = TRUE)
)
rdf_add(rdf, "", "dc:name", "bob")
expect_match(format(rdf, "nquads"), "bob")
testthat::expect_is(rdf, "rdf")
rdf_free(rdf)
})
testthat::test_that("Virtuoso Backend", {
testthat::skip("Virtuoso not tested")
testthat::skip_on_travis()
## FIXME Thiss skip check will pass even when database not present
testthat::skip_if_not(rdf_storage("virtuoso",
host="virtuoso",
user="demo",
password="rdflib",
new_db=TRUE,
check_only = TRUE))
## Fails to connect: librdf error - Virtuoso SQLConnect() failed
## [IM002] [iODBC][Driver Manager]Data source name not found and no default driver specified.
## Driver could not be loaded
testthat::expect_silent(
r <- rdf(storage="virtuoso", host = "virtuoso", user="demo",
password="rdflib",new_db = TRUE)
)
rdf_add(r, "", "dc:name", "bob")
expect_match(format(r, "nquads"), "bob")
testthat::expect_is(r, "rdf")
rdf_free(r)
})
testthat::test_that("We warn if we cannot use disk-based storage", {
testthat::skip_if(rdf_has_bdb())
testthat::expect_warning(rdf <- rdf(storage = "BDB"), "BDB driver not found")
## Falls back on memory-based storage, still creates rdf
testthat::expect_is(rdf, "rdf")
rdf_free(rdf)
})
testthat::test_that("We can use BDB storage", {
testthat::skip_if_not(rdf_has_bdb())
# not sure why this is now failing on appveyor
testthat::skip_on_os("windows")
testthat::expect_silent(rdf <- rdf(storage="BDB", new_db = TRUE))
rdf_add(rdf, "", "dc:name", "bob")
expect_match(format(rdf, "nquads"), "bob")
testthat::expect_is(rdf, "rdf")
rdf_free(rdf)
## We can reconnect to disk based storage after freeing
rdf2 <- rdf(storage = "BDB", new_db = FALSE)
expect_match(format(rdf2, "nquads"), "bob")
rdf_free(rdf2)
unlink("rdflib-po2s.db")
unlink("rdflib-so2p.db")
unlink("rdflib-sp2o.db")
})