File: test-rdf_storage.R

package info (click to toggle)
r-cran-rdflib 0.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 572 kB
  • sloc: xml: 66; sh: 13; makefile: 2
file content (117 lines) | stat: -rw-r--r-- 3,418 bytes parent folder | download | duplicates (3)
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
testthat::context("RDF Storage")

testthat::test_that("SQLite Backend", {
  testthat::skip_on_cran()
  
  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_on_cran()
  
  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_cran()
  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_on_travis()
  testthat::skip_on_cran()
  
  testthat::skip_if_not(rdflib:::rdf_has_virtuoso())
  
  testthat::expect_silent(
    r <- rdf(storage = "virtuoso", 
             user = "dba", 
             password = "dba", 
             dsn = "Local Virtuoso", 
             new_db = TRUE)
    )
  rdf_add(r, "", "dc:name", "bob")
  
  testthat::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")
})