(tmp_path)
| 19 | |
| 20 | |
| 21 | def test_algorithm(tmp_path): |
| 22 | reg = gdal.GetGlobalAlgorithmRegistry() |
| 23 | |
| 24 | names = reg.GetAlgNames() |
| 25 | assert isinstance(names, list) |
| 26 | assert "raster" in names |
| 27 | |
| 28 | alg = reg.InstantiateAlg("non_existing") |
| 29 | assert alg is None |
| 30 | |
| 31 | with pytest.raises(Exception, match="NULL"): |
| 32 | reg.InstantiateAlg(None) |
| 33 | |
| 34 | alg = reg.InstantiateAlg("raster") |
| 35 | assert alg |
| 36 | |
| 37 | assert alg.GetName() == "raster" |
| 38 | assert alg.GetDescription() == "Raster commands." |
| 39 | assert alg.GetLongDescription() == "" |
| 40 | assert alg.GetHelpFullURL() == "https://gdal.org/programs/gdal_raster.html" |
| 41 | |
| 42 | assert alg.HasSubAlgorithms() |
| 43 | |
| 44 | with pytest.raises(Exception, match="NULL"): |
| 45 | alg.InstantiateSubAlgorithm(None) |
| 46 | assert alg.InstantiateSubAlgorithm("non_existing") is None |
| 47 | |
| 48 | subalgs = alg.GetSubAlgorithmNames() |
| 49 | assert isinstance(subalgs, list) |
| 50 | assert "info" in subalgs |
| 51 | |
| 52 | convert = alg.InstantiateSubAlgorithm("convert") |
| 53 | assert convert |
| 54 | |
| 55 | assert json.loads(convert.GetUsageAsJSON())["name"] == "convert" |
| 56 | |
| 57 | outfilename = str(tmp_path / "out.tif") |
| 58 | assert convert.ParseCommandLineArguments(["data/byte.tif", outfilename]) |
| 59 | |
| 60 | last_pct = [0] |
| 61 | |
| 62 | def my_progress(pct, msg, user_data): |
| 63 | last_pct[0] = pct |
| 64 | return True |
| 65 | |
| 66 | assert convert.Run(my_progress) |
| 67 | assert last_pct[0] == 1.0 |
| 68 | |
| 69 | assert convert.Finalize() |
| 70 | |
| 71 | with gdal.Open(outfilename) as ds: |
| 72 | assert ds.GetRasterBand(1).Checksum() == 4672 |
| 73 | |
| 74 | gdal.Unlink(outfilename) |
| 75 | |
| 76 | last_pct = [0] |
| 77 | |
| 78 | convert = alg.InstantiateSubAlgorithm("convert") |
nothing calls this directly
no test coverage detected