Skip to content

Commit

Permalink
Update workflows with python > 3.9 (#745)
Browse files Browse the repository at this point in the history
* Update CI workflow python versions

* Use pytest instead of nosetests

Also skip tests that require python2 when it is not installed
  • Loading branch information
timonegk committed Jan 30, 2023
1 parent edbdaef commit 78b3e43
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 18 deletions.
24 changes: 15 additions & 9 deletions .github/workflows/workflow.yml
Expand Up @@ -9,19 +9,25 @@ jobs:
matrix:
versions:
- dist: ubuntu-18.04
python: 3.6
python: "3.7"
catkin: indigo-devel
- dist: ubuntu-18.04
python: 3.7
catkin: indigo-devel
- dist: ubuntu-18.04
python: 3.8
python: "3.8"
catkin: indigo-devel
- dist: ubuntu-20.04
python: 3.8
python: "3.8"
catkin: noetic-devel
- dist: ubuntu-20.04
python: 3.9
python: "3.9"
catkin: noetic-devel
- dist: ubuntu-22.04
python: "3.9"
catkin: noetic-devel
- dist: ubuntu-22.04
python: "3.10"
catkin: noetic-devel
- dist: ubuntu-22.04
python: "3.11"
catkin: noetic-devel

runs-on: ${{ matrix.versions.dist }}
Expand All @@ -35,7 +41,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install .
pip install --upgrade empy sphinx_rtd_theme sphinxcontrib-spelling nose coverage flake8 mock isort
pip install --upgrade empy sphinx_rtd_theme sphinxcontrib-spelling pytest nose coverage flake8 mock isort
- name: Set up catkin
run: |
git clone https://github.com/ros/catkin.git -b ${{ matrix.versions.catkin }} /tmp/catkin_source
Expand All @@ -46,7 +52,7 @@ jobs:
- name: Test catkin_tools
run: |
source /tmp/catkin_source/build/devel/setup.bash
nosetests tests
pytest tests --ignore=tests/system/resources
isort -c --df --sl -l 120 catkin_tools tests
- name: Build documentation
run: |
Expand Down
6 changes: 6 additions & 0 deletions tests/system/resources/catkin_pkgs/python_tests/test_good.py
@@ -1,4 +1,10 @@
#!/usr/bin/env python
try:
from collections import Callable
except ImportError:
# https://stackoverflow.com/a/70641487
import collections
collections.Callable = collections.abc.Callable

import unittest

Expand Down
@@ -1,4 +1,10 @@
#!/usr/bin/env python
try:
from collections import Callable
except ImportError:
# https://stackoverflow.com/a/70641487
import collections
collections.Callable = collections.abc.Callable

import unittest

Expand Down
@@ -1,4 +1,10 @@
#!/usr/bin/env python
try:
from collections import Callable
except ImportError:
# https://stackoverflow.com/a/70641487
import collections
collections.Callable = collections.abc.Callable

import unittest

Expand Down
@@ -1,4 +1,10 @@
#!/usr/bin/env python
try:
from collections import Callable
except ImportError:
# https://stackoverflow.com/a/70641487
import collections
collections.Callable = collections.abc.Callable

import unittest

Expand Down
6 changes: 6 additions & 0 deletions tests/system/verbs/catkin_build/test_pythonpath.py
Expand Up @@ -3,6 +3,8 @@
import shutil
import subprocess

import pytest

from ....utils import catkin_success
from ....utils import redirected_stdio
from ...workspace_factory import workspace_factory
Expand All @@ -20,6 +22,8 @@


def test_python2_devel():
if not shutil.which('python2'):
pytest.skip('skipping python2 test because it is not installed')
with workspace_factory() as wf:
os.mkdir(os.path.join(wf.workspace, 'src'))
shutil.copytree(
Expand Down Expand Up @@ -55,6 +59,8 @@ def test_python3_devel():


def test_python2_install():
if not shutil.which('python2'):
pytest.skip('skipping python2 test because it is not installed')
with workspace_factory() as wf:
os.mkdir(os.path.join(wf.workspace, 'src'))
shutil.copytree(
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/test_config.py
Expand Up @@ -2,7 +2,7 @@
import shutil

import mock
from nose.tools import assert_raises_regexp
import pytest

from catkin_tools import config

Expand All @@ -25,7 +25,7 @@ def test_config_initialization(patched_func):
# Test failure with file for target config path
with open(test_folder, 'w') as f:
f.write('this will cause a RuntimeError')
with assert_raises_regexp(RuntimeError, "The catkin config directory"):
with pytest.raises(RuntimeError, match="The catkin config directory"):
config.initialize_config(test_folder)


Expand All @@ -34,7 +34,7 @@ def test_verb_alias_config_initialization():
cwd = os.getcwd()
test_folder = os.path.join(cwd, 'test')
# Test target directory does not exist failure
with assert_raises_regexp(RuntimeError, "Cannot initialize verb aliases because catkin configuration path"):
with pytest.raises(RuntimeError, match="Cannot initialize verb aliases because catkin configuration path"):
config.initialize_verb_aliases(test_folder)
# Test normal case
os.makedirs(test_folder)
Expand All @@ -56,7 +56,7 @@ def test_verb_alias_config_initialization():
os.makedirs(test_folder)
with open(os.path.join(test_folder, 'verb_aliases'), 'w') as f:
f.write("this will cause a RuntimeError")
with assert_raises_regexp(RuntimeError, "The catkin verb aliases config directory"):
with pytest.raises(RuntimeError, match="The catkin verb aliases config directory"):
config.initialize_verb_aliases(test_folder)
shutil.rmtree(test_folder)

Expand All @@ -66,12 +66,12 @@ def test_get_verb_aliases():
cwd = os.getcwd()
test_folder = os.path.join(cwd, 'test')
# Test failure case where config folder does not exist
with assert_raises_regexp(RuntimeError, "Cannot get verb aliases because the catkin config path"):
with pytest.raises(RuntimeError, match="Cannot get verb aliases because the catkin config path"):
config.get_verb_aliases(test_folder)
# Test failure case where aliases folder does not exist
with mock.patch('catkin_tools.config.initialize_verb_aliases'):
config.initialize_config(test_folder)
with assert_raises_regexp(RuntimeError, "Cannot get verb aliases because the verb aliases config path"):
with pytest.raises(RuntimeError, match="Cannot get verb aliases because the verb aliases config path"):
config.get_verb_aliases(test_folder)
shutil.rmtree(test_folder)
# Test the normal case
Expand All @@ -97,21 +97,21 @@ def test_get_verb_aliases():
- foo
- bar
""")
with assert_raises_regexp(RuntimeError, "Invalid alias file"):
with pytest.raises(RuntimeError, match="Invalid alias file"):
config.get_verb_aliases(test_folder)
os.remove(bad_path)
with open(bad_path, 'w') as f:
f.write("""\
null: foo
""")
with assert_raises_regexp(RuntimeError, "Invalid alias in file"):
with pytest.raises(RuntimeError, match="Invalid alias in file"):
config.get_verb_aliases(test_folder)
os.remove(bad_path)
with open(bad_path, 'w') as f:
f.write("""\
foo: 13.4
""")
with assert_raises_regexp(RuntimeError, "Invalid alias expansion in file"):
with pytest.raises(RuntimeError, match="Invalid alias expansion in file"):
config.get_verb_aliases(test_folder)
os.remove(bad_path)
# Test with an empty custom file
Expand Down

0 comments on commit 78b3e43

Please sign in to comment.