File: test_Data.R

package info (click to toggle)
r-cran-rsdmx 1%3A0.6%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,000 kB
  • sloc: makefile: 2
file content (61 lines) | stat: -rw-r--r-- 2,527 bytes parent folder | download | duplicates (2)
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
# test_Data.R
# Author: Emmanuel Blondel <emmanuel.blondel1@gmail.com>
#
# Description: Unit tests for SDMX Data methods
#=======================
require(rsdmx, quietly = TRUE)
require(testthat)
context("SDMXData")

test_that("DSD is properly associated to an SDMXData object",{
  testthat::skip_on_travis()
  testthat::skip_on_cran()
  data <- readSDMX(providerId = "UIS", resource = "data",
                        flowRef = "EDULIT_DS", key = list("OFST_1_CP", NULL),
                        start = "2000", end = "2015")
  dsd <- readSDMX(providerId = "UIS", resource = "datastructure",
                       resourceId = "EDULIT_DS")
  
  expect_equal(slot(data,"dsdRef"), "EDULIT_DS")
  expect_true(is.null(slot(data,"dsd")))
  
  data <- setDSD(data, dsd)
  expect_false(is.null(slot(data,"dsd")))
  expect_is(slot(data,"dsd"), "SDMXDataStructureDefinition")
  
})

test_that("DSD is properly fetched by readSDMX and associated to the dataset",{
  testthat::skip_on_travis()
  testthat::skip_on_cran()
  data <- readSDMX(providerId = "UIS", resource = "data",
                        flowRef = "EDULIT_DS", key = list("OFST_1_CP", NULL),
                        start = "2000", end = "2015",
                        dsd = TRUE)
  expect_false(is.null(slot(data,"dsd")))
  expect_is(slot(data,"dsd"), "SDMXDataStructureDefinition")
})

#20170615 deactivate test (nb of requests limited in KNOEMA makes this test fail)
#test_that("DSD is properly fetched by readSDMX when there is no dsdRef (using flowRef)",{ 
  #data <- readSDMX(providerId = "KNOEMA", resource = "data",
  #                 flowRef = "SADG2015", dsd = TRUE)
  #expect_false(is.null(slot(data,"dsd")))
  #expect_is(slot(data,"dsd"), "SDMXDataStructureDefinition")
#})

test_that("Dataset is correctly enriched with labels using the DSD",{
  testthat::skip_on_travis()
  testthat::skip_on_cran()
  sdmx.data <- readSDMX(providerId = "UIS", resource = "data",
                        flowRef = "CAI_DS", dsd = TRUE)
  data <- as.data.frame(sdmx.data)
  data.enriched <- as.data.frame(sdmx.data, labels = TRUE)
  expect_true(ncol(data.enriched) > ncol(data))
  expect_true(all(data["CAI_IND"] == data.enriched["CAI_IND"]))
  expect_true(all(data["LOCATION"] == data.enriched["LOCATION"]))
  expect_true(all(data["TIME_FORMAT"] == data.enriched["TIME_FORMAT"]))
  expect_true(all(data["obsTime"] == data.enriched["obsTime"]))
  expect_true(all(data["obsValue"] == data.enriched["obsValue"]))

})