[Reproducible-commits] [reprotest] 01/01: Add support for environment variable variations, locales and time zones
Ceridwen
ceridwen-guest at moszumanska.debian.org
Sat Jun 4 15:56:10 UTC 2016
This is an automated email from the git hooks/post-receive script.
ceridwen-guest pushed a commit to branch master
in repository reprotest.
commit a94321e4b4cda933fa3e81c9a9bbfcc1d2ae9aad
Author: Ceridwen <ceridwenv at gmail.com>
Date: Sat Jun 4 11:56:04 2016 -0400
Add support for environment variable variations, locales and time zones
---
reprotest/__init__.py | 39 ++++++++++++++++++++++++++++++++++-----
tests/test.py | 21 ++++++++++++---------
2 files changed, 46 insertions(+), 14 deletions(-)
diff --git a/reprotest/__init__.py b/reprotest/__init__.py
index bc98730..4aa9e2c 100644
--- a/reprotest/__init__.py
+++ b/reprotest/__init__.py
@@ -2,12 +2,32 @@
# For details: reprotest/debian/copyright
import argparse
+import os
import subprocess
import sys
import tempfile
-def build(command, artifact_name, temp):
- return_code = subprocess.call(command)
+# TODO: what happens when these environment variables are set on
+# Windows? Hopefully nothing?
+
+# TODO: if this locale doesn't exist on the system, Python's
+# locales.getlocale() will return (None, None) rather than this
+# locale. I imagine it will also probably cause false positives with
+# builds being reproducible when they aren't because of locale-based
+# issues if this locale isn't installed. The right solution here is
+# for this locale to be encoded into the dependencies so installing it
+# installs the right locale. A weaker but still reasonable solution
+# is to figure out what locales are installed (how?) and use another
+# locale if this one isn't installed.
+
+# TODO: is this time zone location actually system-independent?
+
+ENVIRONMENT_VARIABLES1 = {'TZ': '/usr/share/zoneinfo/Etc/GMT+12'}
+
+ENVIRONMENT_VARIABLES2 = {'TZ': '/usr/share/zoneinfo/Etc/GMT-14', 'LANG': 'fr_CH.UTF-8', 'LC_ALL': 'fr_CH.UTF-8'}
+
+def build(command, artifact_name, temp, **kws):
+ return_code = subprocess.call(command, **kws)
if return_code != 0:
sys.exit(2)
else:
@@ -17,8 +37,16 @@ def build(command, artifact_name, temp):
def check(build_command, artifact_name):
with tempfile.TemporaryDirectory() as temp:
- build(build_command, artifact_name, open(temp + '/b1', 'wb'))
- build(build_command, artifact_name, open(temp + '/b2', 'wb'))
+ env = os.environ.copy()
+ # print(env)
+ env.update(ENVIRONMENT_VARIABLES1)
+ # print(env)
+ build(build_command, artifact_name, open(temp + '/b1', 'wb'),
+ env=env)
+ env.update(ENVIRONMENT_VARIABLES2)
+ # print(env)
+ build(build_command, artifact_name, open(temp + '/b2', 'wb'),
+ env=env)
sys.exit(subprocess.call(['diffoscope', temp + '/b1', temp + '/b2']))
def main():
@@ -28,6 +56,7 @@ def main():
arg_parser.add_argument('build_command', help='Build command to execute.')
arg_parse.add_argument(
'artifact', help='Build artifact to test for reproducibility.')
- # Argparse exits with status code 2 if something goes wrong.
+ # Argparse exits with status code 2 if something goes wrong, which
+ # is already the right status exit code for reprotest.
args = arg_parser.parse_args()
check(args.build_command.split(), args.artifact)
diff --git a/tests/test.py b/tests/test.py
index 7bf5b17..c254c86 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -5,17 +5,20 @@ import os
import reprotest
-def test_return_code(command, artifact, code):
+def test_return_code(command, code):
try:
- reprotest.check(command, artifact)
+ reprotest.check(command, 'tests/artifact')
except SystemExit as system_exit:
assert(system_exit.args[0] == code)
-
if __name__ == '__main__':
- test_return_code(['python', 'tests/dummy_build.py'],
- 'tests/dummy_artifact.txt', 0)
- test_return_code(['python', 'tests/fails.py'], '', 2)
- test_return_code(['python', 'tests/irreproducible.py'],
- 'tests/irreproducible_artifact', 1)
- os.remove('tests/irreproducible_artifact')
+ try:
+ test_return_code(['python', 'tests/build.py'], 0)
+ test_return_code(['python', 'tests/fails.py'], 2)
+ test_return_code(['python', 'tests/build.py', 'irreproducible'], 1)
+ test_return_code(['python', 'tests/build.py', 'locales'], 1)
+ test_return_code(['python', 'tests/build.py', 'timezone'], 1)
+ finally:
+ # Clean up random binary file created as part of the test.
+ if os.path.isfile('tests/artifact'):
+ os.remove('tests/artifact')
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/reprotest.git
More information about the Reproducible-commits
mailing list