[diffoscope] 04/04: comparators.apk: Ensure fake "APK metadata" file appears first, fixing non-deterministic tests.
Chris Lamb
chris at chris-lamb.co.uk
Sun Jan 15 03:46:56 CET 2017
This is an automated email from the git hooks/post-receive script.
lamby pushed a commit to branch master
in repository diffoscope.
commit 998b28800bc7afab88fa15fac212113cae569a6f
Author: Chris Lamb <lamby at debian.org>
Date: Sun Jan 15 13:43:22 2017 +1100
comparators.apk: Ensure fake "APK metadata" file appears first, fixing non-deterministic tests.
Signed-off-by: Chris Lamb <lamby at debian.org>
---
diffoscope/comparators/apk.py | 27 ++++++++++++++++++---------
tests/comparators/test_apk.py | 10 +++++-----
2 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/diffoscope/comparators/apk.py b/diffoscope/comparators/apk.py
index 7acf00e..f050560 100644
--- a/diffoscope/comparators/apk.py
+++ b/diffoscope/comparators/apk.py
@@ -53,19 +53,28 @@ class ApkContainer(Archive):
), shell=False, stderr=None, stdout=subprocess.PIPE)
for root, _, files in os.walk(self._unpacked):
- for f in files:
- abspath = os.path.join(root, f)
+ current_dir = []
+
+ for filename in files:
+ abspath = os.path.join(root, filename)
# apktool.yml is a file created by apktool and containing
- # metadata information. Rename it to clarify.
- if os.path.basename(abspath) == 'apktool.yml':
+ # metadata information. Rename it to clarify and always make it
+ # appear at the beginning of the directory listing for
+ # reproducibility.
+ if filename == 'apktool.yml':
abspath = filter_apk_metadata(
abspath,
os.path.basename(self.source.name),
)
+ relpath = abspath[len(self._unpacked) + 1:]
+ current_dir.insert(0, relpath)
+ continue
relpath = abspath[len(self._unpacked)+1:]
- self._members.append(relpath)
+ current_dir.append(relpath)
+
+ self._members.extend(current_dir)
return self
@@ -76,7 +85,8 @@ class ApkContainer(Archive):
return self._members
def extract(self, member_name, dest_dir):
- return os.path.join(self._unpacked, member_name)
+ src_path = os.path.join(self._unpacked, member_name)
+ return src_path
class ApkFile(File):
RE_FILE_TYPE = re.compile(r'^(Java|Zip) archive data.*\b')
@@ -89,9 +99,8 @@ class ApkFile(File):
ApkFile.RE_FILE_EXTENSION.search(file.name)
def compare_details(self, other, source=None):
- zipinfo_difference = \
- Difference.from_command(Zipinfo, self.path, other.path) or \
- Difference.from_command(ZipinfoVerbose, self.path, other.path)
+ zipinfo_difference = Difference.from_command(Zipinfo, self.path, other.path) or \
+ Difference.from_command(ZipinfoVerbose, self.path, other.path)
return [zipinfo_difference]
diff --git a/tests/comparators/test_apk.py b/tests/comparators/test_apk.py
index 6253ace..7c539d1 100644
--- a/tests/comparators/test_apk.py
+++ b/tests/comparators/test_apk.py
@@ -51,12 +51,12 @@ def test_zipinfo(differences):
@skip_unless_tools_exist('apktool', 'zipinfo')
def test_android_manifest(differences):
- assert differences[1].source1 == 'AndroidManifest.xml'
- assert differences[1].source2 == 'AndroidManifest.xml'
+ assert differences[2].source1 == 'AndroidManifest.xml'
+ assert differences[2].source2 == 'AndroidManifest.xml'
expected_diff = open(data('apk_manifest_expected_diff')).read()
- assert differences[1].unified_diff == expected_diff
+ assert differences[2].unified_diff == expected_diff
@skip_unless_tools_exist('apktool', 'zipinfo')
def test_apk_metadata_source(differences):
- assert differences[2].source1 == 'APK metadata'
- assert differences[2].source2 == 'APK metadata'
+ assert differences[1].source1 == 'APK metadata'
+ assert differences[1].source2 == 'APK metadata'
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list