Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when trying to Stub os.path.exists #7

Open
sk- opened this issue Feb 9, 2012 · 2 comments
Open

Bug when trying to Stub os.path.exists #7

sk- opened this issue Feb 9, 2012 · 2 comments

Comments

@sk-
Copy link

sk- commented Feb 9, 2012

Please see the test below. The first test fails with an infinite recursion and the second works just great.

import os
from unittest import TestCase

from ludibrio import Stub, any

class TestStubReplacesStdlib(TestCase):
    def test_os_path_exist_bug(self):
        with Stub() as exists:
            from os.path import exists
            exists(any()) >> True
        self.assertTrue(os.path.exists('/path/to/inexistent/file'))
        exists.restore_import()

    def test_stub_replacement_success(self):
        with Stub() as getsize:
            from os.path import getsize
            getsize(any()) >> 1
        self.assertEquals(os.path.getsize('/path/to/inexistent/file'), 1)
        getsize.restore_import()
@sk-
Copy link
Author

sk- commented Feb 11, 2012

I found the cause of this issue. The problem is that the method of Stub _property_called_name relies on getframeinfo of module inspect. This module relies also on function os.path.exists. So when the replace of exists is made affects all the flow.

My suggestion would be to not call _replace_all for modules like ludibrio or inspect (a more finer exception could be made). I would be happy to provide the patch, but I'd definitely need some guidance, because I tried some patches and somehow I lost the Stub for the exists method. (i.e, after the import the exists is no longer a Stub but a function)

@wyuenho
Copy link

wyuenho commented Apr 3, 2012

I bumped into this issue too. Is there a fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants