Skip to content

Make testing on non-Linux platforms easier #141

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

Merged
merged 4 commits into from
Dec 20, 2017
Merged

Conversation

tiran
Copy link
Member

@tiran tiran commented Dec 18, 2017

A bunch of small chances to the test suite. It should be enough to make it possible to run the test suite under macOS homebrew and Windows (untested).

  • Make LDAPI optional
  • Drop unused import of pwd module
  • Lookup test binaries in PATH

@tiran tiran force-pushed the nonunix branch 2 times, most recently from 9a5c5fc to 6e929f1 Compare December 18, 2017 08:27
@codecov
Copy link

codecov bot commented Dec 18, 2017

Codecov Report

Merging #141 into master will decrease coverage by <.01%.
The diff coverage is 68.88%.

@@            Coverage Diff             @@
##           master     #141      +/-   ##
==========================================
- Coverage   69.33%   69.33%   -0.01%     
==========================================
  Files          49       49              
  Lines        4654     4722      +68     
  Branches      782      802      +20     
==========================================
+ Hits         3227     3274      +47     
- Misses       1080     1093      +13     
- Partials      347      355       +8
Impacted Files Coverage Δ
Lib/slapdtest/__init__.py 100% <100%> (ø) ⬆️
Lib/ldap/compat.py 66.03% <47.05%> (-33.97%) ⬇️
Lib/slapdtest/_slapdtest.py 84.19% <81.48%> (+0.92%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ab93063...02915b3. Read the comment docs.

HAVE_LDAPI = False
else:
HAVE_LDAPI = hasattr(socket, 'AF_UNIX')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if, when CI is set, we only looked at CI_DISABLED? Maybe with an early error if LDAPI isn't disabled but socket.AF_UNIX is available.
And if CI is unset, do the hasattr check.

In this case, the hasattr is probably robust enough, but I think starting a "avoid feature detection if CI is set" pattern would be beneficial.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to run tests without LDAPI support locally, too. Can you recommend a better way to pass an option from tox without introducing more env vars?

We could move to pytest in order to use proper fixtures and options. But I don't like to do that now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misunderstood the code. Sorry for the noise!

slapd_args = [
self.PATH_SLAPD,
'-f', self._slapd_conf,
'-F', self.testrundir,
'-h', '%s' % ' '.join((self.ldap_uri, self.ldapi_uri)),
'-h', '%s' % ' '.join(urls),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The % interpolation looks unnecessary here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

return name
return None


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too, I feel it would be nice to avoid auto-discovery if CI is set.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by auto-detection here? _which simply looks through PATH.

cmd = name[5:].lower()
raise ValueError(
"Command '{}' not found in PATH".format(cmd)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So … commands are defined by being prefixed by PATH_?
That looks like avoidable magic. I think it would be better to have the explicit list and just add a comment to remind people about synchronization, or to turn _which into something that registers the command as well as finding it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old list of file names doesn't result in good UX because _which returns None when it can't find a command. An error message like command None not found isn't very helpful. What do you suggest?

@encukou
Copy link
Member

encukou commented Dec 18, 2017

Should we turn on macOS on Travis, as well?

LDAPI is LDAP over Unix Domain Socket, also referred as LDAP IPC.
AF_UNIX is only supported on POSIX compatible operating systems. Don't
bind to LDAPI socket and skip LDAPI specific tests, e.g. SASL EXTERNAL
with SO_PEERCRED.

Signed-off-by: Christian Heimes <cheimes@redhat.com>
Signed-off-by: Christian Heimes <cheimes@redhat.com>
Instead of hard-coded paths /usr/bin and /usr/sbin, the SlapdObject test
helper now uses PATH env var to find test binaries. For slapd server
binary, sbin paths are automatically added to lookup PATH in case they
are missing.

Signed-off-by: Christian Heimes <cheimes@redhat.com>
Make SlapdObject.PATH_* instance attributes, rather than class
ones. Set them in __init__.
Move checking them from start() to __init__(), so the check becomes
simply error handling.

Put a straight-up copy of Python's shutil.which() in
ldap.compat -- it is a temporary backport, not a modified fork.
@encukou
Copy link
Member

encukou commented Dec 19, 2017

Here is my suggestion: do both the which() and the error handling from __init__, rather than at the class level and from start(). This should be fine: we don't really care about the performance hit of finding paths for each instance, and the whole class is useless if start() fails, so no harm in raising errors already in __init__.

I also made which() clearly a backport, not a modified fork.

@tiran
Copy link
Member Author

tiran commented Dec 19, 2017

+1 for which()

But I don't like the sbin code. It's too complicated. Should we really care where a command is located as long as it's found in a standard bin dir? I also don't like SLAPD, BINDIR and SBINDIR env vars. They are hacks that are no longer required with which.

@encukou
Copy link
Member

encukou commented Dec 19, 2017

I agree they're too complicated. However, since 2.4.36, slapdtest is a top-level module for general use, rather than an internal python-ldap helper. I consider the env vars to be its public API. So, I don't want to drop them in 3.0.

It might make sense to deprecate slapdtest as a general tool, and later make it an internal test helper again.

@encukou encukou added this to the 3.0 milestone Dec 19, 2017
@tiran
Copy link
Member Author

tiran commented Dec 20, 2017

I'm not fully satisfied with the patch, but it's as good as it will get. But it should do the trick while keeping backwards compatibility. Let's ship it!

@encukou encukou merged commit 8f5184c into python-ldap:master Dec 20, 2017
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

Successfully merging this pull request may close these issues.

2 participants