import numpy as np
from mock import Mock

from menpo.transform import Transform


x = np.zeros([5, 5])


class MockTransform(Transform):
    def _apply(self, x, **kwargs):
        return x


def transform_n_dims_return_None_test():
    tr = MockTransform()
    n_dims = tr.n_dims
    assert (n_dims is None)


def transform_n_dims_output_return_None_test():
    tr = MockTransform()
    n_dims = tr.n_dims_output
    assert (n_dims is None)


def transform_apply_x_transformable_test():
    mocked = Mock(**{'_transform.return_value': x})
    tr = MockTransform()
    new_x = tr.apply(mocked)

    assert (new_x is x)
    assert mocked._transform.called


def transform_compose_before_test():
    mocked = Mock(**{'_apply.return_value': x})
    tr = MockTransform()
    chain = tr.compose_before(mocked)
    # Check transform chain
    assert (len(chain.transforms) == 2)
    assert (chain.transforms[0] is tr)
    assert (chain.transforms[1] is mocked)
    # Apply transform chain
    result = chain.apply(x)
    assert (result is x)
    assert mocked._apply.called


def transform_compose_after_test():
    mocked = Mock(**{'_apply.return_value': x})
    tr = MockTransform()
    chain = tr.compose_after(mocked)
    # Check transform chain
    assert (len(chain.transforms) == 2)
    assert (chain.transforms[0] is mocked)
    assert (chain.transforms[1] is tr)
    # Apply transform chain
    result = chain.apply(x)
    assert (result is x)
    assert mocked._apply.called

@@ -12,16 +12,58 @@
 y as np%0A
+from numpy.testing import assert_allclose%0A
 from moc
@@ -222,17 +222,27 @@
  return 
-x
+np.array(x)
 %0A%0A%0Adef t
@@ -480,32 +480,190 @@
 dims is None)%0A%0A%0A
+def transform_apply_x_not_transformable_test():%0A    tr = MockTransform()%0A    new_x = tr.apply(x)%0A%0A    assert (new_x is not x)%0A    assert_allclose(new_x, x)%0A%0A%0A
 def transform_ap
@@ -708,20 +708,29 @@
  = Mock(
-**%7B'
+)%0A    mocked.
 _transfo
@@ -736,38 +736,41 @@
 orm.return_value
-': x%7D)
+ = mocked
 %0A    tr = MockTr
@@ -775,37 +775,48 @@
 Transform()%0A    
-new_x
+transformed_mock
  = tr.apply(mock
@@ -836,18 +836,294 @@
 rt (
-new_x is x
+transformed_mock is mocked)%0A    assert mocked._transform.called%0A%0A%0Adef transform_apply_inplace_x_transformable_test():%0A    mocked = Mock()%0A    mocked._transform_inplace.return_value = mocked%0A    tr = MockTransform()%0A    no_return = tr.apply_inplace(mocked)%0A%0A    assert (no_return is None
 )%0A  
@@ -1140,32 +1140,40 @@
 ocked._transform
+_inplace
 .called%0A%0A%0Adef tr
@@ -1158,32 +1158,221 @@
 nplace.called%0A%0A%0A
+def transform_apply_inplace_x_not_transformable_test():%0A    tr = MockTransform()%0A    x_ref = x%0A    no_return = tr.apply_inplace(x)%0A%0A    assert (no_return is None)%0A    assert (x_ref is x)%0A%0A%0A
 def transform_co
@@ -1402,36 +1402,45 @@
   mocked = Mock(
-**%7B'
+)%0A    mocked.
 _apply.return_va
@@ -1434,38 +1434,36 @@
 ply.return_value
-': x%7D)
+ = x
 %0A    tr = MockTr
@@ -1664,121 +1664,8 @@
 ed)%0A
-    # Apply transform chain%0A    result = chain.apply(x)%0A    assert (result is x)%0A    assert mocked._apply.called%0A
 %0A%0Ade
@@ -1720,12 +1720,21 @@
 ock(
-**%7B'
+)%0A    mocked.
 _app
@@ -1752,14 +1752,12 @@
 alue
-': x%7D)
+ = x
 %0A   
@@ -1969,117 +1969,5 @@
 tr)%0A
-    # Apply transform chain%0A    result = chain.apply(x)%0A    assert (result is x)%0A    assert mocked._apply.called
 %0A

Use mock a lot better