7. Processing Algorithms Testing
7.1. アルゴリズムのテスト
注釈
The original version of these instructions is available at https://github.com/qgis/QGIS/blob/release-3_22/python/plugins/processing/tests/README.md
QGISでは、プロセッシングフレームワークの下にいくつかのアルゴリズムを提供しています。このリストは独自のアルゴリズムで拡張できます。そして新しい機能と同様、テストを追加することが必要です。
To test algorithms you can add entries into testdata/qgis_algorithm_tests.yaml
or testdata/gdal_algorithm_tests.yaml as appropriate.
This file is structured with yaml syntax.
A basic test appears under the top level key tests and looks like this:
- name: centroid
algorithm: qgis:polygoncentroids
params:
- type: vector
name: polys.gml
results:
OUTPUT_LAYER:
type: vector
name: expected/polys_centroid.gml
7.1.1. How To
To add a new test please follow these steps:
プロセッシングツールボックス からQGISでテストしたい アルゴリズム を実行します。結果がベクタレイヤの場合、混合ジオメトリタイプと優れた読みやすさのサポートの出力として、XSDを備えたGMLを優先します。出力を
python/plugins/processing/tests/testdata/expectedにリダイレクトします。入力レイヤには、フォルダtestdataに既にあるものを優先的に使用します。追加のデータが必要な場合は、それをtestdata/customに入れてください。When you have run the algorithm, go to and find the algorithm which you have just run.
Right click the algorithm and click Create Test. A new window will open with a text definition.
Open the file
python/plugins/processing/tests/testdata/algorithm_tests.yaml, copy the text definition there.
The first string from the command goes to the key algorithm, the subsequent
ones to params and the last one(s) to results.
The above translates to
- name: densify
algorithm: qgis:densifygeometriesgivenaninterval
params:
- type: vector
name: polys.gml
- 2 # Interval
results:
OUTPUT:
type: vector
name: expected/polys_densify.gml
処理スクリプトのテストを作成することもできます。スクリプトは、テストデータのディレクトリ python/plugins/processing/tests/testdata/ の scripts サブディレクトリに配置する必要があります。スクリプトファイル名は、スクリプトアルゴリズム名と一致する必要があります。
7.1.2. Parameters and results
Trivial type parameters
パラメータと結果はリストまたは辞書として指定されます:
params:
INTERVAL: 5
INTERPOLATE: True
NAME: A processing test
or
params:
- 2
- string
- another param
Layer type parameters
多くの場合、レイヤをパラメータとして指定する必要があるでしょう。レイヤを指定するには、次を指定する必要があります:
種類、すなわち
vectorまたはrastera name, with a relative path like
expected/polys_centroid.gml
This is what it looks like in action:
params:
PAR: 2
STR: string
LAYER:
type: vector
name: polys.gml
OTHER: another param
File type parameters
アルゴリズムのテストに外部ファイルが必要な場合は、「ファイル」タイプと「名前」でファイルへの(相対)パスを指定する必要があります。
params:
PAR: 2
STR: string
EXTFILE:
type: file
name: custom/grass7/extfile.txt
OTHER: another param
結果
Results are specified very similarly.
Basic vector files
It couldn't be more trivial
OUTPUT:
name: expected/qgis_intersection.gml
type: vector
Add the expected GML and XSD files in the folder.
Vector with tolerance
プラットフォームによって、わずかに異なる結果が作成される場合がありますが、それでも依然として許容範囲です。この場合(ただしその場合のみ)、追加のプロパティを使用して、レイヤーの比較方法を定義することもできます。
出力値の特定の許容範囲を処理するために、出力に 比較 プロパティを指定できます。この比較プロパティには、「フィールド」のサブプロパティを含めることができます。これには、特定のフィールドがどの程度正確に比較されるか(「精度」)、またはフィールドを完全に「スキップ」することもできます。すべてのフィールドに特定の許容値を適用する特別なフィールド名 __all__ があります。別に、各頂点に適用される「精度」も受け入れるプロパティ「ジオメトリ」があります。
OUTPUT:
type: vector
name: expected/abcd.gml
compare:
fields:
__all__:
precision: 5 # compare to a precision of .00001 on all fields
A: skip # skip field A
geometry:
precision: 5 # compare coordinates with a precision of 5 digits
Raster files
ラスタファイルはハッシュチェックサムと比較されます。これは、プロセッシングの履歴からテストを作成するときに計算されます。
OUTPUT:
type: rasterhash
hash: f1fedeb6782f9389cf43590d4c85ada9155ab61fef6dc285aaeb54d6
Files
出力ファイルの内容を予想される結果参照ファイルと比較できます
OUTPUT_HTML_FILE:
name: expected/basic_statistics_string.html
type: file
Or you can use one or more regular expressions that will be matched against the file content
OUTPUT:
name: layer_info.html
type: regex
rules:
- 'Extent: \(-1.000000, -3.000000\) - \(11.000000, 5.000000\)'
- 'Geometry: Line String'
- 'Feature Count: 6'
Directories
You can compare the content of an output directory with an expected result reference directory
OUTPUT_DIR:
name: expected/tiles_xyz/test_1
type: directory
7.1.3. アルゴリズムのコンテキスト
アルゴリズムのコンテキストを変更できる定義がいくつかあります。これらはテストの最上位で指定できます:
project- will load a specified QGIS project file before running the algorithm. If not specified, the algorithm will run with an empty projectproject_crs- overrides the default project CRS - e.g.EPSG:27700ellipsoid- overrides the default project ellipsoid used for measurements, e.g.GRS80
7.1.4. Running tests locally
ctest -V -R ProcessingQgisAlgorithmsTest
or one of the following values listed in the CMakelists.txt