[Reproducible-commits] [reprotest] 01/01: Very rough first draft of the command line API

Ceridwen ceridwen-guest at moszumanska.debian.org
Fri Jun 3 21:49:11 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 1104c3c89061668ab072f4c9d8d011b04d9af908
Author: Ceridwen <ceridwenv at gmail.com>
Date:   Fri Jun 3 16:58:24 2016 -0400

    Very rough first draft of the command line API
---
 reprotest/__init__.py                         | 30 ++++++++++++++++++++++++++-
 tests/dummy_artifact.txt                      |  1 +
 reprotest/__init__.py => tests/dummy_build.py |  3 +--
 reprotest/__init__.py => tests/fails.py       |  6 ++++--
 tests/irreproducible.py                       |  7 +++++++
 tests/test.py                                 | 21 +++++++++++++++++++
 6 files changed, 63 insertions(+), 5 deletions(-)

diff --git a/reprotest/__init__.py b/reprotest/__init__.py
index 6d6e960..bc98730 100644
--- a/reprotest/__init__.py
+++ b/reprotest/__init__.py
@@ -1,5 +1,33 @@
 # Licensed under the GPL: https://www.gnu.org/licenses/gpl-3.0.en.html
 # For details: reprotest/debian/copyright
 
+import argparse
+import subprocess
+import sys
+import tempfile
+
+def build(command, artifact_name, temp):
+    return_code = subprocess.call(command)
+    if return_code != 0:
+        sys.exit(2)
+    else:
+        with open(artifact_name, 'rb') as artifact:
+            temp.write(artifact.read())
+            temp.flush()
+
+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'))
+        sys.exit(subprocess.call(['diffoscope', temp + '/b1', temp + '/b2']))
+
 def main():
-    pass
+    arg_parser = argparse.ArgumentParser(
+        description='Build packages and check them for reproducibility.',
+        formatter_class=argparse.RawDescriptionHelpFormatter)
+    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.
+    args = arg_parser.parse_args()
+    check(args.build_command.split(), args.artifact)
diff --git a/tests/dummy_artifact.txt b/tests/dummy_artifact.txt
new file mode 100644
index 0000000..8f210e8
--- /dev/null
+++ b/tests/dummy_artifact.txt
@@ -0,0 +1 @@
+Foobar.
diff --git a/reprotest/__init__.py b/tests/dummy_build.py
old mode 100644
new mode 100755
similarity index 76%
copy from reprotest/__init__.py
copy to tests/dummy_build.py
index 6d6e960..a4152a0
--- a/reprotest/__init__.py
+++ b/tests/dummy_build.py
@@ -1,5 +1,4 @@
 # Licensed under the GPL: https://www.gnu.org/licenses/gpl-3.0.en.html
 # For details: reprotest/debian/copyright
 
-def main():
-    pass
+# Dummy build script, does nothing.
diff --git a/reprotest/__init__.py b/tests/fails.py
old mode 100644
new mode 100755
similarity index 65%
copy from reprotest/__init__.py
copy to tests/fails.py
index 6d6e960..0c7d4f0
--- a/reprotest/__init__.py
+++ b/tests/fails.py
@@ -1,5 +1,7 @@
 # Licensed under the GPL: https://www.gnu.org/licenses/gpl-3.0.en.html
 # For details: reprotest/debian/copyright
 
-def main():
-    pass
+import random
+import sys
+
+sys.exit(random.randrange(1, 127))
diff --git a/tests/irreproducible.py b/tests/irreproducible.py
new file mode 100755
index 0000000..e01f847
--- /dev/null
+++ b/tests/irreproducible.py
@@ -0,0 +1,7 @@
+# Licensed under the GPL: https://www.gnu.org/licenses/gpl-3.0.en.html
+# For details: reprotest/debian/copyright
+
+import os
+
+with open('tests/irreproducible_artifact', 'wb') as irreproducible_artifact:
+    irreproducible_artifact.write(os.urandom(1024))
diff --git a/tests/test.py b/tests/test.py
new file mode 100644
index 0000000..7bf5b17
--- /dev/null
+++ b/tests/test.py
@@ -0,0 +1,21 @@
+# Licensed under the GPL: https://www.gnu.org/licenses/gpl-3.0.en.html
+# For details: reprotest/debian/copyright
+
+import os
+
+import reprotest
+
+def test_return_code(command, artifact, code):
+    try:
+        reprotest.check(command, 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')

-- 
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