Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/tar/tests/test_build.py
# Copyright (C) 2015-2018 The Software Heritage developers | # Copyright (C) 2015-2018 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import unittest | import unittest | ||||
from unittest.mock import patch | from unittest.mock import patch | ||||
from swh.loader.tar import build | from swh.loader.tar import build | ||||
class TestBuildUtils(unittest.TestCase): | class TestBuildUtils(unittest.TestCase): | ||||
def test_compute_origin(self): | @patch('swh.loader.tar.build._time_from_last_modified') | ||||
# given | def test_compute_revision(self, mock_time_from_last_modified): | ||||
expected_origin = { | mock_time_from_last_modified.return_value = 'some-other-time' | ||||
'url': 'rsync://some/url/package-foo', | |||||
'type': 'rsync', | |||||
} | |||||
# when | |||||
actual_origin = build.compute_origin( | |||||
'rsync://some/url/', | |||||
'rsync', | |||||
'/some/root/path/', | |||||
'/some/root/path/package-foo/package-foo-1.2.3.tgz') | |||||
# then | |||||
self.assertEqual(actual_origin, expected_origin) | |||||
@patch('swh.loader.tar.build._time_from_path') | |||||
def test_compute_revision(self, mock_time_from_path): | |||||
mock_time_from_path.return_value = 'some-other-time' | |||||
# when | # when | ||||
actual_revision = build.compute_revision('/some/path') | actual_revision = build.compute_revision('/some/path', 'last-modified') | ||||
expected_revision = { | expected_revision = { | ||||
'date': { | 'date': { | ||||
'timestamp': 'some-other-time', | 'timestamp': 'some-other-time', | ||||
'offset': build.UTC_OFFSET, | 'offset': build.UTC_OFFSET, | ||||
}, | }, | ||||
'committer_date': { | 'committer_date': { | ||||
'timestamp': 'some-other-time', | 'timestamp': 'some-other-time', | ||||
'offset': build.UTC_OFFSET, | 'offset': build.UTC_OFFSET, | ||||
}, | }, | ||||
'author': build.SWH_PERSON, | 'author': build.SWH_PERSON, | ||||
'committer': build.SWH_PERSON, | 'committer': build.SWH_PERSON, | ||||
'type': build.REVISION_TYPE, | 'type': build.REVISION_TYPE, | ||||
'message': build.REVISION_MESSAGE, | 'message': build.REVISION_MESSAGE, | ||||
'synthetic': True, | |||||
} | } | ||||
# then | # then | ||||
self.assertEqual(actual_revision, expected_revision) | self.assertEqual(actual_revision, expected_revision) | ||||
mock_time_from_path.assert_called_once_with('/some/path') | mock_time_from_last_modified.assert_called_once_with( | ||||
'last-modified') | |||||
@patch('swh.loader.tar.build.os') | def test_time_from_last_modified_with_float(self): | ||||
def test_time_from_path_with_float(self, mock_os): | actual_time = build._time_from_last_modified( | ||||
class MockStat: | '2015-10-20T13:38:06.830834+00:00') | ||||
st_mtime = 1445348286.8308342 | |||||
mock_os.lstat.return_value = MockStat() | |||||
actual_time = build._time_from_path('some/path') | |||||
self.assertEqual(actual_time, { | self.assertEqual(actual_time, { | ||||
'seconds': 1445348286, | 'seconds': 1445348286, | ||||
'microseconds': 8308342 | 'microseconds': 830834 | ||||
ardumont: Apparently my initial mtime was wrong, thus the slight change here.
Other than that, i used the… | |||||
}) | }) | ||||
mock_os.lstat.assert_called_once_with('some/path') | def test_time_from_last_modified_with_int(self): | ||||
actual_time = build._time_from_last_modified( | |||||
Done Inline ActionsI used the same date as before with another format. ardumont: I used the same date as before with another format. | |||||
@patch('swh.loader.tar.build.os') | '2015-10-20T13:38:06+00:00') | ||||
def test_time_from_path_with_int(self, mock_os): | |||||
class MockStat: | |||||
st_mtime = 1445348286 | |||||
mock_os.lstat.return_value = MockStat() | |||||
actual_time = build._time_from_path('some/path') | |||||
self.assertEqual(actual_time, { | self.assertEqual(actual_time, { | ||||
'seconds': 1445348286, | 'seconds': 1445348286, | ||||
'microseconds': 0 | 'microseconds': 0 | ||||
}) | }) | ||||
mock_os.lstat.assert_called_once_with('some/path') |
Apparently my initial mtime was wrong, thus the slight change here.
Other than that, i used the same date as before with another readable format.