Exemplo n.º 1
0
def iemob():
    """Database."""
    res = blah()
    ts = utc(2015, 9, 1, 1, 0)
    sid = ''.join(
        random.choice(string.ascii_uppercase + string.digits)
        for _ in range(7))
    res.iemid = 0 - random.randint(0, 1000)
    res.ob = observation.Observation(sid, 'FAKE', ts)
    res.conn = get_dbconn('iem')
    res.cursor = res.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
    # Create fake station, so we can create fake entry in summary
    # and current tables
    res.cursor.execute(
        """
        INSERT into stations(id, network, iemid, tzname)
        VALUES (%s, 'FAKE', %s, 'UTC')
    """, (sid, res.iemid))
    res.cursor.execute(
        """
        INSERT into current(iemid, valid) VALUES
        (%s, '2015-09-01 00:00+00')
    """, (res.iemid, ))
    res.cursor.execute(
        """
        INSERT into summary_2015(iemid, day) VALUES
        (%s, '2015-09-01')
    """, (res.iemid, ))
    return res
Exemplo n.º 2
0
def test_calc():
    """Can we compute feels like and RH?"""
    ts = utc(2018)
    ob = observation.Observation('FAKE', 'FAKE', ts)
    ob.data['tmpf'] = 89.
    ob.data['dwpf'] = 70.
    ob.data['sknt'] = 10.
    ob.calc()
    assert (ob.data['feel'] - 94.3) < 0.1
    assert (ob.data['relh'] - 53.6) < 0.1
Exemplo n.º 3
0
def test_calc():
    """Can we compute feels like and RH?"""
    ts = utc(2018)
    ob = observation.Observation("FAKE", "FAKE", ts)
    ob.data["tmpf"] = 89.0
    ob.data["dwpf"] = 70.0
    ob.data["sknt"] = 10.0
    ob.calc()
    assert (ob.data["feel"] - 94.3) < 0.1
    assert (ob.data["relh"] - 53.6) < 0.1
Exemplo n.º 4
0
 def setUp(self):
     ts = datetime.datetime(2015, 9, 1, 1, 0)
     ts = ts.replace(tzinfo=pytz.timezone("UTC"))
     sid = ''.join(random.choice(
                 string.ascii_uppercase + string.digits) for _ in range(7))
     self.iemid = 0 - random.randint(0, 1000)
     self.ob = observation.Observation(sid, 'FAKE', ts)
     self.conn = psycopg2.connect(database='iem', host='iemdb')
     self.cursor = self.conn.cursor(
                     cursor_factory=psycopg2.extras.DictCursor)
     # Create fake station, so we can create fake entry in summary
     # and current tables
     self.cursor.execute("""
         INSERT into stations(id, network, iemid, tzname)
         VALUES (%s, 'FAKE', %s, 'UTC')
     """, (sid, self.iemid))
     self.cursor.execute("""
         INSERT into current(iemid, valid) VALUES
         (%s, '2015-09-01 00:00+00')
     """, (self.iemid, ))
     self.cursor.execute("""
         INSERT into summary_2015(iemid, day) VALUES
         (%s, '2015-09-01')
     """, (self.iemid, ))
Exemplo n.º 5
0
def test_notz():
    """Test that we warn when there is no timezone set."""
    msg = "tzinfo is not set on valid, defaulting to UTC"
    with pytest.warns(UserWarning, match=msg):
        observation.Observation("Z", "Z", datetime.datetime(2000, 1, 1))