Skip to content

Commit

Permalink
Make tests portable enough to run on Windows (#268)
Browse files Browse the repository at this point in the history
No changes to the package itself were necessary.
  • Loading branch information
cottsay authored Apr 19, 2024
1 parent 82779ed commit b269a4b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ on: # yamllint disable-line rule:truthy
jobs:
pytest:
uses: ros-infrastructure/ci/.github/workflows/pytest.yaml@main
with:
matrix-filter: del(.matrix.os[] | select(contains("windows")))
yamllint:
runs-on: ubuntu-latest
steps:
Expand Down
9 changes: 5 additions & 4 deletions test/test_rospkg_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def test_get_ros_root():
from rospkg import get_ros_root
assert get_ros_root(env={}) is None

env = {'ROS_ROOT': '/fake/path'}
assert '/fake/path' == get_ros_root(env=env)
fake_path = os.path.normpath('/fake/path')
env = {'ROS_ROOT': fake_path}
assert fake_path == get_ros_root(env=env)

real_ros_root = get_ros_root()

Expand Down Expand Up @@ -142,8 +143,8 @@ def test_compute_package_paths():
assert compute_package_paths(None, 'bar') == ['bar'], compute_package_paths(None, 'bar')
assert compute_package_paths('foo', '') == ['foo']
assert compute_package_paths('foo', 'bar') == ['foo', 'bar']
assert compute_package_paths('foo', 'bar:bz') == ['foo', 'bar', 'bz']
assert compute_package_paths('foo', 'bar:bz::blah') == ['foo', 'bar', 'bz', 'blah']
assert compute_package_paths('foo', os.path.pathsep.join(('bar', 'bz'))) == ['foo', 'bar', 'bz']
assert compute_package_paths('foo', os.path.pathsep.join(('bar', 'bz', '', 'blah'))) == ['foo', 'bar', 'bz', 'blah']


def test_resolve_path():
Expand Down
4 changes: 3 additions & 1 deletion test/test_rospkg_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ def test_parse_manifest():
from rospkg.manifest import MANIFEST_FILE, parse_manifest
d = get_test_dir()
p = os.path.join(d, 'example1', MANIFEST_FILE)
with open(p, 'r') as f:
# Open in binary mode to match the parse_manifest_file function
# This is particularly important on Windows
with open(p, 'rb') as f:
contents = f.read()
_subtest_parse_example1(parse_manifest(MANIFEST_FILE, contents, p))

Expand Down
3 changes: 2 additions & 1 deletion test/test_rospkg_os_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from __future__ import absolute_import

import os
import sys

try:
from unittest.mock import Mock, patch
Expand Down Expand Up @@ -75,7 +76,7 @@ def get_codename(self):

def test__read_stdout():
from rospkg.os_detect import _read_stdout
assert 'hello' == _read_stdout(['echo', 'hello'])
assert 'hello' == _read_stdout([sys.executable, '-c', "print('hello')"])
assert _read_stdout(['bad-command-input-for-rospkg-os-detect']) is None


Expand Down

0 comments on commit b269a4b

Please sign in to comment.