Skip to content
Snippets Groups Projects
Commit 27a05d68 authored by vlorentz's avatar vlorentz
Browse files

tox: Check swh-identify can run even if Dulwich isn't installed

parent c62f13fd
No related branches found
No related tags found
No related merge requests found
...@@ -3,3 +3,4 @@ addopts = --doctest-modules -p no:pytest_swh_core ...@@ -3,3 +3,4 @@ addopts = --doctest-modules -p no:pytest_swh_core
norecursedirs = docs .* norecursedirs = docs .*
markers = markers =
fs: tests that involve filesystem ios fs: tests that involve filesystem ios
requires_optional_deps: tests in test_cli.py that should not run if optional dependencies are not installed
Click Click
dulwich
pytest pytest
pytz pytz
...@@ -54,6 +54,7 @@ setup( ...@@ -54,6 +54,7 @@ setup(
), ),
extras_require={ extras_require={
"cli": parse_requirements("cli"), "cli": parse_requirements("cli"),
"testing-minimal": parse_requirements("test"),
"testing": parse_requirements("test") + parse_requirements("cli"), "testing": parse_requirements("test") + parse_requirements("cli"),
}, },
include_package_data=True, include_package_data=True,
......
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
# See top-level LICENSE file for more information # See top-level LICENSE file for more information
import os import os
import sys
import tarfile import tarfile
import tempfile import tempfile
import unittest import unittest
import unittest.mock
from click.testing import CliRunner from click.testing import CliRunner
import pytest import pytest
...@@ -52,6 +54,7 @@ class TestIdentify(DataMixin, unittest.TestCase): ...@@ -52,6 +54,7 @@ class TestIdentify(DataMixin, unittest.TestCase):
result = self.runner.invoke(cli.identify, ["--type", "directory", path]) result = self.runner.invoke(cli.identify, ["--type", "directory", path])
self.assertSWHID(result, "swh:1:dir:e8b0f1466af8608c8a3fb9879db172b887e80759") self.assertSWHID(result, "swh:1:dir:e8b0f1466af8608c8a3fb9879db172b887e80759")
@pytest.mark.requires_optional_deps
def test_snapshot_id(self): def test_snapshot_id(self):
"""identify a snapshot""" """identify a snapshot"""
tarball = os.path.join( tarball = os.path.join(
...@@ -68,6 +71,18 @@ class TestIdentify(DataMixin, unittest.TestCase): ...@@ -68,6 +71,18 @@ class TestIdentify(DataMixin, unittest.TestCase):
result, "swh:1:snp:abc888898124270905a0ef3c67e872ce08e7e0c1" result, "swh:1:snp:abc888898124270905a0ef3c67e872ce08e7e0c1"
) )
def test_snapshot_without_dulwich(self):
"""checks swh-identify returns a 'nice' message instead of a traceback
when dulwich is not installed"""
with unittest.mock.patch.dict(sys.modules, {"dulwich": None}):
with tempfile.TemporaryDirectory(prefix="swh.model.cli") as d:
result = self.runner.invoke(
cli.identify, ["--type", "snapshot", d], catch_exceptions=False,
)
assert result.exit_code == 1
assert "'swh.model[cli]'" in result.output
def test_origin_id(self): def test_origin_id(self):
"""identify an origin URL""" """identify an origin URL"""
url = "https://github.com/torvalds/linux" url = "https://github.com/torvalds/linux"
......
[tox] [tox]
envlist=black,flake8,mypy,py3,identify envlist=black,flake8,mypy,py3-{minimal,full}
[testenv] [testenv]
extras = extras =
testing full: testing
minimal: testing-minimal
deps = deps =
pytest-cov pytest-cov
commands = commands =
pytest --cov={envsitepackagesdir}/swh/model \ pytest --cov={envsitepackagesdir}/swh/model \
--doctest-modules \ --doctest-modules \
{envsitepackagesdir}/swh/model \ full: {envsitepackagesdir}/swh/model \
--cov-branch {posargs} minimal: {envsitepackagesdir}/swh/model/tests/test_cli.py -m 'not requires_optional_deps' \
--cov-branch {posargs}
[testenv:identify] [testenv:py3]
# no 'extras = testing', as it would install swh-core; skip_install = true
# and this test is designed to check 'swh-identify' does not depend on swh-core. deps = tox
extras =
deps =
-r requirements-test.txt
commands = commands =
pytest {envsitepackagesdir}/swh/model/tests/test_cli.py tox -e py3-full -- {posargs}
tox -e py3-minimal -- {posargs}
[testenv:black] [testenv:black]
skip_install = true skip_install = true
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment