File: test_DataStructures.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 (55 lines) | stat: -rw-r--r-- 2,208 bytes parent folder | download | duplicates (5)
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
# test_DataStructures.R
# Author: Emmanuel Blondel <emmanuel.blondel1@gmail.com>
#
# Description: Unit tests for SDMX DataStructures methods
#=======================
require(rsdmx, quietly = TRUE)
require(testthat)
context("SDMXDataStructures")

test_that("DataStructures / KeyFamilies - 2.0",{
  file <- system.file("extdata", "SDMXDataStructures_Example_2.0.xml",
                      package = "rsdmx")
  xmlObj <- xmlParse(file)
  ns <- namespaces.SDMX(xmlObj)
  ds <- SDMXDataStructures(xmlObj, ns)
  expect_is(ds, "SDMXDataStructures")
  expect_equal(length(ds@datastructures), 1L)
  
  ds.df <- as.data.frame(ds)
  expect_is(ds.df, "data.frame")
  expect_equal(nrow(ds.df), 1L)
  expect_equal(colnames(ds.df), c("id","agencyID","Name.en", "version",
                               "uri", "urn", "isExternalReference", "isFinal",
                               "validFrom", "validTo"))
  
  expect_equal(ds.df[1,"id"], "TRADE_DATASTRUCTURE")
  expect_equal(ds.df[1, "agencyID"], "FAO")
  expect_equal(ds.df[1, "Name.en"], "TRADE_DATASTRUCTURE")
  expect_equal(ds.df[1, "version"], "0.1")
  expect_equal(ds.df[1, "urn"], "urn:sdmx:org.sdmx.infomodel.DataStructure=FAO:TRADE_DATASTRUCTURE[0.1]")

})

test_that("DataStructures / KeyFamilies - 2.1",{
  file <- system.file("extdata", "SDMXDataStructures_Example_2.1.xml",
                      package = "rsdmx")
  xmlObj <- xmlParse(file)
  ns <- namespaces.SDMX(xmlObj)
  ds <- SDMXDataStructures(xmlObj, ns)
  expect_is(ds, "SDMXDataStructures")
  expect_equal(length(ds@datastructures), 1L)
  
  ds.df <- as.data.frame(ds)
  expect_is(ds.df, "data.frame")
  expect_equal(nrow(ds.df), 1L)
  expect_equal(colnames(ds.df), c("id","agencyID","Name.en", "version",
                                "uri", "urn", "isExternalReference", "isFinal",
                                "validFrom", "validTo"))
  expect_equal(ds.df[1,"id"], "ECB_EXR1")
  expect_equal(ds.df[1, "agencyID"], "ECB")
  expect_equal(ds.df[1, "Name.en"], "Exchange Rates")
  expect_equal(ds.df[1, "version"], "1.0")
  expect_equal(ds.df[1, "urn"], "urn:sdmx:org.sdmx.infomodel.datastructure.DataStructure=ECB:ECB_EXR1(1.0)")
  
})