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

Add some tests #24

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/spell_check.words
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
apache
autouse
colcon
darwin
dyld
dylib
iterdir
libfoo
linter
linux
namedtuple
Expand All @@ -15,4 +17,8 @@ pydocstyle
pytest
scspell
setuptools
skipif
thomas
tmpdir
todo
unittest
63 changes: 63 additions & 0 deletions test/test_environment_library_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright 2025 Open Source Robotics Foundation, Inc.
# Licensed under the Apache License, Version 2.0

from pathlib import Path
import platform
import sys
from unittest.mock import patch

from colcon_library_path.environment.library_path import LibraryPathEnvironment
import pytest

skip_unless_windows = pytest.mark.skipif(
sys.platform != 'win32',
reason='Test is only applicable to Windows systems')

skip_unless_darwin = pytest.mark.skipif(
platform.system() != 'Darwin',
reason='Test is only applicable to Darwin systems')

skip_if_darwin_or_windows = pytest.mark.skipif(
sys.platform == 'win32' or platform.system() == 'Darwin',
reason='Test is not applicable to Darwin or Windows systems')


@pytest.fixture(scope='module', autouse=True)
def env_hook_patch():
with patch(
'colcon_core.shell.create_environment_hook',
return_value=['/some/hook', '/other/hook']
):
yield


@pytest.mark.parametrize('search_path', [
pytest.param('lib/libfoo.so', marks=skip_if_darwin_or_windows),
pytest.param('lib64/libfoo.so', marks=skip_if_darwin_or_windows),
pytest.param('lib/libfoo.dylib', marks=skip_unless_darwin),
pytest.param('bin/foo.dll', marks=skip_unless_windows),
])
def test_library_path(tmpdir, search_path):
extension = LibraryPathEnvironment()
prefix_path = Path(tmpdir)
library = prefix_path / search_path

# no libraries or directories
hooks = extension.create_environment_hooks(prefix_path, 'pkg_name')
assert len(hooks) == 0

# library directory exists but is empty
library.parent.mkdir(parents=True)
hooks = extension.create_environment_hooks(prefix_path, 'pkg_name')
assert len(hooks) == 0

# subdirectories named similarly to library
# TODO: This should probably be fixed
# library.with_name('dir_' + library.name).mkdir(parents=True)
# hooks = extension.create_environment_hooks(prefix_path, 'pkg_name')
# assert len(hooks) == 0

# library exists
library.touch()
hooks = extension.create_environment_hooks(prefix_path, 'pkg_name')
assert len(hooks) > 0
Loading