<s> from mock import Mock <EOL> from nose . tools import raises <EOL> import numpy as np <EOL> from numpy . testing import assert_equal <EOL> from menpo . transform . base import Alignment <EOL> source_array = np . random . random ( [ <NUM_LIT:5> , <NUM_LIT:2> ] ) <EOL> target_array = np . random . random ( [ <NUM_LIT:5> , <NUM_LIT:2> ] ) <EOL> target_mismatch_array = np . random . random ( [ <NUM_LIT:8> , <NUM_LIT:2> ] ) <EOL> target_array_3d = np . random . random ( [ <NUM_LIT:5> , <NUM_LIT:3> ] ) <EOL> source = Mock ( points = source_array , n_dims = source_array . shape [ <NUM_LIT:1> ] , <EOL> n_points = source_array . shape [ <NUM_LIT:0> ] ) <EOL> target = Mock ( points = target_array , n_dims = target_array . shape [ <NUM_LIT:1> ] , <EOL> n_points = target_array . shape [ <NUM_LIT:0> ] ) <EOL> target_mismatch = Mock ( points = target_mismatch_array , <EOL> n_dims = target_mismatch_array . shape [ <NUM_LIT:1> ] , <EOL> n_points = target_mismatch_array . shape [ <NUM_LIT:0> ] ) <EOL> target_3d = Mock ( points = target_array_3d , n_dims = target_array_3d . shape [ <NUM_LIT:1> ] , <EOL> n_points = target_array_3d . shape [ <NUM_LIT:0> ] ) <EOL> class MockedAlignment ( Alignment ) : <EOL> def _sync_state_from_target ( self ) : <EOL> pass <EOL> def apply ( self , x ) : <EOL> return x <EOL> def alignment_init_test ( ) : <EOL> MockedAlignment ( source , target ) <EOL> @ raises ( ValueError ) <EOL> def alignment_init_n_dims_mismatch_test ( ) : <EOL> MockedAlignment ( source , target_3d ) <EOL> @ raises ( ValueError ) <EOL> def alignment_init_n_dims_mismatch_test ( ) : <EOL> MockedAlignment ( source , target_3d ) <EOL> @ raises ( ValueError ) <EOL> def alignment_init_n_points_mismatch_test ( ) : <EOL> MockedAlignment ( source , target_mismatch ) <EOL> def alignment_source_test ( ) : <EOL> al = MockedAlignment ( source , target ) <EOL> assert ( al . source is source ) <EOL> def alignment_target_test ( ) : <EOL> al = MockedAlignment ( source , target ) <EOL> assert ( al . target is target ) <EOL> def alignment_aligned_source_test ( ) : <EOL> al = MockedAlignment ( source , target ) <EOL> assert ( al . aligned_source ( ) is source ) <EOL> def alignment_alignment_error_test ( ) : <EOL> al = MockedAlignment ( source , target ) <EOL> error = al . alignment_error ( ) <EOL> assert_equal ( error , np . linalg . norm ( al . source . points - al . target . points ) ) <EOL> @ raises ( NotImplementedError ) <EOL> def alignment_view_non_2d_test ( ) : <EOL> al = MockedAlignment ( target_3d , target_3d ) <EOL> al . view ( ) </s>
