Exemplo n.º 1
0
        # CREX
        with io.open(os.getenv("DBA_TESTDATA") + "/crex/test-synop0.crex", "rb") as fp:
            self.db.reset()
            self.assertEqual(self.db.load(fp, "CREX"), 1)

        # BUFR loaded as CREX yields no results
        with io.open(os.getenv("DBA_TESTDATA") + "/bufr/vad.bufr", "rb") as fp:
            self.db.reset()
            self.assertEqual(self.db.load(fp, "CREX"), 0)



    def testQueryVolnd(self):
        from testlib import fill_volnd
        self.db.reset()
        fill_volnd(self.db)
        query = dballe.Record()
        query["var"] = "B10004"
        query["datetime"] = datetime.datetime(2007, 1, 1, 0, 0, 0)
        reports = []
        for cur in self.db.query_data(query):
            reports.append(cur["rep_memo"])
        s = "synop"
        t = "temp"
        self.assertEqual(reports, [s, t, s, t, s, t, s, s, t, s, t])

if __name__ == "__main__":
    from testlib import main
    main("test_db")
Exemplo n.º 2
0
        # input endpoints, and does not support the paging interface.
        service = client.connect(**self.opts.kwargs)
        count = len(service.inputs.list())
        self.check_iterable(service.inputs, count)

    def test_jobs(self):
        # The Jobs REST API endpoint does not support the paging interface.
        service = client.connect(**self.opts.kwargs)
        count = len(service.jobs.list())
        self.check_iterable(service.jobs, count)

    def test_loggers(self):
        service = client.connect(**self.opts.kwargs)
        self.check_collection(service.loggers)

    def test_messages(self):
        service = client.connect(**self.opts.kwargs)
        self.check_collection(service.messages)

    def test_roles(self):
        service = client.connect(**self.opts.kwargs)
        self.check_collection(service.roles)

    def test_users(self):
        service = client.connect(**self.opts.kwargs)
        self.check_collection(service.users)

if __name__ == "__main__":
    testlib.main()

Exemplo n.º 3
0
        # query.settimerange(dballe.TimeRange(0,0,0))
        vars = volnd.read(
            self.db.query_data(query),
            (volnd.AnaIndex(), volnd.NetworkIndex(), volnd.LevelIndex(), volnd.TimeRangeIndex()),
        )
        # print "ana:", vars["B10004"].dims[0]
        # print "net:", vars["B10004"].dims[1]
        # print vars["B10004"]
        # rpy.r.print_(rconvert.vnddata_to_r(vars['B10004']))
        # rpy.r.assign('pippo', rconvert.vnddata_to_r(vars['B10004']))
        # rpy.r.save('pippo', file='/tmp/pippo')

        rconvert.volnd_save_to_r(vars, "/tmp/pippo")

    def test_bug1(self):
        # Second test case reported by Paolo
        query = dballe.Record()
        # query.setd("latmin", 10.)
        # query.setd("latmax", 60.)
        # query.setd("lonmin", -10.)
        # query.setd("lonmax", 40.)
        query["var"] = "B13011"
        vars = volnd.read(self.db.query_data(query), (volnd.AnaIndex(), volnd.DateTimeIndex()), checkConflicts=False)
        rconvert.volnd_save_to_r(vars, "/tmp/pippo")


if __name__ == "__main__":
    from testlib import main

    main("test_rconvert")
Exemplo n.º 4
0
#        self.assertEqual(info.var, "B01001")

    def testLookup(self):
        table = wreport.Vartable.get_bufr(master_table_version_number=24)
        info = table["B01001"]
        self.assertEqual(info.type, "integer")
        self.assertEqual(info.len, 3)
        self.assertEqual(info.unit, "NUMERIC")

    def testLookupMissing(self):
        table = wreport.Vartable.get_bufr(master_table_version_number=24)
        with self.assertRaises(KeyError):
            table["B63254"]

#    def testIterate(self):
#        table = wreport.Vartable("dballe")
#        selected = None
#        count = 0
#        for entry in table:
#            if entry.var == "B12101":
#                selected = entry
#            count += 1
#        self.assertGreater(count, 100)
#        self.assertEqual(count, len(table))
#        self.assertIsNotNone(selected)


if __name__ == "__main__":
    from testlib import main
    main("vartable")
Exemplo n.º 5
0
        self.assertEqual(type(var.enq()), int)
        self.assertEqual(var.enq(), 1)
        var = wreport.Var(self.table["B05001"], 1.12345)
        self.assertEqual(type(var.enq()), float)
        self.assertEqual(var.enq(), 1.12345)
        var = wreport.Var(self.table["B01019"], "ciao")
        self.assertIsInstance(var.enq(), string_types)
        self.assertEqual(var.enq(), "ciao")
    def testGet(self):
        var = wreport.Var(self.table["B01001"])
        self.assertIsNone(var.get())
        self.assertIs(var.get("foo"), "foo")
        var = wreport.Var(self.table["B01001"], 1)
        self.assertIs(var.get(), 1)
        var = wreport.Var(self.table["B05001"], 1.12345)
        self.assertEqual(var.get(), 1.12345)
        var = wreport.Var(self.table["B01019"], "ciao")
        self.assertEqual(var.get(), "ciao")
    def testEq(self):
        var = wreport.Var(self.table["B01001"], 1)
        self.assertEqual(var, var)
        self.assertEqual(var, wreport.Var(self.table["B01001"], 1))
        self.assertNotEqual(var, wreport.Var(self.table["B01001"], 2))
        self.assertNotEqual(var, wreport.Var(self.table["B01002"], 1))
        self.assertIsNot(var, None)
        self.assertIsNot(wreport.Var(self.table["B01001"]), None)

if __name__ == "__main__":
    from testlib import main
    main("var")
Exemplo n.º 6
0
#!/usr/bin/python
# coding: utf-8
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import dballe
import unittest

class Describe(unittest.TestCase):
    def testLevel(self):
        self.assertIn("surface", dballe.describe_level(1))

    def testTrange(self):
        self.assertIn("Accumulation", dballe.describe_trange(1))


if __name__ == "__main__":
    from testlib import main
    main("test_core")
Exemplo n.º 7
0
        query = dballe.Record()
        query["rep_memo"] = "synop"
        vars = read(self.db.query_station_data(query), indexes, checkConflicts=True)
        self.assertEqual(sorted(vars.keys()), ["B01001", "B01002", "B01019"])

    def testExportSyncAna(self):
        # Export some data
        indexes = (AnaIndex(), DateTimeIndex())
        query = dballe.Record()
        query["rep_memo"] = 'synop'
        query["level"] = (1,)
        query["trange"] = (4, -21600, 0)
        vars = read(self.db.query_data(query), indexes, checkConflicts=True)
        self.assertEqual(sorted(vars.keys()), ["B13011"])

        # Freeze all the indexes
        for i in range(len(indexes)):
            indexes[i].freeze()

        # Export the pseudoana data in sync with the data
        query.clear()
        query["rep_memo"] = "synop"
        anas = read(self.db.query_station_data(query), (indexes[0],), checkConflicts=True)

        self.assertEqual(sorted(anas.keys()), ["B01001", "B01002", "B01019"])
        self.assertEqual(anas["B01001"].dims[0], vars["B13011"].dims[0])

if __name__ == "__main__":
    from testlib import main
    main("test_volnd")
Exemplo n.º 8
0
from __future__ import print_function
from __future__ import unicode_literals
import wreport
import unittest

class Varinfo(unittest.TestCase):
    def testEmptyVarinfo(self):
        self.assertRaises(NotImplementedError, wreport.Varinfo)

    def testData(self):
        table = wreport.Vartable.get_bufr(master_table_version_number=24)
        info = table["B01001"]
        self.assertEqual(info.code, "B01001")
        self.assertEqual(info.desc, "WMO block number")
        self.assertEqual(info.unit, "NUMERIC")
        self.assertEqual(info.scale, 0)
        self.assertEqual(info.len, 3)
        self.assertEqual(info.bit_ref, 0)
        self.assertEqual(info.bit_len, 7)
        self.assertEqual(info.type, "integer")

    def testStringification(self):
        table = wreport.Vartable.get_bufr(master_table_version_number=24)
        info = table["B01001"]
        self.assertTrue(str(info).startswith("B01001"))
        self.assertTrue(repr(info).startswith("Varinfo('B01001"))

if __name__ == "__main__":
    from testlib import main
    main("varinfo")
Exemplo n.º 9
0
        ids = self.db.insert_data(data, False, True)
        attrs = dballe.Record()
        attrs["B33209"] = 98
        self.db.attr_insert_data(ids["B12101"], attrs)

        data.update(
            rep_memo="synop",
            lat=0.0, lon=0.0,
            ident="#000000",
            level=(103, 2000),
            trange=(254, 0, 0),
            datetime=datetime.datetime(1005, 1, 1, 1, 1, 1),
            B12101=271.96)
        ids = self.db.insert_data(data, False, True)
        attrs = dballe.Record()
        attrs["B33209"] = 100
        self.db.attr_insert_data(ids["B12101"], attrs)

        query = dballe.Record()
        out = io.StringIO()
        dbacsv.export(self.db, query, out)

        lines = out.getvalue().splitlines()
        self.assertEqual(lines[2], "1005-01-01 01:01:00,270.96,98")
        self.assertEqual(lines[3], "1005-01-01 01:01:01,271.96,100")


if __name__ == "__main__":
    from testlib import main
    main("test_csv")