| 1 |
import copy |
| 2 |
import pickle |
| 3 |
|
| 4 |
import pycolmap |
| 5 |
|
| 6 |
# --- Tests on RANSACOptions (flat dataclass) --- |
| 7 |
|
| 8 |
|
| 9 |
def test_ransac_options_summary(): |
| 10 |
options = pycolmap.RANSACOptions() |
| 11 |
summary = options.summary() |
| 12 |
assert isinstance(summary, str) |
| 13 |
assert "RANSACOptions" in summary |
| 14 |
|
| 15 |
|
| 16 |
def test_ransac_options_summary_write_type(): |
| 17 |
options = pycolmap.RANSACOptions() |
| 18 |
summary = options.summary(write_type=True) |
| 19 |
assert isinstance(summary, str) |
| 20 |
assert "RANSACOptions" in summary |
| 21 |
|
| 22 |
|
| 23 |
def test_ransac_options_repr(): |
| 24 |
options = pycolmap.RANSACOptions() |
| 25 |
representation = repr(options) |
| 26 |
assert isinstance(representation, str) |
| 27 |
assert len(representation) > 0 |
| 28 |
|
| 29 |
|
| 30 |
def test_ransac_options_todict(): |
| 31 |
options = pycolmap.RANSACOptions() |
| 32 |
dictionary = options.todict() |
| 33 |
assert isinstance(dictionary, dict) |
| 34 |
assert "max_error" in dictionary |
| 35 |
assert "confidence" in dictionary |
| 36 |
|
| 37 |
|
| 38 |
def test_ransac_options_todict_recursive(): |
| 39 |
options = pycolmap.RANSACOptions() |
| 40 |
dictionary = options.todict(recursive=True) |
| 41 |
assert isinstance(dictionary, dict) |
| 42 |
assert "max_error" in dictionary |
| 43 |
|
| 44 |
|
| 45 |
def test_ransac_options_mergedict(): |
| 46 |
options = pycolmap.RANSACOptions() |
| 47 |
options.mergedict({"max_error": 12.0, "confidence": 0.99}) |
| 48 |
assert options.max_error == 12.0 |
| 49 |
assert options.confidence == 0.99 |
| 50 |
|
| 51 |
|
| 52 |
def test_ransac_options_copy(): |
| 53 |
options = pycolmap.RANSACOptions() |
| 54 |
options.max_error = 7.5 |
| 55 |
copied = copy.copy(options) |
| 56 |
assert copied.max_error == 7.5 |
| 57 |
assert copied is not options |
| 58 |
|
| 59 |
|
| 60 |
def test_ransac_options_deepcopy(): |
| 61 |
options = pycolmap.RANSACOptions() |
| 62 |
options.max_error = 3.3 |
| 63 |
deep = copy.deepcopy(options) |
| 64 |
assert deep.max_error == 3.3 |
| 65 |
assert deep is not options |
| 66 |
|
| 67 |
|
| 68 |
def test_ransac_options_eq(): |
| 69 |
options_a = pycolmap.RANSACOptions() |
| 70 |
options_b = pycolmap.RANSACOptions() |
| 71 |
assert options_a == options_b |
| 72 |
options_b.max_error = 999.0 |
| 73 |
assert options_a != options_b |
| 74 |
|
| 75 |
|
| 76 |
def test_ransac_options_pickle_roundtrip(): |
| 77 |
options = pycolmap.RANSACOptions() |
| 78 |
options.max_error = 5.5 |
| 79 |
options.confidence = 0.95 |
| 80 |
data = pickle.dumps(options) |
| 81 |
restored = pickle.loads(data) |
| 82 |
assert restored.max_error == 5.5 |
| 83 |
assert restored.confidence == 0.95 |
| 84 |
|
| 85 |
|
| 86 |
def test_ransac_options_dict_constructor(): |
| 87 |
options = pycolmap.RANSACOptions({"max_error": 11.0, "confidence": 0.98}) |
| 88 |
assert options.max_error == 11.0 |
| 89 |
assert options.confidence == 0.98 |
| 90 |
|
| 91 |
|
| 92 |
def test_ransac_options_kwargs_constructor(): |
| 93 |
options = pycolmap.RANSACOptions(max_error=22.0, min_num_trials=200) |
| 94 |
assert options.max_error == 22.0 |
| 95 |
assert options.min_num_trials == 200 |
| 96 |
|
| 97 |
|
| 98 |
# --- Tests on IncrementalPipelineOptions (nested dataclass) --- |
| 99 |
|
| 100 |
|
| 101 |
def test_incremental_pipeline_options_todict_recursive(): |
| 102 |
options = pycolmap.IncrementalPipelineOptions() |
| 103 |
dictionary = options.todict(recursive=True) |
| 104 |
assert isinstance(dictionary, dict) |
| 105 |
assert "min_num_matches" in dictionary |
| 106 |
|
| 107 |
|
| 108 |
def test_incremental_pipeline_options_mergedict(): |
| 109 |
options = pycolmap.IncrementalPipelineOptions() |
| 110 |
options.mergedict({"min_num_matches": 30}) |
| 111 |
assert options.min_num_matches == 30 |
| 112 |
|
| 113 |
|
| 114 |
def test_incremental_pipeline_options_summary(): |
| 115 |
options = pycolmap.IncrementalPipelineOptions() |
| 116 |
summary = options.summary() |
| 117 |
assert isinstance(summary, str) |
| 118 |
assert "IncrementalPipelineOptions" in summary |
| 119 |
|
| 120 |
|
| 121 |
def test_incremental_pipeline_options_pickle(): |
| 122 |
options = pycolmap.IncrementalPipelineOptions() |
| 123 |
options.min_num_matches = 42 |
| 124 |
data = pickle.dumps(options) |
| 125 |
restored = pickle.loads(data) |
| 126 |
assert restored.min_num_matches == 42 |
| 127 |
|
| 128 |
|
| 129 |
# --- Tests on Rigid3d --- |
| 130 |
|
| 131 |
|
| 132 |
def test_rigid3d_summary(): |
| 133 |
rigid = pycolmap.Rigid3d() |
| 134 |
summary = rigid.summary() |
| 135 |
assert isinstance(summary, str) |
| 136 |
assert "Rigid3d" in summary |
| 137 |
|
| 138 |
|
| 139 |
def test_rigid3d_todict(): |
| 140 |
rigid = pycolmap.Rigid3d() |
| 141 |
dictionary = rigid.todict() |
| 142 |
assert isinstance(dictionary, dict) |
| 143 |
|
| 144 |
|
| 145 |
def test_rigid3d_pickle_roundtrip(): |
| 146 |
rigid = pycolmap.Rigid3d() |
| 147 |
data = pickle.dumps(rigid) |
| 148 |
restored = pickle.loads(data) |
| 149 |
assert isinstance(restored, pycolmap.Rigid3d) |
| 150 |
assert restored == rigid |