예제 #1
0
    def test_insert_map_datum(self):
        """An `uiapi.hazard_map_data` record is inserted correctly."""
        self.output = self.setup_output()
        session = Session.get()
        hmw = HazardMapDBWriter(
            session, self.output.path, self.output.oq_job.id)
        hmw.output = self.output

        # This output has no map data before calling the function under test.
        self.assertEqual(0, len(self.output.hazardmapdata_set))
        self.assertEqual(0, len(self.output.lossmapdata_set))

        # Call the function under test.
        data = HAZARD_MAP_DATA[-1]
        hmw.insert_map_datum(*data)

        # After calling the function under test we see the expected map data.
        self.assertEqual(1, len(self.output.hazardmapdata_set))
        self.assertEqual(0, len(self.output.lossmapdata_set))

        # Make sure the inserted map data is correct.
        [hmd] = self.output.hazardmapdata_set
        point = data[0].point
        self.assertEqual([point.x, point.y], hmd.location.coords(session))
        self.assertEqual(round_float(data[1].get("IML")),
                         round_float(hmd.value))
예제 #2
0
    def test_insert_map_datum(self):
        """An `uiapi.hazard_map_data` record is inserted correctly."""
        self.output = self.setup_output()
        session = Session.get()
        hmw = HazardMapDBWriter(session, self.output.path,
                                self.output.oq_job.id)
        hmw.output = self.output

        # This output has no map data before calling the function under test.
        self.assertEqual(0, len(self.output.hazardmapdata_set))
        self.assertEqual(0, len(self.output.lossmapdata_set))

        # Call the function under test.
        data = HAZARD_MAP_DATA[-1]
        hmw.insert_map_datum(*data)

        # After calling the function under test we see the expected map data.
        self.assertEqual(1, len(self.output.hazardmapdata_set))
        self.assertEqual(0, len(self.output.lossmapdata_set))

        # Make sure the inserted map data is correct.
        [hmd] = self.output.hazardmapdata_set
        point = data[0].point
        self.assertEqual([point.x, point.y], hmd.location.coords(session))
        self.assertEqual(round_float(data[1].get("IML")),
                         round_float(hmd.value))
예제 #3
0
    def test_serialize_small(self):
        data = HAZARD_MAP_DATA(20, 4)

        self.job = self.setup_classic_job()
        output_path = self.generate_output_path(self.job)

        for i in xrange(0, 10):
            hmw = HazardMapDBWriter(output_path + str(i), self.job.id)

            # Call the function under test.
            hmw.serialize(data)
예제 #4
0
    def test_serialize_small(self):
        data = HAZARD_MAP_DATA(20, 4)

        self.job = self.setup_classic_job()
        output_path = self.generate_output_path(self.job)

        for i in xrange(0, 10):
            hmw = HazardMapDBWriter(output_path + str(i), self.job.id)

            # Call the function under test.
            hmw.serialize(data)
예제 #5
0
    def setUp(self):
        self.job = self.setup_classic_job()
        output_path = self.generate_output_path(self.job)
        self.display_name = os.path.basename(output_path)

        self.writer = HazardMapDBWriter(output_path, self.job.id)
        self.reader = HazardMapDBReader()
예제 #6
0
    def test_serialize_sets_min_max_values(self):
        """
        serialize() sets the minimum and maximum values on the output record.
        """
        self.job = self.setup_classic_job()
        session = Session.get()
        output_path = self.generate_output_path(self.job)
        hmw = HazardMapDBWriter(session, output_path, self.job.id)

        # Call the function under test.
        hmw.serialize(HAZARD_MAP_DATA)

        minimum = min(data[1].get("IML") for data in HAZARD_MAP_DATA)
        maximum = max(data[1].get("IML") for data in HAZARD_MAP_DATA)
        # After calling the function under test we see the expected map data.
        [output] = self.job.output_set
        self.assertEqual(round_float(minimum), round_float(output.min_value))
        self.assertEqual(round_float(maximum), round_float(output.max_value))
예제 #7
0
    def test_serialize_sets_min_max_values(self):
        """
        serialize() sets the minimum and maximum values on the output record.
        """
        self.job = self.setup_classic_job()
        session = Session.get()
        output_path = self.generate_output_path(self.job)
        hmw = HazardMapDBWriter(session, output_path, self.job.id)

        # Call the function under test.
        hmw.serialize(HAZARD_MAP_DATA)

        minimum = min(data[1].get("IML") for data in HAZARD_MAP_DATA)
        maximum = max(data[1].get("IML") for data in HAZARD_MAP_DATA)
        # After calling the function under test we see the expected map data.
        [output] = self.job.output_set
        self.assertEqual(round_float(minimum), round_float(output.min_value))
        self.assertEqual(round_float(maximum), round_float(output.max_value))
예제 #8
0
    def test_serialize(self):
        """serialize() inserts the output and the hazard_map_data records."""
        self.job = self.setup_classic_job()
        session = Session.get()
        output_path = self.generate_output_path(self.job)
        hmw = HazardMapDBWriter(session, output_path, self.job.id)

        # This job has no outputs before calling the function under test.
        self.assertEqual(0, len(self.job.output_set))

        # Call the function under test.
        hmw.serialize(HAZARD_MAP_DATA)

        # After calling the function under test we see the expected output.
        self.assertEqual(1, len(self.job.output_set))

        # After calling the function under test we see the expected map data.
        [output] = self.job.output_set
        self.assertEqual(len(HAZARD_MAP_DATA), len(output.hazardmapdata_set))
        self.assertEqual(0, len(output.lossmapdata_set))
예제 #9
0
    def test_serialize(self):
        """serialize() inserts the output and the hazard_map_data records."""
        self.job = self.setup_classic_job()
        session = Session.get()
        output_path = self.generate_output_path(self.job)
        hmw = HazardMapDBWriter(session, output_path, self.job.id)

        # This job has no outputs before calling the function under test.
        self.assertEqual(0, len(self.job.output_set))

        # Call the function under test.
        hmw.serialize(HAZARD_MAP_DATA)

        # After calling the function under test we see the expected output.
        self.assertEqual(1, len(self.job.output_set))

        # After calling the function under test we see the expected map data.
        [output] = self.job.output_set
        self.assertEqual(len(HAZARD_MAP_DATA), len(output.hazardmapdata_set))
        self.assertEqual(0, len(output.lossmapdata_set))
예제 #10
0
    def test_insert_output(self):
        """An `uiapi.output` record is inserted correctly."""
        self.job = self.setup_classic_job()
        session = Session.get()
        output_path = self.generate_output_path(self.job)
        hmw = HazardMapDBWriter(session, output_path, self.job.id)

        # This job has no outputs before calling the function under test.
        self.assertEqual(0, len(self.job.output_set))

        # Call the function under test.
        hmw.insert_output()

        # After calling the function under test we see the expected output.
        self.assertEqual(1, len(self.job.output_set))

        # Make sure the inserted output record has the right data.
        [output] = self.job.output_set
        self.assertTrue(output.db_backed)
        self.assertEqual(output_path, output.path)
        self.assertEqual("hazard_map", output.output_type)
        self.assertIs(self.job, output.oq_job)
예제 #11
0
    def test_insert_output(self):
        """An `uiapi.output` record is inserted correctly."""
        self.job = self.setup_classic_job()
        session = Session.get()
        output_path = self.generate_output_path(self.job)
        hmw = HazardMapDBWriter(session, output_path, self.job.id)

        # This job has no outputs before calling the function under test.
        self.assertEqual(0, len(self.job.output_set))

        # Call the function under test.
        hmw.insert_output()

        # After calling the function under test we see the expected output.
        self.assertEqual(1, len(self.job.output_set))

        # Make sure the inserted output record has the right data.
        [output] = self.job.output_set
        self.assertTrue(output.db_backed)
        self.assertEqual(output_path, output.path)
        self.assertEqual("hazard_map", output.output_type)
        self.assertIs(self.job, output.oq_job)