Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7437756
D966.id3065.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Subscribers
None
D966.id3065.diff
View Options
diff --git a/requirements-swh.txt b/requirements-swh.txt
--- a/requirements-swh.txt
+++ b/requirements-swh.txt
@@ -1,6 +1,6 @@
swh.core >= 0.0.46
swh.model >= 0.0.27
-swh.scheduler >= 0.0.14
+swh.scheduler >= 0.0.39
swh.storage >= 0.0.83
swh.loader.core >= 0.0.35
swh.loader.dir >= 0.0.33
diff --git a/requirements-test.txt b/requirements-test.txt
--- a/requirements-test.txt
+++ b/requirements-test.txt
@@ -1,2 +1,3 @@
-pytest
+swh-scheduler[testing]
requests-mock
+pytest-cov
diff --git a/swh/loader/tar/tasks.py b/swh/loader/tar/tasks.py
--- a/swh/loader/tar/tasks.py
+++ b/swh/loader/tar/tasks.py
@@ -3,24 +3,21 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
-from swh.scheduler.task import Task
+from celery import current_app as app
from swh.loader.tar.loader import RemoteTarLoader
-class LoadTarRepository(Task):
+@app.task(name='swh.loader.tar.tasks.LoadTarRepository', bind=True)
+def load_tar(self, origin, visit_date, last_modified):
"""Import a remote or local archive to Software Heritage
"""
- task_queue = 'swh_loader_tar'
-
- def run_task(self, *, origin, visit_date, last_modified):
- """Import a tarball into swh.
-
- Args: see :func:`TarLoader.prepare`.
-
- """
- loader = RemoteTarLoader()
- loader.log = self.log
- return loader.load(
- origin=origin, visit_date=visit_date, last_modified=last_modified)
+ self.log.debug('%s, origin=%s, visit_date=%s, last_modified=%s',
+ self.name, origin, visit_date, last_modified)
+ loader = RemoteTarLoader()
+ loader.log = self.log
+ ret = loader.load(
+ origin=origin, visit_date=visit_date, last_modified=last_modified)
+ self.log.debug('%s OK', self.name)
+ return ret
diff --git a/swh/loader/tar/tests/conftest.py b/swh/loader/tar/tests/conftest.py
new file mode 100644
--- /dev/null
+++ b/swh/loader/tar/tests/conftest.py
@@ -0,0 +1,10 @@
+import pytest
+
+from swh.scheduler.tests.conftest import * # noqa
+
+
+@pytest.fixture(scope='session')
+def celery_includes():
+ return [
+ 'swh.loader.tar.tasks',
+ ]
diff --git a/swh/loader/tar/tests/test_tasks.py b/swh/loader/tar/tests/test_tasks.py
--- a/swh/loader/tar/tests/test_tasks.py
+++ b/swh/loader/tar/tests/test_tasks.py
@@ -3,29 +3,26 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
-import unittest
from unittest.mock import patch
-from swh.loader.tar.tasks import LoadTarRepository
+@patch('swh.loader.tar.loader.RemoteTarLoader.load')
+def test_tar_loader_task(mock_loader, swh_app, celery_session_worker):
+ mock_loader.return_value = {'status': 'eventful'}
-class TestTasks(unittest.TestCase):
- def test_check_task_name(self):
- task = LoadTarRepository()
- self.assertEqual(task.task_queue, 'swh_loader_tar')
+ # task = LoadTarRepository()
+ res = swh_app.send_task(
+ 'swh.loader.tar.tasks.LoadTarRepository',
+ ('origin', 'visit_date', 'last_modified'))
+ assert res
+ res.wait()
+ assert res.successful()
- @patch('swh.loader.tar.loader.RemoteTarLoader.load')
- def test_task(self, mock_loader):
- mock_loader.return_value = {'status': 'eventful'}
- task = LoadTarRepository()
+ # given
+ actual_result = res.result
- # given
- actual_result = task.run_task(
- origin='origin', visit_date='visit_date',
- last_modified='last_modified')
+ assert actual_result == {'status': 'eventful'}
- self.assertEqual(actual_result, {'status': 'eventful'})
-
- mock_loader.assert_called_once_with(
- origin='origin', visit_date='visit_date',
- last_modified='last_modified')
+ mock_loader.assert_called_once_with(
+ origin='origin', visit_date='visit_date',
+ last_modified='last_modified')
diff --git a/tox.ini b/tox.ini
--- a/tox.ini
+++ b/tox.ini
@@ -4,7 +4,6 @@
[testenv:py3]
deps =
.[testing]
- pytest-cov
commands =
pytest --cov=swh --cov-branch {posargs}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Apr 14, 4:56 AM (13 h, 7 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3219874
Attached To
D966: Rewrite the celery task as a decorated function
Event Timeline
Log In to Comment