Page MenuHomeSoftware Heritage

D5467.diff
No OneTemporary

D5467.diff

diff --git a/pytest.ini b/pytest.ini
--- a/pytest.ini
+++ b/pytest.ini
@@ -3,3 +3,4 @@
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
diff --git a/requirements-test.txt b/requirements-test.txt
--- a/requirements-test.txt
+++ b/requirements-test.txt
@@ -1,4 +1,3 @@
Click
-dulwich
pytest
pytz
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -54,6 +54,7 @@
),
extras_require={
"cli": parse_requirements("cli"),
+ "testing-minimal": parse_requirements("test"),
"testing": parse_requirements("test") + parse_requirements("cli"),
},
include_package_data=True,
diff --git a/swh/model/tests/test_cli.py b/swh/model/tests/test_cli.py
--- a/swh/model/tests/test_cli.py
+++ b/swh/model/tests/test_cli.py
@@ -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 @@
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 @@
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"
diff --git a/tox.ini b/tox.ini
--- a/tox.ini
+++ b/tox.ini
@@ -1,25 +1,25 @@
[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

File Metadata

Mime Type
text/plain
Expires
Nov 5 2024, 6:39 AM (8 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3224045

Event Timeline