[diffoscope] 01/02: Instanciate a directory container for files given on the command line

Jérémy Bobbio lunar at moszumanska.debian.org
Wed Jan 20 17:04:34 CET 2016


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch master
in repository diffoscope.

commit 8488436f36f6b6a066db9d9c311b3012f361e7a3
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Wed Jan 20 15:21:14 2016 +0000

    Instanciate a directory container for files given on the command line
    
    This will make getting the ELF symbols from a debug Debian package works even
    if only two .deb were given on the command line.
    
    We also reuse this construction to make the relevant ELF tests faster.
---
 diffoscope/comparators/__init__.py  |  8 +++++---
 diffoscope/comparators/directory.py |  6 ++++++
 tests/comparators/test_elf.py       | 17 +++++++++--------
 3 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index dabfc3b..755f7e0 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -45,7 +45,7 @@ except ImportError as ex:
     from diffoscope.comparators.debian_fallback import DotChangesFile, DotDscFile
 from diffoscope.comparators.device import Device
 from diffoscope.comparators.dex import DexFile
-from diffoscope.comparators.directory import Directory, compare_directories
+from diffoscope.comparators.directory import FilesystemDirectory, Directory, compare_directories
 from diffoscope.comparators.elf import ElfFile, ElfSection, StaticLibFile
 from diffoscope.comparators.fsimage import FsImageFile
 from diffoscope.comparators.fonts import TtfFile
@@ -88,8 +88,10 @@ def compare_root_paths(path1, path2):
         bail_if_non_existing(path1, path2)
     if os.path.isdir(path1) and os.path.isdir(path2):
         return compare_directories(path1, path2)
-    file1 = specialize(FilesystemFile(path1))
-    file2 = specialize(FilesystemFile(path2))
+    container1 = FilesystemDirectory(os.path.dirname(path1)).as_container
+    file1 = specialize(FilesystemFile(path1, container=container1))
+    container2 = FilesystemDirectory(os.path.dirname(path2)).as_container
+    file2 = specialize(FilesystemFile(path2, container=container2))
     return compare_files(file1, file2)
 
 
diff --git a/diffoscope/comparators/directory.py b/diffoscope/comparators/directory.py
index e50aa02..03713ec 100644
--- a/diffoscope/comparators/directory.py
+++ b/diffoscope/comparators/directory.py
@@ -120,6 +120,12 @@ class FilesystemDirectory(object):
     def name(self):
         return self._path
 
+    @property
+    def as_container(self):
+        if not hasattr(self, '_as_container'):
+            self._as_container = DirectoryContainer(self)
+        return self._as_container
+
     def is_directory(self):
         return True
 
diff --git a/tests/comparators/test_elf.py b/tests/comparators/test_elf.py
index 4732762..9007181 100644
--- a/tests/comparators/test_elf.py
+++ b/tests/comparators/test_elf.py
@@ -101,16 +101,18 @@ def test_lib_compare_non_existing(monkeypatch, lib1):
     assert difference.source2 == '/nonexisting'
     assert len(difference.details) > 0
 
-TEST_DBGSYM_DIR1_PATH = os.path.join(os.path.dirname(__file__), '../data/dbgsym/add')
-TEST_DBGSYM_DIR2_PATH = os.path.join(os.path.dirname(__file__), '../data/dbgsym/mult')
+TEST_DBGSYM_DEB1_PATH = os.path.join(os.path.dirname(__file__), '../data/dbgsym/add/test-dbgsym_1_amd64.deb')
+TEST_DBGSYM_DEB2_PATH = os.path.join(os.path.dirname(__file__), '../data/dbgsym/mult/test-dbgsym_1_amd64.deb')
 
 @pytest.fixture
 def dbgsym_dir1():
-    return specialize(FilesystemDirectory(TEST_DBGSYM_DIR1_PATH))
+    container = FilesystemDirectory(os.path.dirname(TEST_DBGSYM_DEB1_PATH)).as_container
+    return specialize(FilesystemFile(TEST_DBGSYM_DEB1_PATH, container=container))
 
 @pytest.fixture
 def dbgsym_dir2():
-    return specialize(FilesystemDirectory(TEST_DBGSYM_DIR2_PATH))
+    container = FilesystemDirectory(os.path.dirname(TEST_DBGSYM_DEB2_PATH)).as_container
+    return specialize(FilesystemFile(TEST_DBGSYM_DEB2_PATH, container=container))
 
 @pytest.fixture
 def dbgsym_differences(dbgsym_dir1, dbgsym_dir2):
@@ -119,16 +121,15 @@ def dbgsym_differences(dbgsym_dir1, dbgsym_dir2):
 @pytest.mark.skipif(any([tool_missing(tool) for tool in ['readelf', 'objdump', 'objcopy']]), reason='missing readelf, objdump, or objcopy')
 def test_differences_with_dbgsym(dbgsym_differences):
     output_text(dbgsym_differences, print)
-    assert dbgsym_differences.details[1].source1 == 'test-dbgsym_1_amd64.deb'
-    assert dbgsym_differences.details[1].details[2].source1 == 'data.tar.xz'
-    bin_details = dbgsym_differences.details[1].details[2].details[0].details[0]
+    assert dbgsym_differences.details[2].source1 == 'data.tar.xz'
+    bin_details = dbgsym_differences.details[2].details[0].details[0]
     assert bin_details.source1 == './usr/bin/test'
     assert bin_details.details[1].source1.startswith('objdump')
     assert 'test-cases/dbgsym/package/test.c:2' in bin_details.details[1].unified_diff
 
 @pytest.mark.skipif(any([tool_missing(tool) for tool in ['readelf', 'objdump', 'objcopy']]), reason='missing readelf, objdump, or objcopy')
 def test_original_gnu_debuglink(dbgsym_differences):
-    bin_details = dbgsym_differences.details[1].details[2].details[0].details[0]
+    bin_details = dbgsym_differences.details[2].details[0].details[0]
     assert '.gnu_debuglink' in bin_details.details[2].source1
     expected_gnu_debuglink = open(os.path.join(os.path.dirname(__file__), '../data/gnu_debuglink_expected_diff')).read()
     assert bin_details.details[2].unified_diff == expected_gnu_debuglink

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list