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')
示例#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')
示例#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')
示例#4
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')
示例#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'
示例#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'
示例#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')
示例#8
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')
示例#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')
示例#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'
示例#11
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')
示例#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')
示例#13
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')

        should_raise(test_something)()

        compare(sample1.z(),'original z')
示例#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')
示例#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()
示例#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'
示例#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')
示例#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')
示例#19
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')
示例#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')
示例#21
0
 def test_something():
     compare(sample1.z(), 'replacement z')
     raise Exception()
示例#22
0
 def test_something():
     compare(sample1.z(), 'test z')
     compare(sample2.z(), 'original z')
示例#23
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')
示例#24
0
 def test_something():
     compare(sample1.z(),'test z')
     compare(sample2.z(),'original z')
示例#25
0
 def test_something():
     compare(sample1.z(), 'replacement z')
示例#26
0
 def test_something():
     compare(sample1.z(),'replacement z')
     raise Exception()
示例#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')
示例#28
0
 def test_something():
     compare(sample1.z(), 'replacement z')