Debian Codegraph @

src/pycolmap/util/cancellation_test.py

raw
1 import pytest
2
3 import pycolmap
4
5
6 def test_cancellation_token():
7 token = pycolmap.CancellationToken()
8 assert not token.is_cancelled
9 token.cancel()
10 assert token.is_cancelled
11
12
13 def test_cancelled_feature_extraction_raises(tmp_path):
14 image_path = tmp_path / "images"
15 image_path.mkdir()
16 token = pycolmap.CancellationToken()
17 token.cancel()
18
19 with pytest.raises(InterruptedError):
20 pycolmap.extract_features(
21 tmp_path / "database.db",
22 image_path,
23 device=pycolmap.Device.cpu,
24 cancellation_token=token,
25 )
26
27
28 def test_cancelled_bundle_adjustment_raises():
29 options = pycolmap.SyntheticDatasetOptions()
30 options.num_cameras_per_rig = 1
31 options.num_frames_per_rig = 3
32 options.num_points3D = 50
33 reconstruction = pycolmap.synthesize_dataset(options)
34 token = pycolmap.CancellationToken()
35 token.cancel()
36
37 with pytest.raises(InterruptedError):
38 pycolmap.bundle_adjustment(reconstruction, cancellation_token=token)
39
40
41 @pytest.mark.parametrize(
42 "function_name",
43 [
44 "bundle_adjustment",
45 "stereo_fusion",
46 "triangulate_points",
47 "undistort_images",
48 ],
49 )
50 def test_pipeline_accepts_cancellation_token(function_name):
51 assert "cancellation_token" in getattr(pycolmap, function_name).__doc__