Ejemplo n.º 1
0
 def test_top_metadata(self, mock_stdout):
     """Test that inspect_job dumps top-level metadata.
     """
     inspect_job(self.job)
     output = mock_stdout.getvalue()
     for key, value in [("bar", "high"), ("shape", "rotund")]:
         self._check_metadata(key, value, output)
Ejemplo n.º 2
0
 def test_measurements(self, mock_stdout):
     """Test that inspect_job dumps measurements with and without metadata.
     """
     inspect_job(self.job)
     output = mock_stdout.getvalue()
     # MeasurementSet.values does not exist
     for _, measurement in self.job.measurements.items():
         self._check_measurement(measurement, output)
Ejemplo n.º 3
0
 def test_metrics(self, mock_stdout):
     """Test that inspect_job only mentions metrics with measurements."
     """
     inspect_job(self.job)
     self.assertNotIn("foo.boringmetric", mock_stdout.getvalue())
     self.assertIn("foo.fancymetric", mock_stdout.getvalue())
     self.assertIn("foo.fanciermetric", mock_stdout.getvalue())
     self.assertIn("foo.fanciestmetric", mock_stdout.getvalue())
Ejemplo n.º 4
0
 def test_top_metadata(self, mock_stdout):
     """Test that inspect_job dumps top-level metadata.
     """
     inspect_job(self.job)
     output = mock_stdout.getvalue()
     for key, value in [("bar", "high"), ("shape", "rotund")]:
         regex = r"%s.+%s" % (key, value)
         match = re.search(regex, output, flags=self.regex_flags)
         self.assertIsNotNone(match, msg="Can't find metadata %s" % key)
Ejemplo n.º 5
0
    def test_metadataonly(self, mock_stdout):
        """Test that inspect_job can handle files with metadata but no metrics.
        """
        # Job and its components were not designed to support deletion, so
        # create a new Job from scratch to ensure it's a valid object.
        job = Job()
        job.metrics.insert(
            Metric("foo.boringmetric", "", u.percent, tags=["redundant"]))
        job.metrics.insert(
            Metric("foo.fancymetric", "", u.meter, tags=["vital"]))
        job.meta["bar"] = "high"
        job.meta["shape"] = "rotund"
        job.specs.insert(
            ThresholdSpecification("utterly_ridiculous", 1e10 * u.meter, ">"))

        inspect_job(job)
        output = mock_stdout.getvalue()
        for key, value in [("bar", "high"), ("shape", "rotund")]:
            self._check_metadata(key, value, output)
Ejemplo n.º 6
0
    def test_metricsonly(self, mock_stdout):
        """Test that inspect_job can handle files with metrics but no metadata.
        """
        # Job and its components were not designed to support deletion, so
        # create a new Job from scratch to ensure it's a valid object.
        job = Job()
        job.metrics.insert(
            Metric("foo.boringmetric", "", u.percent, tags=["redundant"]))
        job.metrics.insert(
            Metric("foo.fancymetric", "", u.meter, tags=["vital"]))
        job.measurements.insert(Measurement("foo.fancymetric", 2.0 * u.meter))
        job.measurements.insert(
            Measurement("foo.fanciermetric", 3.5 * u.second))
        job.measurements["foo.fanciermetric"].notes["fanciness"] = "moderate"
        job.measurements.insert(
            Measurement("foo.fanciestmetric", 3.1415927 * u.kilogram))

        inspect_job(job)
        output = mock_stdout.getvalue()
        # MeasurementSet.values does not exist
        for _, measurement in job.measurements.items():
            self._check_measurement(measurement, output)
Ejemplo n.º 7
0
    def test_measurement_metadata(self, mock_stdout):
        """Test that inspect_job dumps measurement-level metadata on the same
        line as their measurement.
        """
        inspect_job(self.job)
        output = mock_stdout.getvalue()
        for metric_name, measurement in self.job.measurements.items():
            line = re.search("^.*%s.*$" % metric_name,
                             output,
                             flags=self.regex_flags | re.MULTILINE)
            error = "Can't find measurement %s" % metric_name
            self.assertIsNotNone(line, msg=error)
            line = line.group()

            for key in measurement.notes:
                regex = r"(?P<keyname>[\w\.]+)\W+%s" % (measurement.notes[key])
                match = re.search(regex, line, flags=self.regex_flags)
                self.assertIsNotNone(match,
                                     msg="Can't find metadata %s." % key)
                reportedMetadataName = match.group('keyname')
                fullMetadataName = "%s.%s" % (measurement.metric_name,
                                              reportedMetadataName)
                self.assertEqual(fullMetadataName, key)
Ejemplo n.º 8
0
 def test_empty(self, mock_stdout):
     """Test that inspect_job can handle files with neither metrics nor
     metadata.
     """
     inspect_job(Job())