def test_multiple_replace(self):

        def test_y(self):
            return 'test y'

        def test_z():
            return 'test z'

        compare(sample1.z(),'original z')
        compare(sample1.X().y(),'original y')

        @replace('testfixtures.tests.sample1.z',test_z)
        @replace('testfixtures.tests.sample1.X.y',test_y)
        def test_something(passed_test_y,passed_test_z):
            compare(test_z,passed_test_z)
            compare(test_y,passed_test_y)
            compare(sample1.z(),'test z')
            compare(sample1.X().y(),'test y')

        compare(sample1.z(),'original z')
        compare(sample1.X().y(),'original y')

        test_something()

        compare(sample1.z(),'original z')
        compare(sample1.X().y(),'original y')
Exemple #2
0
    def test_multiple_replace(self):
        def test_y(self):
            return 'test y'

        def test_z():
            return 'test z'

        compare(sample1.z(), 'original z')
        compare(sample1.X().y(), 'original y')

        @replace('testfixtures.tests.sample1.z', test_z)
        @replace('testfixtures.tests.sample1.X.y', test_y)
        def test_something(passed_test_y, passed_test_z):
            compare(test_z, passed_test_z)
            compare(test_y, passed_test_y)
            compare(sample1.z(), 'test z')
            compare(sample1.X().y(), 'test y')

        compare(sample1.z(), 'original z')
        compare(sample1.X().y(), 'original y')

        test_something()

        compare(sample1.z(), 'original z')
        compare(sample1.X().y(), 'original y')
Exemple #3
0
    def test_replace_context_manager(self):
        def test_z():
            return 'replacement z'

        compare(sample1.z(), 'original z')

        with Replace('testfixtures.tests.sample1.z', test_z) as z:
            compare(z(), 'replacement z')
            compare(sample1.z(), 'replacement z')

        compare(sample1.z(), 'original z')
    def test_replace_context_manager(self):
        def test_z():
            return 'replacement z'

        compare(sample1.z(), 'original z')

        with Replace('testfixtures.tests.sample1.z', test_z) as z:
            compare(z(), 'replacement z')
            compare(sample1.z(), 'replacement z')

        compare(sample1.z(), 'original z')
Exemple #5
0
    def test_with_statement(self):
        from testfixtures.tests import sample1
        assert sample1.z() == 'original z'

        def test_z():
          return 'replacement z'

        with Replacer() as r:
            r.replace('testfixtures.tests.sample1.z',test_z)
            assert sample1.z() == 'replacement z'

        assert sample1.z() == 'original z'
Exemple #6
0
    def test_remove_called_twice(self):
        from testfixtures.tests import sample1

        def test_z(): pass

        r = Replacer()
        r.replace('testfixtures.tests.sample1.z',test_z)

        r.restore()
        assert sample1.z() == 'original z'

        r.restore()
        assert sample1.z() == 'original z'
Exemple #7
0
    def test_use_as_cleanup(self):
        def test_z():
            return 'replacement z'

        compare(sample1.z(), 'original z')
        replace = Replacer()
        compare(sample1.z(), 'original z')
        replace('testfixtures.tests.sample1.z', test_z)
        cleanup = replace.restore
        try:
            compare(sample1.z(), 'replacement z')
        finally:
            cleanup()
        compare(sample1.z(), 'original z')
    def test_use_as_cleanup(self):
        def test_z():
            return 'replacement z'

        compare(sample1.z(), 'original z')
        replace = Replacer()
        compare(sample1.z(), 'original z')
        replace('testfixtures.tests.sample1.z', test_z)
        cleanup = replace.restore
        try:
            compare(sample1.z(), 'replacement z')
        finally:
            cleanup()
        compare(sample1.z(), 'original z')
Exemple #9
0
    def test_function(self):

        def test_z():
            return 'replacement z'

        compare(sample1.z(), 'original z')

        @replace('testfixtures.tests.sample1.z', test_z)
        def test_something():
            compare(sample1.z(), 'replacement z')

        compare(sample1.z(), 'original z')
        test_something()
        compare(sample1.z(), 'original z')
Exemple #10
0
    def test_function(self):
        from testfixtures.tests import sample1
        assert sample1.z() == 'original z'

        def test_z():
          return 'replacement z'

        r = Replacer()
        r.replace('testfixtures.tests.sample1.z',test_z)

        assert sample1.z() == 'replacement z'

        r.restore()

        assert sample1.z() == 'original z'
    def test_function(self):

        def test_z():
            return 'replacement z'

        compare(sample1.z(), 'original z')

        @replace('testfixtures.tests.sample1.z',test_z)
        def test_something():
            compare(sample1.z(), 'replacement z')

        compare(sample1.z(), 'original z')

        test_something()

        compare(sample1.z(), 'original z')
Exemple #12
0
    def test_raises(self):

        def test_z():
            return 'replacement z'

        compare(sample1.z(), 'original z')

        @replace('testfixtures.tests.sample1.z', test_z)
        def test_something():
            compare(sample1.z(), 'replacement z')
            raise Exception()

        compare(sample1.z(), 'original z')
        with ShouldRaise():
            test_something()
        compare(sample1.z(), 'original z')
    def test_raises(self):

        def test_z():
            return 'replacement z'

        compare(sample1.z(),'original z')

        @replace('testfixtures.tests.sample1.z',test_z)
        def test_something():
            compare(sample1.z(),'replacement z')
            raise Exception()

        compare(sample1.z(),'original z')

        should_raise(test_something)()

        compare(sample1.z(),'original z')
Exemple #14
0
    def test_gotcha(self):

        def test_z():
            return 'test z'

        compare(sample1.z(), 'original z')
        compare(sample2.z(), 'original z')

        @replace('testfixtures.tests.sample1.z', test_z)
        def test_something():
            compare(sample1.z(), 'test z')
            compare(sample2.z(), 'original z')

        compare(sample1.z(), 'original z')
        compare(sample2.z(), 'original z')
        test_something()
        compare(sample1.z(), 'original z')
        compare(sample2.z(), 'original z')
Exemple #15
0
    def test_gotcha(self):
        # Just because you replace an object in one context:

        from testfixtures.tests import sample1
        from testfixtures.tests import sample2
        assert sample1.z() == 'original z'

        def test_z():
          return 'replacement z'

        r = Replacer()
        r.replace('testfixtures.tests.sample1.z',test_z)

        assert sample1.z() == 'replacement z'

        # Doesn't meant that it's replaced in all contexts:

        assert sample2.z() == 'original z'

        r.restore()
Exemple #16
0
    def test_multiple_replace(self):
        from testfixtures.tests import sample1
        assert sample1.z() == 'original z'
        assert sample1.X().y() == 'original y'

        def test_y(self):
          return self.__class__.__name__
        def test_z():
          return 'replacement z'

        r = Replacer()
        r.replace('testfixtures.tests.sample1.z',test_z)
        r.replace('testfixtures.tests.sample1.X.y',test_y)

        assert sample1.z() == 'replacement z'
        assert sample1.X().y() == 'X'

        r.restore()

        assert sample1.z() == 'original z'
        assert sample1.X().y() == 'original y'
Exemple #17
0
    def test_multiple_context_managers(self):
        def test_y(self):
            return 'test y'

        def test_z():
            return 'test z'

        compare(sample1.z(), 'original z')
        compare(sample1.X().y(), 'original y')

        with Replacer() as replace:
            z = replace('testfixtures.tests.sample1.z', test_z)
            y = replace('testfixtures.tests.sample1.X.y', test_y)
            compare(z(), 'test z')
            if PY3:
                compare(y, sample1.X.y)
            compare(sample1.X().y(), 'test y')
            compare(sample1.z(), 'test z')
            compare(sample1.X().y(), 'test y')

        compare(sample1.z(), 'original z')
        compare(sample1.X().y(), 'original y')
Exemple #18
0
    def test_gotcha(self):
        # Just because you replace an object in one context,
        # doesn't meant that it's replaced in all contexts!

        def test_z():
            return 'test z'

        compare(sample1.z(), 'original z')
        compare(sample2.z(), 'original z')

        @replace('testfixtures.tests.sample1.z', test_z)
        def test_something():
            compare(sample1.z(), 'test z')
            compare(sample2.z(), 'original z')

        compare(sample1.z(), 'original z')
        compare(sample2.z(), 'original z')

        test_something()

        compare(sample1.z(), 'original z')
        compare(sample2.z(), 'original z')
    def test_gotcha(self):
        # Just because you replace an object in one context,
        # doesn't meant that it's replaced in all contexts!

        def test_z():
            return 'test z'
        
        compare(sample1.z(),'original z')
        compare(sample2.z(),'original z')
        
        @replace('testfixtures.tests.sample1.z',test_z)
        def test_something():
            compare(sample1.z(),'test z')
            compare(sample2.z(),'original z')
            
        compare(sample1.z(),'original z')
        compare(sample2.z(),'original z')
    
        test_something()

        compare(sample1.z(),'original z')
        compare(sample2.z(),'original z')
Exemple #20
0
    def test_multiple_context_managers(self):

        def test_y(self):
            return 'test y'

        def test_z():
            return 'test z'

        compare(sample1.z(), 'original z')
        compare(sample1.X().y(), 'original y')

        with Replacer() as replace:
            z = replace('testfixtures.tests.sample1.z', test_z)
            y = replace('testfixtures.tests.sample1.X.y', test_y)
            compare(z(), 'test z')
            if PY3:
                compare(y, sample1.X.y)
            compare(sample1.X().y(), 'test y')
            compare(sample1.z(), 'test z')
            compare(sample1.X().y(), 'test y')

        compare(sample1.z(), 'original z')
        compare(sample1.X().y(), 'original y')
Exemple #21
0
 def test_something():
     compare(sample1.z(), 'replacement z')
     raise Exception()
Exemple #22
0
 def test_something():
     compare(sample1.z(), 'test z')
     compare(sample2.z(), 'original z')
 def test_something(passed_test_y,passed_test_z):
     compare(test_z,passed_test_z)
     compare(test_y,passed_test_y)
     compare(sample1.z(),'test z')
     compare(sample1.X().y(),'test y')
 def test_something():
     compare(sample1.z(),'test z')
     compare(sample2.z(),'original z')
Exemple #25
0
 def test_something():
     compare(sample1.z(), 'replacement z')
 def test_something():
     compare(sample1.z(),'replacement z')
     raise Exception()
Exemple #27
0
 def test_something(passed_test_y, passed_test_z):
     compare(test_z, passed_test_z)
     compare(test_y, passed_test_y)
     compare(sample1.z(), 'test z')
     compare(sample1.X().y(), 'test y')
 def test_something():
     compare(sample1.z(), 'replacement z')