def test_str_01(self): """Test __str__ method with minimum values.""" # None values serie = obshydro.Serie(strict=False) self.assertTrue(serie.__str__().rfind('Serie') > -1) self.assertTrue(serie.__str__().rfind('Statut') > -1) self.assertTrue(serie.__str__().rfind('Observations') > -1) # a junk entite serie = obshydro.Serie(entite='station 33', strict=False) self.assertTrue(serie.__str__().rfind('station 33') > -1)
def _serie_from_element(element): """Return a obshydro.Serie from a <Serie> element.""" if element is not None: # entite can be a Sitehydro, a Stationhydro or a Capteur entite = None if element.find('CdSiteHydro') is not None: entite = _sitehydro.Sitehydro( code=_value(element, 'CdSiteHydro') ) elif element.find('CdStationHydro') is not None: entite = _sitehydro.Stationhydro( code=_value(element, 'CdStationHydro') ) elif element.find('CdCapteur') is not None: entite = _sitehydro.Capteur( code=_value(element, 'CdCapteur') ) # make the Serie return _obshydro.Serie( entite=entite, grandeur=_value(element, 'GrdSerie'), statut=_value(element, 'StatutSerie'), observations=_observations_from_element(element.find('ObssHydro')) )
def test_fuzzy_mode_01(self): """Fuzzy mode test.""" s = 4 g = 'RR' t = 123 o = [10, 13, 25, 8] serie = obshydro.Serie(entite=s, grandeur=g, statut=t, observations=o, strict=False) self.assertEqual((serie.entite, serie.grandeur, serie.statut, serie.observations, serie._strict), (s, g, t, o, False)) serie = obshydro.Serie(strict=False) self.assertEqual((serie.entite, serie.grandeur, serie.statut, serie.observations, serie._strict), (None, None, 0, None, False))
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)
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))
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 })
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)
def test_error_04(self): """Observations error.""" s = sitehydro.Stationhydro(code='A044581001', strict=False) obshydro.Serie(**{ 'entite': s, 'grandeur': 'H', 'observations': 12, 'strict': False }) self.assertRaises( TypeError, obshydro.Serie, **{ 'entite': s, 'grandeur': 'H', 'observations': 12, 'strict': True })
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))