File: test_Main.R

package info (click to toggle)
r-cran-rsdmx 0.5.7%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 940 kB
  • sloc: makefile: 2
file content (98 lines) | stat: -rw-r--r-- 3,081 bytes parent folder | download
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
# test_Main.R
# Author: Emmanuel Blondel <emmanuel.blondel1@gmail.com>
#
# Description: Unit tests for SDMX Main methods
#=======================
require(rsdmx, quietly = TRUE)
require(testthat)
context("SDMX")

#SDMX datasets
#------------

file <- system.file("extdata", "SDMXGenericDataExample_2.0.xml", package = "rsdmx")
sdmxObj <- readSDMX(file, isURL = FALSE)

test_that("readSDMX - 2.0",{
	expect_is(sdmxObj, "SDMXGenericData")
})

#tests for 2.1
file2 <- system.file("extdata", "SDMXGenericDataExample_2.1.xml", package = "rsdmx")
sdmxObj2 <- readSDMX(file2, isURL = FALSE)

test_that("readSDMX - 2.1",{
  expect_is(sdmxObj2, "SDMXGenericData")
})

#SDMXConcepts
#-----------
test_that("readSDMX - SDMXConcepts - 2.0",{
  file <- system.file("extdata", "SDMXConcepts_Example_2.0.xml",
                      package = "rsdmx")
  sdmxObj <- readSDMX(file, isURL = FALSE)
  expect_is(sdmxObj, "SDMXConcepts")
})

test_that("readSDMX - SDMXConcepts (conceptScheme) - 2.0",{
  file <- system.file("extdata", "SDMXConceptSchemes_Example_2.0.xml",
                       package = "rsdmx")
  sdmxObj <- readSDMX(file, isURL = FALSE)
  expect_is(sdmxObj, "SDMXConcepts")
})

test_that("readSDMX - SDMXConcepts (conceptScheme) - 2.1",{
  file <- system.file("extdata", "SDMXConceptSchemes_Example_2.1.xml",
                      package = "rsdmx")
  sdmxObj <- readSDMX(file, isURL = FALSE)
  expect_is(sdmxObj, "SDMXConcepts")
})

#SDMXCodelists
#-------------
test_that("readSDMX - SDMXCodelists - 2.0",{
  file <- system.file("extdata", "SDMXCodelists_Example_2.0.xml",
                      package = "rsdmx")
  sdmxObj <- readSDMX(file, isURL = FALSE)
  expect_is(sdmxObj, "SDMXCodelists")
})

test_that("readSDMX - SDMXCodelists - 2.0",{
  file <- system.file("extdata", "SDMXCodelists_Example_2.1.xml",
                      package = "rsdmx")
  sdmxObj <- readSDMX(file, isURL = FALSE)
  expect_is(sdmxObj, "SDMXCodelists")
})

#SDMXDataStructureDefinition (DSD)
#--------------------------------
test_that("readSDMX - SDMXDataStructureDefinition (DSD) - 2.0",{

  file <- system.file("extdata", "SDMXDataStructureDefinition_Example_2.0.xml",
                      package = "rsdmx")
  dsd <- readSDMX(file, isURL = FALSE)
  expect_is(dsd, "SDMXDataStructureDefinition")
  expect_is(dsd@concepts, "SDMXConcepts")
  expect_is(dsd@codelists, "SDMXCodelists")
  expect_is(dsd@datastructures, "SDMXDataStructures")
})

test_that("readSDMX - Catch 400 bad request", {
  testthat::skip_on_travis()
  testthat::skip_on_cran()
  expect_error(
    sdmx <- readSDMX(providerId = "KNOEMA", resource = "data", flowRef = "bad_ref")
  )
})

test_that("readSDMX - Catch good request that fails for other reason (bad proxy)", {
  testthat::skip_on_travis()
  testthat::skip_on_cran()
  old_opts <- options()
  options(RCurlOptions = list("proxy" = "bad_proxy"))
  
  expect_error(
    sdmx <- readSDMX(providerId = "KNOEMA", resource = "data", flowRef = "SADG2015")
  )
  options(old_opts)
})