コード例 #1
0
    def test_parsing_event_wadls_with_missing_attributes(self):
        """
        Some WADL file miss required attributes. In this case a warning will be
        raised.

        Update: FDSN-WS 1.1 has optional arguments which are no longer
        required!
        """
        # This event WADL misses the includeallorigins and the updatedafter
        # parameters.
        filename = os.path.join(self.data_path,
                                "event_missing_attributes.wadl")
        with open(filename, "rb") as fh:
            wadl_string = fh.read()
        with warnings.catch_warnings(record=True) as w:
            # Cause all warnings to always be triggered.
            warnings.simplefilter("always")
            parser = WADLParser(wadl_string)
            # No warning should be raised due to update to FDSN-WS 1.1.
            self.assertEqual(len(w), 0)

        # Assert that some other parameters are still existent.
        params = parser.parameters
        self.assertIn("starttime", params)
        self.assertIn("endtime", params)
        self.assertIn("minlatitude", params)
        self.assertIn("maxlatitude", params)
        self.assertIn("minlongitude", params)
        self.assertIn("maxlongitude", params)
        self.assertIn("minmagnitude", params)
        self.assertIn("maxmagnitude", params)
        self.assertIn("magnitudetype", params)
        self.assertIn("catalog", params)
コード例 #2
0
    def test_parsing_dataselect_wadls_with_missing_attributes(self):
        """
        Some WADL file miss required attributes. In this case a warning will be
        raised.

        Update: FDSN-WS 1.1 has optional arguments which are no longer
        required!
        """
        # This dataselect WADL misses the quality, minimumlength, and
        # longestonly parameters.
        filename = os.path.join(self.data_path,
                                "dataselect_missing_attributes.wadl")
        with open(filename, "rb") as fh:
            wadl_string = fh.read()
        with warnings.catch_warnings(record=True) as w:
            # Cause all warnings to always be triggered.
            warnings.simplefilter("always")
            parser = WADLParser(wadl_string)
            # No warning should be raised due to update to FDSN-WS 1.1.
            self.assertEqual(len(w), 0)

        # Assert that some other parameters are still existent.
        params = parser.parameters
        self.assertIn("starttime", params)
        self.assertIn("endtime", params)
        self.assertIn("network", params)
        self.assertIn("station", params)
        self.assertIn("location", params)
        self.assertIn("channel", params)
コード例 #3
0
 def _parse_wadl_file(self, filename):
     """
     Parses wadl, returns WADLParser and any catched warnings.
     """
     filename = os.path.join(self.data_path, filename)
     with open(filename, "rb") as fh:
         wadl_string = fh.read()
     with warnings.catch_warnings(record=True) as w:
         # Cause all warnings to always be triggered.
         warnings.simplefilter("always")
         parser = WADLParser(wadl_string)
     return parser, w
コード例 #4
0
    def test_reading_wadls_without_type(self):
        """
        Tests the reading of WADL files that have no type.
        """
        filename = os.path.join(self.data_path, "station_no_types.wadl")
        parser, w = self._parse_wadl_file(filename)
        params = parser.parameters

        # Assert that types have been assigned.
        self.assertEqual(params["starttime"]["type"], UTCDateTime)
        self.assertEqual(params["endtime"]["type"], UTCDateTime)
        self.assertEqual(params["startbefore"]["type"], UTCDateTime)
        self.assertEqual(params["startafter"]["type"], UTCDateTime)
        self.assertEqual(params["endbefore"]["type"], UTCDateTime)
        self.assertEqual(params["endafter"]["type"], UTCDateTime)
        self.assertEqual(params["network"]["type"], str)
        self.assertEqual(params["station"]["type"], str)
        self.assertEqual(params["location"]["type"], str)
        self.assertEqual(params["channel"]["type"], str)
        self.assertEqual(params["minlatitude"]["type"], float)
        self.assertEqual(params["maxlatitude"]["type"], float)
        self.assertEqual(params["latitude"]["type"], float)
        self.assertEqual(params["minlongitude"]["type"], float)
        self.assertEqual(params["maxlongitude"]["type"], float)
        self.assertEqual(params["longitude"]["type"], float)
        self.assertEqual(params["minradius"]["type"], float)
        self.assertEqual(params["maxradius"]["type"], float)
        self.assertEqual(params["level"]["type"], str)
        self.assertEqual(params["includerestricted"]["type"], bool)
        self.assertEqual(params["includeavailability"]["type"], bool)
        self.assertEqual(params["updatedafter"]["type"], UTCDateTime)

        # Now read a dataselect file with no types.
        filename = os.path.join(self.data_path, "dataselect_no_types.wadl")
        with open(filename, "rb") as fh:
            wadl_string = fh.read()
        parser = WADLParser(wadl_string)
        params = parser.parameters

        # Assert that types have been assigned.
        self.assertEqual(params["starttime"]["type"], UTCDateTime)
        self.assertEqual(params["endtime"]["type"], UTCDateTime)
        self.assertEqual(params["network"]["type"], str)
        self.assertEqual(params["station"]["type"], str)
        self.assertEqual(params["location"]["type"], str)
        self.assertEqual(params["channel"]["type"], str)
        self.assertEqual(params["quality"]["type"], str)
        self.assertEqual(params["minimumlength"]["type"], float)
        self.assertEqual(params["longestonly"]["type"], bool)
コード例 #5
0
    def test_usgs_event_wadl_parsing(self):
        """
        Tests the parsing of an event wadl.
        """
        filename = os.path.join(self.data_path, "usgs_event.wadl")
        with open(filename, "rb") as fh:
            wadl_string = fh.read()
        parser = WADLParser(wadl_string)
        params = parser.parameters

        # The WADL contains some short forms. In the parameters dictionary
        # these should be converted to the long forms.
        self.assertIn("starttime", params)
        self.assertIn("endtime", params)
        self.assertIn("minlatitude", params)
        self.assertIn("maxlatitude", params)
        self.assertIn("minlongitude", params)
        self.assertIn("maxlongitude", params)
        self.assertIn("minmagnitude", params)
        self.assertIn("maxmagnitude", params)
        self.assertIn("magnitudetype", params)
        self.assertIn("catalog", params)

        self.assertIn("contributor", params)
        self.assertIn("maxdepth", params)
        self.assertIn("mindepth", params)
        self.assertIn("latitude", params)
        self.assertIn("longitude", params)

        self.assertIn("maxradius", params)
        self.assertIn("minradius", params)
        self.assertIn("orderby", params)
        self.assertIn("updatedafter", params)

        self.assertIn("eventid", params)
        self.assertIn("includearrivals", params)
        self.assertIn("includeallmagnitudes", params)
        self.assertIn("includeallorigins", params)
        self.assertIn("limit", params)
        self.assertIn("offset", params)
コード例 #6
0
    def test_dataselect_wadl_parsing(self):
        """
        Tests the parsing of a dataselect wadl.
        """
        filename = os.path.join(self.data_path, "dataselect.wadl")
        with open(filename, "rb") as fh:
            wadl_string = fh.read()
        parser = WADLParser(wadl_string)
        params = parser.parameters

        self.assertIn("starttime", params)
        self.assertIn("endtime", params)
        self.assertIn("network", params)
        self.assertIn("station", params)
        self.assertIn("location", params)
        self.assertIn("channel", params)
        self.assertIn("quality", params)
        self.assertIn("minimumlength", params)
        self.assertIn("quality", params)
        self.assertIn("longestonly", params)

        self.assertEqual(params["starttime"]["type"], UTCDateTime)
        self.assertEqual(params["starttime"]["required"], True)

        self.assertEqual(params["endtime"]["type"], UTCDateTime)
        self.assertEqual(params["endtime"]["required"], True)

        self.assertEqual(params["network"]["type"], str)
        self.assertEqual(params["station"]["type"], str)
        self.assertEqual(params["location"]["type"], str)
        self.assertEqual(params["channel"]["type"], str)

        self.assertEqual(sorted(params["quality"]["options"]),
                         sorted(["D", "R", "Q", "M", "B"]))

        # Check that the default values did get read correctly.
        self.assertEqual(params["quality"]["default_value"], "B")
        self.assertEqual(params["minimumlength"]["default_value"], 0.0)
        self.assertEqual(params["longestonly"]["default_value"], False)