File: test_drs_tree_json.py

package info (click to toggle)
drslib 0.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,596 kB
  • sloc: python: 6,119; xml: 988; makefile: 128; sh: 121
file content (45 lines) | stat: -rw-r--r-- 1,513 bytes parent folder | download | duplicates (4)
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
# BSD Licence
# Copyright (c) 2011, Science & Technology Facilities Council (STFC)
# All rights reserved.
#
# See the LICENSE file in the source distribution of this software for
# the full license text.

from drslib.cordex import CordexFileSystem, CordexDRS
from drslib.specs import SpecsFileSystem, SpecsDRS
from .drs_tree_shared import TestEg, TestListing, test_dir
from drslib.drs_tree import DRSTree
import json

import os.path as op

class TestJson(TestEg):
    __test__ = True

    def test_1(self):
        drs_fs = CordexFileSystem(self.tmpdir)
        drs_tree = DRSTree(drs_fs)
        json_obj = json.load(open(op.join(test_dir, 'cordex_1.json')))

        drs_tree.discover_incoming_fromjson(json_obj, activity='cordex')

        assert len(drs_tree.pub_trees) == 3

    def test_2(self):
        drs_fs = SpecsFileSystem(self.tmpdir)
        drs_tree = DRSTree(drs_fs)
        with open(op.join(test_dir, 'specs_cedacc.json')) as fh:
            json_obj = [json.loads(line) for line in fh]

        drs_tree.discover_incoming_fromjson(json_obj, activity='specs')
        
        # This id will not be present if realm is not correctly split on space
        drs_id = 'specs.output.IPSL.IPSL-CM5A-LR.decadal.S20130101.mon.seaIce.OImon.sic.r3i1p1'
        assert drs_id in drs_tree.pub_trees

        p = list(drs_tree.pub_trees.values())[0]
        p_vars = set(drs.variable for (drs_str, drs) in p._todo)

        # All DRS objects should be for the same variable
        assert len(p_vars) == 1