コード例 #1
0
    def test_vectors_equal(self):
        """Verify that two primitive vectors assert to be equal."""
        from pygeoprocessing.testing import assert_vectors_equal
        from pygeoprocessing.testing.sampledata import SRS_COLOMBIA
        from pygeoprocessing.testing.sampledata import create_vector_on_disk

        #TODO: does this not work for a single field?

        create_vector = functools.partial(
            VectorTests.create_vector,
            geometries=[LineString([(0, 0), (1, 1)])],
            projection=SRS_COLOMBIA.projection,
            fields={
                'a': 'real',
                'b': 'real'
            },
            attributes=[{
                'a': 0.12,
                'b': 0.1
            }])

        filename_a = os.path.join(self.workspace, 'foo')
        filename_b = os.path.join(self.workspace, 'bar')
        create_vector(filename=filename_a)
        create_vector(filename=filename_b)

        assert_vectors_equal(filename_a, filename_b, 1e-9)
コード例 #2
0
    def test_file_not_found(self):
        """IOError should be raised when a vector does not exist."""
        from pygeoprocessing.testing import assert_vectors_equal
        nonexistent_file_a = os.path.join(self.workspace, 'foo')
        nonexistent_file_b = os.path.join(self.workspace, 'bar')

        with self.assertRaises(IOError):
            assert_vectors_equal(nonexistent_file_a, nonexistent_file_b, 0.1)
コード例 #3
0
    def test_different_geometries(self):
        """Assert we can test geometric values of the same type."""
        from pygeoprocessing.testing import assert_vectors_equal
        filename_a = os.path.join(self.workspace, 'foo')
        filename_b = os.path.join(self.workspace, 'bar')

        VectorTests.create_vector(geometries=[Point(0, 1)],
                                  filename=filename_a)
        VectorTests.create_vector(geometries=[Point(0, 0)],
                                  filename=filename_b)

        with self.assertRaises(AssertionError):
            assert_vectors_equal(filename_a, filename_b, 0.1)
コード例 #4
0
    def test_mismatched_geometry_type(self):
        """Assert mismatched geometry types."""
        from pygeoprocessing.testing import assert_vectors_equal

        filename_a = os.path.join(self.workspace, 'foo')
        filename_b = os.path.join(self.workspace, 'bar')

        VectorTests.create_vector(filename=filename_a)
        VectorTests.create_vector(filename=filename_b,
                                  geometries=[LineString([(0, 0), (0, 1)])])

        with self.assertRaises(AssertionError):
            assert_vectors_equal(filename_a, filename_b, 0.1)
コード例 #5
0
    def test_different_nonnumeric_field_values(self):
        """Assert that nonnumeric field values can be checked correctly."""
        from pygeoprocessing.testing import assert_vectors_equal

        create_vector = functools.partial(VectorTests.create_vector,
                                          fields={'a': 'string'})

        filename_a = os.path.join(self.workspace, 'foo')
        filename_b = os.path.join(self.workspace, 'bar')

        create_vector(filename=filename_a, attributes=[{'a': 'aaa'}])
        create_vector(filename=filename_b, attributes=[{'a': 'bbb'}])

        with self.assertRaises(AssertionError):
            assert_vectors_equal(filename_a, filename_b, 0.1)
コード例 #6
0
    def test_mismatched_projections(self):
        """Raise assertionerror when projections differ."""
        from pygeoprocessing.testing import assert_vectors_equal
        from pygeoprocessing.testing.sampledata import SRS_WILLAMETTE,\
            SRS_COLOMBIA

        filename_a = os.path.join(self.workspace, 'foo')
        filename_b = os.path.join(self.workspace, 'bar')
        VectorTests.create_vector(filename=filename_a,
                                  projection=SRS_WILLAMETTE.projection)
        VectorTests.create_vector(filename=filename_b,
                                  projection=SRS_COLOMBIA.projection)

        with self.assertRaises(AssertionError):
            assert_vectors_equal(filename_a, filename_b, 0.1)
コード例 #7
0
    def test_mismatched_layer_counts(self):
        """Mismatched layer counts should raise assertionerror."""
        from pygeoprocessing.testing import assert_vectors_equal

        # creating manually, since create_vector_on_disk can't create vectors
        # with multiple layers at the moment.
        # Using KML for readability and multi-layer support.
        driver = ogr.GetDriverByName('KML')

        filepath_a = os.path.join(self.workspace, 'foo.kml')
        out_vector_a = driver.CreateDataSource(filepath_a)
        out_vector_a.CreateLayer('a')
        out_vector_a.CreateLayer('b')
        out_vector_a = None

        filepath_b = os.path.join(self.workspace, 'bar.kml')
        out_vector_b = driver.CreateDataSource(filepath_b)
        out_vector_b.CreateLayer('a')
        out_vector_b = None

        with self.assertRaises(AssertionError):
            assert_vectors_equal(filepath_a, filepath_b, 0.1)
コード例 #8
0
    def test_field_mismatch(self):
        """Assert we can catch when fieldnames don't match."""
        from pygeoprocessing.testing import assert_vectors_equal

        filename_a = os.path.join(self.workspace, 'foo')
        filename_b = os.path.join(self.workspace, 'bar')

        create_vector = functools.partial(VectorTests.create_vector,
                                          geometries=[Point(0, 1)])

        create_vector(filename=filename_a,
                      fields={'a': 'string'},
                      attributes=[{
                          'a': 'foo'
                      }])
        create_vector(filename=filename_b,
                      fields={'b': 'string'},
                      attributes=[{
                          'b': 'foo'
                      }])

        with self.assertRaises(AssertionError):
            assert_vectors_equal(filename_a, filename_b, 0.1)
コード例 #9
0
    def test_field_count_mismatch(self):
        """Assert we can catch when field counts don't match."""
        from pygeoprocessing.testing import assert_vectors_equal

        filename_a = os.path.join(self.workspace, 'foo')
        filename_b = os.path.join(self.workspace, 'bar')

        VectorTests.create_vector(fields={
            'a': 'string',
            'b': 'string'
        },
                                  attributes=[{
                                      'a': 'foo',
                                      'b': 'foo'
                                  }],
                                  filename=filename_a)
        VectorTests.create_vector(fields={'b': 'string'},
                                  attributes=[{
                                      'b': 'foo'
                                  }],
                                  filename=filename_b)

        with self.assertRaises(AssertionError):
            assert_vectors_equal(filename_a, filename_b, 0.1)