Example #1
0
 def test_base_01(self):
     """Simple test."""
     # The simpliest __init_: datetime and res
     obs = obshydro.Observations(
         obshydro.Observation('2012-10-03 06:00', 33),
         obshydro.Observation('2012-10-03 07:00', 37),
         obshydro.Observation('2012-10-03 08:00', 42))
     self.assertEqual(obs['res'].tolist(), [33, 37, 42])
Example #2
0
 def test_error_01(self):
     """Concat error test."""
     obs1 = obshydro.Observations(
         obshydro.Observation('2012-10-03 06:00', 33),
         obshydro.Observation('2012-10-03 07:00', 37),
         obshydro.Observation('2012-10-03 08:00', 42))
     self.assertRaises(TypeError, obshydro.Observations.concat,
                       *(obs1, '33'))
Example #3
0
 def test_str_02(self):
     """Test __str__ method with a small Observations."""
     s = sitehydro.Stationhydro(code='A044581001')
     o = obshydro.Observations(obshydro.Observation('2012-10-03 06:00', 33),
                               obshydro.Observation('2012-10-03 08:00', 42))
     serie = obshydro.Serie(entite=s, grandeur='Q', observations=o)
     self.assertTrue(serie.__str__().rfind('Serie') > -1)
     self.assertTrue(serie.__str__().rfind('Statut') > -1)
     self.assertTrue(serie.__str__().rfind('Observations') > -1)
Example #4
0
 def test_base_02(self):
     """Some instanciation use cases."""
     obshydro.Observation('2000-01-01 10:33:01', 20)
     obshydro.Observation('2000-01-01 10:33', 0, 4)
     obshydro.Observation('2000-01-01 00:00+0100', 10, 4, 8, True)
     obshydro.Observation(datetime.datetime(2000, 1, 1, 10),
                          10,
                          mth=4,
                          qal=8)
     obshydro.Observation(datetime.datetime(2000, 1, 1), '20', cnt=True)
Example #5
0
 def test_base_02(self):
     """Serie on a station with no statut."""
     s = sitehydro.Stationhydro(code='A044581001')
     g = 'Q'
     o = obshydro.Observations(obshydro.Observation('2012-10-03 06:00', 33),
                               obshydro.Observation('2012-10-03 08:00', 42))
     serie = obshydro.Serie(entite=s, grandeur=g, observations=o)
     self.assertEqual((serie.entite, serie.grandeur, serie.statut,
                       serie.observations, serie._strict),
                      (s, g, 0, o, True))
Example #6
0
 def test_error_01(self):
     """Date error."""
     obshydro.Observation(**{'dte': '2000-10-10 10:00', 'res': 10})
     self.assertRaises(TypeError, obshydro.Observation, **{
         'dte': '2000-10',
         'res': 10
     })
Example #7
0
 def test_error_02(self):
     """Res error."""
     obshydro.Observation(**{'dte': '2000-10-05 10:00', 'res': 10})
     self.assertRaises(ValueError, obshydro.Observation, **{
         'dte': '2000-10-05 10:00',
         'res': 'aaa'
     })
Example #8
0
 def test_base_01(self):
     """Serie on a site."""
     s = sitehydro.Sitehydro(code='A0445810',
                             libelle='Le Rhône à Marseille')
     g = 'Q'
     t = 16
     o = obshydro.Observations(obshydro.Observation('2012-10-03 06:00', 33),
                               obshydro.Observation('2012-10-03 07:00', 37),
                               obshydro.Observation('2012-10-03 08:00', 42))
     i = True
     serie = obshydro.Serie(entite=s,
                            grandeur=g,
                            statut=t,
                            observations=o,
                            strict=i)
     self.assertEqual((serie.entite, serie.grandeur, serie.statut,
                       serie.observations, serie._strict), (s, g, t, o, i))
Example #9
0
 def test_str_01(self):
     """Test __str__ method."""
     dte = '2000-01-01 10:33:01+0000'
     res = 20.5
     mth = 4
     qal = 8
     cnt = False
     obs = obshydro.Observation(dte, res, mth, qal, cnt)
     self.assertTrue(obs.__str__().rfind('UTC') > -1)
     self.assertTrue(obs.__str__().rfind('continue') > -1)
Example #10
0
 def test_base_01(self):
     """Base case test."""
     dte = '2000-01-01 10:33:01+0000'
     res = 20.5
     mth = 4
     qal = 8
     cnt = False
     obs = obshydro.Observation(dte, res, mth, qal, cnt)
     self.assertEqual(
         obs.item(),
         (datetime.datetime(2000, 1, 1, 10, 33, 1), res, mth, qal, cnt))
Example #11
0
 def test_error_01(self):
     """Entite error."""
     s = sitehydro.Stationhydro(code='A044581001', strict=False)
     o = obshydro.Observations(obshydro.Observation('2012-10-03 06:00', 33))
     obshydro.Serie(**{'entite': s, 'grandeur': 'H', 'observations': o})
     self.assertRaises(
         TypeError, obshydro.Serie, **{
             'entite': 'X',
             'grandeur': 'H',
             'observations': o
         })
Example #12
0
 def test_str_03(self):
     """Test __str__ method with a big Observations."""
     s = sitehydro.Stationhydro(code='A044581001', libelle='Toulouse')
     o = obshydro.Observations(*[
         obshydro.Observation('20%i-01-01 00:00' % x, x)
         for x in xrange(10, 50)
     ])
     serie = obshydro.Serie(entite=s, grandeur='H', observations=o)
     self.assertTrue(serie.__str__().rfind('Serie') > -1)
     self.assertTrue(serie.__str__().rfind('Statut') > -1)
     self.assertTrue(serie.__str__().rfind('Observations') > -1)
Example #13
0
 def test_error_04(self):
     """Qal error."""
     obshydro.Observation(**{
         'dte': '2000-10-05 10:00',
         'res': 20,
         'qal': 16
     })
     self.assertRaises(
         ValueError, obshydro.Observation, **{
             'dte': '2000-10-05 10:00',
             'res': 20,
             'qal': 1000
         })
Example #14
0
 def test_base_02(self):
     """Base case test."""
     # Datetime, res and others attributes
     obs = obshydro.Observations(
         obshydro.Observation('2012-10-03 06:00',
                              33,
                              mth=4,
                              qal=0,
                              cnt=True),
         obshydro.Observation('2012-10-03 07:00',
                              37,
                              mth=0,
                              qal=12,
                              cnt=False),
         obshydro.Observation('2012-10-03 08:00',
                              42,
                              mth=12,
                              qal=20,
                              cnt=True))
     self.assertEqual(obs['mth'].tolist(), [4, 0, 12])
     self.assertEqual(obs['qal'].tolist(), [0, 12, 20])
     self.assertEqual(obs['cnt'].tolist(), [True, False, True])
Example #15
0
 def test_error_03(self):
     """Mth error."""
     obshydro.Observation(**{
         'dte': '2000-10-05 10:00',
         'res': 20,
         'mth': 4
     })
     self.assertRaises(
         ValueError, obshydro.Observation, **{
             'dte': '2000-10-05 10:00',
             'res': 20,
             'mth': 1000
         })
Example #16
0
 def test_error_01(self):
     """List of observation error."""
     # check that init works when call regurlaly...
     o = obshydro.Observation('2012-10-03 06:00',
                              33,
                              mth=4,
                              qal=0,
                              cnt=True)
     obshydro.Observations(*[o, o])
     # ...and fails otherwise
     self.assertRaises(
         TypeError,
         obshydro.Observations,
         # *[o, o]  # is good !
         *[o, 33]  # is wrong !!
     )
Example #17
0
def _observations_from_element(element):
    """Return a obshydro.Observations from a <ObssHydro> element."""
    if element is not None:

        # prepare a list of Observation
        observations = []
        for o in element:
            args = {}
            args['dte'] = _value(o, 'DtObsHydro', _UTC)
            args['res'] = _value(o, 'ResObsHydro')
            mth = _value(o, 'MethObsHydro', int)
            if mth is not None:
                args['mth'] = mth
            qal = _value(o, 'QualifObsHydro', int)
            if qal is not None:
                args['qal'] = qal
            # we can't use bool injection here because bool('False') is True
            cnt = _value(o, 'ContObsHydro')
            if cnt is not None:
                args['cnt'] = True if (cnt == 'True') else False
            observations.append(_obshydro.Observation(**args))

        # build Observations
        return _obshydro.Observations(*observations)
Example #18
0
 def test_base_01(self):
     """Concat base test."""
     obs1 = obshydro.Observations(
         obshydro.Observation('2012-10-03 06:00', 33),
         obshydro.Observation('2012-10-03 07:00', 37),
         obshydro.Observation('2012-10-03 08:00', 42))
     obs2 = obshydro.Observations(
         obshydro.Observation('2014-10-03 06:00', 330),
         obshydro.Observation('2014-10-03 07:00', 370),
         obshydro.Observation('2014-10-03 08:00', 420))
     expected = obshydro.Observations(
         obshydro.Observation('2012-10-03 06:00', 33),
         obshydro.Observation('2012-10-03 07:00', 37),
         obshydro.Observation('2012-10-03 08:00', 42),
         obshydro.Observation('2014-10-03 06:00', 330),
         obshydro.Observation('2014-10-03 07:00', 370),
         obshydro.Observation('2014-10-03 08:00', 420))
     concat = obshydro.Observations.concat(obs1, obs2)
     self.assertTrue(numpy.array_equal(concat, expected))