def test_enum(self): """ Tests for the enum type. """ items = ["m", "s", "m/s", "m/(s*s)", "m*s", "dimensionless", "other"] units = Enum(items) # existing selections self.assertEqual(units.other, "other") self.assertEqual(units.M, "m") self.assertEqual(units['m/s'], "m/s") self.assertEqual(units.get('m/s'), "m/s") self.assertEqual(units[0], "m") self.assertEqual(units[-1], "other") # not existing selections should fail self.assertRaises(Exception, units.__getitem__, '5') self.assertRaises(Exception, units.__getattr__, 'xx') self.assertRaises(Exception, units.get, 'xx', 'default') self.assertRaises(Exception, units.__getitem__, 99) self.assertRaises(Exception, units.__getitem__, -99) # test in operator self.assertTrue("other" in units) self.assertTrue("ot21her" not in units) # test typical dict methods self.assertEqual(units.values(), items) self.assertEqual(units.items(), list(zip(items, items))) self.assertEqual(units.keys(), items) # call will either return correct enum label or return None self.assertEqual(units('m'), 'm') self.assertEqual(units('m/(s*s)'), 'm/(s*s)') self.assertEqual(units(5), 'dimensionless') self.assertEqual(units(99), None) self.assertEqual(units('xxx'), None)
from obspy.core.util import Enum OriginUncertaintyDescription = Enum([ "horizontal uncertainty", "uncertainty ellipse", "confidence ellipsoid", ]) AmplitudeCategory = Enum([ "point", "mean", "duration", "period", "integral", "other", ]) OriginDepthType = Enum([ "from location", "from moment tensor inversion", "from modeling of broad-band P waveforms", "constrained by depth phases", "constrained by direct phases", "constrained by depth and direct phases", "operator assigned", "other", ]) OriginType = Enum([ "hypocenter", "centroid",
import collections import copy from multiprocessing.pool import ThreadPool import numpy as np import os import time import timeit import obspy from obspy.core.util import Enum from . import utils # The current status of an entity. STATUS = Enum(["none", "needs_downloading", "downloaded", "ignore", "exists", "download_failed", "download_rejected", "download_partially_failed"]) class Station(object): """ Object representing a seismic station within the download helper classes. It knows the coordinates of the station to perform the filtering, its channels and the filename and status of the StationXML files. :param network: The network code. :type network: str :param station: The station code. :type station: str :param latitude: The latitude of the station.
def test_enum(self): """ Tests for the enum type. """ items = ["m", "s", "m/s", "m/(s*s)", "m*s", "dimensionless", "other"] units = Enum(items) # existing selections assert units.other == "other" assert units.M == "m" assert units['m/s'] == "m/s" assert units.get('m/s') == "m/s" assert units[0] == "m" assert units[-1] == "other" # not existing selections should fail with pytest.raises(Exception): units.__getitem__('5') with pytest.raises(Exception): units.__getattr__('xx') with pytest.raises(Exception): units.get('xx', 'default') with pytest.raises(Exception): units.__getitem__(99) with pytest.raises(Exception): units.__getitem__(-99) # test in operator assert "other" in units assert "ot21her" not in units # test typical dict methods assert units.values() == items assert units.items() == list(zip(items, items)) assert units.keys() == items # call will either return correct enum label or return None assert units('m') == 'm' assert units('m/(s*s)') == 'm/(s*s)' assert units(5) == 'dimensionless' assert units(99) is None assert units('xxx') is None