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
norecursedirs = docs .*
markers =
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
dulwich
pytest
pytz
......@@ -54,6 +54,7 @@ setup(
),
extras_require={
"cli": parse_requirements("cli"),
"testing-minimal": parse_requirements("test"),
"testing": parse_requirements("test") + parse_requirements("cli"),
},
include_package_data=True,
......
......@@ -4,9 +4,11 @@
# See top-level LICENSE file for more information
import os
import sys
import tarfile
import tempfile
import unittest
import unittest.mock
from click.testing import CliRunner
import pytest
......@@ -52,6 +54,7 @@ class TestIdentify(DataMixin, unittest.TestCase):
result = self.runner.invoke(cli.identify, ["--type", "directory", path])
self.assertSWHID(result, "swh:1:dir:e8b0f1466af8608c8a3fb9879db172b887e80759")
@pytest.mark.requires_optional_deps
def test_snapshot_id(self):
"""identify a snapshot"""
tarball = os.path.join(
......@@ -68,6 +71,18 @@ class TestIdentify(DataMixin, unittest.TestCase):
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):
"""identify an origin URL"""
url = "https://github.com/torvalds/linux"
......
[tox]
envlist=black,flake8,mypy,py3,identify
envlist=black,flake8,mypy,py3-{minimal,full}
[testenv]
extras =
testing
full: testing
minimal: testing-minimal
deps =
pytest-cov
commands =
pytest --cov={envsitepackagesdir}/swh/model \
--doctest-modules \
{envsitepackagesdir}/swh/model \
--cov-branch {posargs}
full: {envsitepackagesdir}/swh/model \
minimal: {envsitepackagesdir}/swh/model/tests/test_cli.py -m 'not requires_optional_deps' \
--cov-branch {posargs}
[testenv:identify]
# no 'extras = testing', as it would install swh-core;
# and this test is designed to check 'swh-identify' does not depend on swh-core.
extras =
deps =
-r requirements-test.txt
[testenv:py3]
skip_install = true
deps = tox
commands =
pytest {envsitepackagesdir}/swh/model/tests/test_cli.py
tox -e py3-full -- {posargs}
tox -e py3-minimal -- {posargs}
[testenv:black]
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