From 51cda271643a8aa70b4e86f0d32ce0f6b9048553 Mon Sep 17 00:00:00 2001 From: Antoine Lavenant Date: Wed, 25 Sep 2024 11:45:14 +0200 Subject: [PATCH] refacto test --- pdaltools/_version.py | 2 +- test/test_standardize_format.py | 45 +++++++++++++++------------------ 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/pdaltools/_version.py b/pdaltools/_version.py index 31890a2..d868670 100644 --- a/pdaltools/_version.py +++ b/pdaltools/_version.py @@ -1,4 +1,4 @@ -__version__ = "1.7.4" +__version__ = "1.7.3" if __name__ == "__main__": diff --git a/test/test_standardize_format.py b/test/test_standardize_format.py index 663f83a..75ff8c4 100644 --- a/test/test_standardize_format.py +++ b/test/test_standardize_format.py @@ -119,6 +119,22 @@ def test_standardize_malformed_laz(): assert os.path.isfile(output_file) +def get_pipeline_metadata_cross_plateform(pipeline): + try: + metadata = json.loads(pipeline.metadata) + except TypeError: + d_metadata = json.dumps(pipeline.metadata) + metadata = json.loads(d_metadata) + return metadata + +def get_statistics_from_las_points(points): + pipeline = pdal.Pipeline(arrays=[points]) + pipeline |= pdal.Filter.stats(dimensions="Classification", enumerate="Classification") + pipeline.execute() + metadata = get_pipeline_metadata_cross_plateform(pipeline) + statistic = metadata["metadata"]["filters.stats"]["statistic"] + return statistic[0]["count"], statistic[0]["values"] + @pytest.mark.parametrize( "classes_to_remove", [ @@ -131,36 +147,17 @@ def test_remove_points_from_class(classes_to_remove): input_file = os.path.join(TEST_PATH, "data/classified_laz/test_data_77050_627755_LA93_IGN69.laz") output_file = os.path.join(TMP_PATH, "test_remove_points_from_class.laz") - def get_pipeline_metadata(pipeline): - try: - metadata = json.loads(pipeline.metadata) - except TypeError: - d_metadata = json.dumps(pipeline.metadata) - metadata = json.loads(d_metadata) - return metadata - - def get_statistics(points): - pipeline = pdal.Pipeline(arrays=[points]) - pipeline |= pdal.Filter.stats(dimensions="Classification", enumerate="Classification") - pipeline.execute() - metadata = get_pipeline_metadata(pipeline) - statistic = metadata["metadata"]["filters.stats"]["statistic"] - return statistic[0]["count"], statistic[0]["values"] - # count points of class not in classes_to_remove (get the point we should have in fine) pipeline = pdal.Pipeline() | pdal.Reader.las(input_file) - where = "" - for cl in classes_to_remove: - where += "Classification != " + str(cl) - if cl != classes_to_remove[-1]: - where += " && " + + where = ' && '.join(["CLassification != " + str(cl) for cl in classes_to_remove]) pipeline |= pdal.Filter.stats(dimensions="Classification", enumerate="Classification", where=where) pipeline.execute() points = pipeline.arrays[0] - nb_points_before, class_before = get_statistics(points) + nb_points_before, class_before = get_statistics_from_las_points(points) - metadata = get_pipeline_metadata(pipeline) + metadata = get_pipeline_metadata_cross_plateform(pipeline) statistic = metadata["metadata"]["filters.stats"]["statistic"] nb_points_to_get = statistic[0]["count"] @@ -170,7 +167,7 @@ def get_statistics(points): assert nb_points_to_get == 0 return - nb_points_after, class_after = get_statistics(points) + nb_points_after, class_after = get_statistics_from_las_points(points) assert nb_points_before > 0 assert nb_points_before > nb_points_after