def test_create_shapefile_with_loss_map(self):
     """
     Make sure the right function is called for loss maps.
     """
     config = dict(key="22", layer="", output="", path=self.map_file,
                   type="loss")
     with mock.patch(
         'bin.map_transformer.create_shapefile_from_loss_map') as mf:
         mf.return_value = ("", 0, 1)
         create_shapefile(config)
         self.assertEqual(1, mf.call_count)
Beispiel #2
0
 def test_create_shapefile_with_loss_map(self):
     """
     Make sure the right function is called for loss maps.
     """
     config = dict(key="22", layer="", output="", path=self.map_file,
                   type="loss")
     with mock.patch(
         'bin.map_transformer.create_shapefile_from_loss_map') as mf:
         mf.return_value = ("", 0, 1)
         create_shapefile(config)
         self.assertEqual(1, mf.call_count)
    def test_create_shapefile_with_no_output_specified_loss(self):
        """
        This is bascially the same test as
        `test_create_shapefile_with_no_output_specified_hazard`, but for loss
        map shapefiles.
        """
        config = dict(key="11", layer="", output="", path=self.map_file,
                      type="loss")

        # mock the create_shapefile_from_hazard_map function so we don't
        # actually create a shapefile
        with mock.patch('bin.gen_shapefile.create_shapefile_from_loss_map') \
            as _mock_func:
            create_shapefile(config)
            expected_output = os.path.join(
                os.path.dirname(config['path']),
                'loss-shapefiles')
            self.assertEqual(expected_output, config['output'])
 def test_create_shapefile_no_output(self):
     """
     If unspecified the output is determined from the map's path/layer.
     """
     config = dict(key="17", layer="", output="", path=self.map_file,
                   type="hazard")
     with mock.patch(
         'bin.map_transformer.create_shapefile_from_hazard_map') as mf:
         mf.return_value = ("", 0, 1)
         create_shapefile(config)
         basename = os.path.basename(self.map_file)
         expected_layer = "%s-%s" % (config["key"], basename)
         [actual_config], _kwargs = mf.call_args
         self.assertEqual(expected_layer, actual_config["layer"])
         dirname = os.path.dirname(self.map_file)
         self.assertEqual(
             os.path.join(dirname, "%s-shapefiles" % config["type"]),
             actual_config["output"])
Beispiel #5
0
    def test_create_shapefile_with_no_output_specified_loss(self):
        """
        This is bascially the same test as
        `test_create_shapefile_with_no_output_specified_hazard`, but for loss
        map shapefiles.
        """
        config = dict(key="11", layer="", output="", path=self.map_file,
                      type="loss")

        # mock the create_shapefile_from_hazard_map function so we don't
        # actually create a shapefile
        with mock.patch('bin.map_transformer.create_shapefile_from_loss_map') \
            as _mock_func:
            create_shapefile(config)
            expected_output = os.path.join(
                os.path.dirname(config['path']),
                'loss-shapefiles')
            self.assertEqual(expected_output, config['output'])
Beispiel #6
0
 def test_create_shapefile_no_output(self):
     """
     If unspecified the output is determined from the map's path/layer.
     """
     config = dict(key="17", layer="", output="", path=self.map_file,
                   type="hazard")
     with mock.patch(
         'bin.map_transformer.create_shapefile_from_hazard_map') as mf:
         mf.return_value = ("", 0, 1)
         create_shapefile(config)
         basename = os.path.basename(self.map_file)
         expected_layer = "%s-%s" % (config["key"], basename)
         [actual_config], _kwargs = mf.call_args
         self.assertEqual(expected_layer, actual_config["layer"])
         dirname = os.path.dirname(self.map_file)
         self.assertEqual(
             os.path.join(dirname, "%s-shapefiles" % config["type"]),
             actual_config["output"])
    def test_create_shapefile_with_no_output_specified_hazard(self):
        """
        If no 'output' parameter is specified, create_shapefile() will try to
        create an output path based on the 'path' parameter.

        For example: if 'path' is set to '/tmp/some-hazard-map.xml',
        create_shapefile() will attempt to create an output directory called
        '/tmp/hazard-shapefiles/'.
        """
        config = dict(key="11", layer="", output="", path=self.map_file,
                      type="hazard")

        # mock the create_shapefile_from_hazard_map function so we don't
        # actually create a shapefile
        with mock.patch('bin.gen_shapefile.create_shapefile_from_hazard_map') \
            as _mock_func:
            create_shapefile(config)
            expected_output = os.path.join(
                os.path.dirname(config['path']),
                'hazard-shapefiles')
            self.assertEqual(expected_output, config['output'])
Beispiel #8
0
    def test_create_shapefile_with_no_output_specified_hazard(self):
        """
        If no 'output' parameter is specified, create_shapefile() will try to
        create an output path based on the 'path' parameter.

        For example: if 'path' is set to '/tmp/some-hazard-map.xml',
        create_shapefile() will attempt to create an output directory called
        '/tmp/hazard-shapefiles/'.
        """
        config = dict(key="11", layer="", output="", path=self.map_file,
                      type="hazard")

        # mock the create_shapefile_from_hazard_map function so we don't
        # actually create a shapefile
        with mock.patch('bin.map_transformer.'
                        'create_shapefile_from_hazard_map') \
            as _mock_func:
            create_shapefile(config)
            expected_output = os.path.join(
                os.path.dirname(config['path']),
                'hazard-shapefiles')
            self.assertEqual(expected_output, config['output'])
 def test_create_shapefile_no_output_with_dots(self):
     """
     If unspecified the output is determined from the map's path/layer.
     All dot characters in the layer name will be replaced by dashes.
     """
     map_file2 = self.touch(prefix="we.love.dots.")
     config = dict(key="18", layer="", output="", path=map_file2,
                   type="hazard")
     with mock.patch(
         'bin.map_transformer.create_shapefile_from_hazard_map') as mf:
         mf.return_value = ("", 0, 1)
         create_shapefile(config)
         basename = os.path.basename(map_file2)
         basename, _ = os.path.splitext(basename)
         expected_layer = (
             "%s-%s" % (config["key"], basename.replace(".", "-")))
         [actual_config], _kwargs = mf.call_args
         self.assertEqual(expected_layer, actual_config["layer"])
         dirname = os.path.dirname(self.map_file)
         self.assertEqual(
             os.path.join(dirname, "%s-shapefiles" % config["type"]),
             actual_config["output"])
     os.unlink(map_file2)
Beispiel #10
0
 def test_create_shapefile_no_output_with_dots(self):
     """
     If unspecified the output is determined from the map's path/layer.
     All dot characters in the layer name will be replaced by dashes.
     """
     map_file2 = self.touch(prefix="we.love.dots.")
     config = dict(key="18", layer="", output="", path=map_file2,
                   type="hazard")
     with mock.patch(
         'bin.map_transformer.create_shapefile_from_hazard_map') as mf:
         mf.return_value = ("", 0, 1)
         create_shapefile(config)
         basename = os.path.basename(map_file2)
         basename, _ = os.path.splitext(basename)
         expected_layer = (
             "%s-%s" % (config["key"], basename.replace(".", "-")))
         [actual_config], _kwargs = mf.call_args
         self.assertEqual(expected_layer, actual_config["layer"])
         dirname = os.path.dirname(self.map_file)
         self.assertEqual(
             os.path.join(dirname, "%s-shapefiles" % config["type"]),
             actual_config["output"])
     os.unlink(map_file2)