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

DirExists and Not matchers produce poor feedback #227

Open
thomir opened this issue Apr 13, 2016 · 1 comment
Open

DirExists and Not matchers produce poor feedback #227

thomir opened this issue Apr 13, 2016 · 1 comment

Comments

@thomir
Copy link
Member

thomir commented Apr 13, 2016

I have a test that includes the following line:

self.expectThat(working_dir, Not(DirExists()))

When this assertion fails, the feedback I get isn't very readable:

'/tmp/tmpBNe_N9' matches MatchesAll(MatchesPredicate(<function exists at 0x7f0835277578>, '%s does not exist.'), MatchesPredicate(<function isdir at 0x7f0835277668>, '%s is not a directory.'))

This can be reproduced with the following:

>>> import os
>>> os.mkdir('/tmp/hello-testtools')
>>> from testtools.matchers import Not, DirExists
>>> matcher = Not(DirExists())
>>> mismatch = matcher.match('/tmp/hello-testtools')
>>> print(mismatch.describe())
'/tmp/hello-testtools' matches MatchesAll(MatchesPredicate(<function exists at 0x7f0835277578>, '%s does not exist.'), MatchesPredicate(<function isdir at 0x7f0835277668>, '%s is not a directory.'))

This is because DirExists is simply a function that returns an instance of MatchesAll:

def DirExists():
    """Matches if the path exists and is a directory."""
    return MatchesAll(
        PathExists(),
        MatchesPredicate(os.path.isdir, "%s is not a directory."),
        first_only=True)

and does not customize the __str__ method, which means we get the default MatchesAll str representation.

Being able to create new matcher types with a simple function is 'A Good Thing' (tm), but I wonder if we need a way to customise the __str__ representations of these new matchers.

Thoughts?

@rbtcollins
Copy link
Member

Sure, being able to curry up something more useful would be great.

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