Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F8394895
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
View Options
diff --git a/swh/loader/git/tests/test_converters.py b/swh/loader/git/tests/test_converters.py
new file mode 100644
index 0000000..cd8ee67
--- /dev/null
+++ b/swh/loader/git/tests/test_converters.py
@@ -0,0 +1,76 @@
+# Copyright (C) 2015 The Software Heritage developers
+# See the AUTHORS file at the top-level directory of this distribution
+# License: GNU General Public License version 3, or any later version
+# See top-level LICENSE file for more information
+
+import os
+import shutil
+import subprocess
+import tempfile
+import unittest
+
+from nose.tools import istest
+import pygit2
+
+import swh.loader.git.converters as converters
+from swh.core.hashutil import hex_to_hash
+
+
+class TestConverters(unittest.TestCase):
+ @classmethod
+ def setUpClass(cls):
+ super().setUpClass()
+ cls.repo_path = tempfile.mkdtemp()
+ cls.repo = pygit2.init_repository(cls.repo_path, bare=True)
+
+ fast_export = os.path.join(os.path.dirname(__file__),
+ '../../../../..',
+ 'swh-storage-testdata',
+ 'git-repos',
+ 'example-submodule.fast-export.xz')
+
+ xz = subprocess.Popen(
+ ['xzcat'],
+ stdin=open(fast_export, 'rb'),
+ stdout=subprocess.PIPE,
+ )
+
+ git = subprocess.Popen(
+ ['git', 'fast-import'],
+ stdin=xz.stdout,
+ stdout=subprocess.PIPE,
+ cwd=cls.repo_path,
+ )
+
+ # flush stdout of xz
+ xz.stdout.close()
+ git.communicate()
+
+ @classmethod
+ def tearDownClass(cls):
+ super().tearDownClass()
+
+ shutil.rmtree(cls.repo_path)
+ print(cls.repo_path)
+
+ def setUp(self):
+ super().setUp()
+
+ self.blob_id = pygit2.Oid(
+ hex='28c6f4023d65f74e3b59a2dea3c4277ed9ee07b0')
+ self.blob = {
+ 'sha1_git': self.blob_id.raw,
+ 'sha1': hex_to_hash('4850a3420a2262ff061cb296fb915430fa92301c'),
+ 'sha256': hex_to_hash('fee7c8a485a10321ad94b64135073cb5'
+ '5f22cb9f57fa2417d2adfb09d310adef'),
+ 'data': (b'[submodule "example-dependency"]\n'
+ b'\tpath = example-dependency\n'
+ b'\turl = https://github.com/githubtraining/'
+ b'example-dependency.git\n'),
+ 'length': 124,
+ }
+
+ @istest
+ def blob_to_content(self):
+ content = converters.blob_to_content(self.blob_id, self.repo)
+ self.assertEqual(self.blob, content)
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Jun 4 2025, 7:30 PM (9 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3213357
Attached To
rDLDG Git loader
Event Timeline
Log In to Comment