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
|
# 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.
import tempfile
import shutil
import sys, os
from glob import glob
from io import StringIO
import datetime
from unittest import TestCase
from . import gen_drs
from drslib.drs_tree import DRSTree
from drslib import config
from drslib.cmip5 import CMIP5FileSystem
test_dir = os.path.dirname(__file__)
class TestEg(TestCase):
__test__ = False
today = int(datetime.date.today().strftime('%Y%m%d'))
def setUp(self):
self.tmpdir = tempfile.mkdtemp(prefix='drslib-')
self.incoming = os.path.join(self.tmpdir, config.DEFAULT_INCOMING)
def tearDown(self):
shutil.rmtree(self.tmpdir)
class TestListing(TestEg):
# Set the following in subclasses
# listing_file
def setUp(self):
super(TestListing, self).setUp()
listing_path = os.path.join(test_dir, self.listing_file)
gen_drs.write_listing(self.tmpdir, listing_path)
self._init_drs_fs()
self.dt = DRSTree(self.drs_fs)
def _init_drs_fs(self):
self.drs_fs = CMIP5FileSystem(self.tmpdir)
def _discover(self, institute, model):
self.dt.discover(self.incoming, activity='cmip5',
product='output1',
institute=institute,
model=model)
def _do_version(self, pt):
assert pt.state == pt.STATE_INITIAL
pt.do_version()
assert pt.state == pt.STATE_VERSIONED
assert list(pt.versions.keys()) == [self.today]
|