2121import math
2222import multiprocessing
2323import operator
24+ import os
2425import random
26+ import shlex
2527import subprocess
2628import sys
29+ import tempfile
2730import textwrap
2831import time
2932
@@ -244,14 +247,15 @@ def run_backup_tests(test, new_blessed, run_reproducibility=True, run_speed=True
244247 pass
245248 elif result .returncode != 0 :
246249 print_red ("failing-command {} {}s" .format (name , elapsed ))
250+ print_red (textwrap .indent ("generate command: " + qr_command , " " ))
247251 print_red (textwrap .indent (result .stderr .decode ("utf8" ), " " ))
248252 failures += 1
249253 return failures , None
250254 elif sha == expected_sha :
251255 print_green ("backup-reproducible {} {}s" .format (name , elapsed ))
252256 else :
253257 print_red ("backup-not-reproducible {} {}s" .format (name , elapsed ))
254- print ( " command:" , qr_command )
258+ print_red ( textwrap . indent ( "generate command: " + qr_command , " " ) )
255259 print (" result:" , sha , "!=" , expected_sha )
256260 failures += 1
257261
@@ -261,6 +265,7 @@ def run_backup_tests(test, new_blessed, run_reproducibility=True, run_speed=True
261265 if run_speed :
262266 if elapsed > time_limit * 2 :
263267 print_red ("too-slow" , name , "{}s, <2^{}" .format (elapsed , power ))
268+ print_red (textwrap .indent ("generate command: " + qr_command , " " ))
264269 failures += 1
265270 elif elapsed <= time_limit / 3 :
266271 print ("too-fast" , name , "{}s, <2^{}" .format (elapsed , power ))
@@ -277,16 +282,21 @@ def run_backup_tests(test, new_blessed, run_reproducibility=True, run_speed=True
277282
278283 if result2 .returncode != 0 :
279284 print_red ("failing-command {} {}s" .format (name , elapsed ))
285+ print_red (textwrap .indent ("generate command: " + qr_command , " " ))
286+ print_red (textwrap .indent ("restore command: " + restore_command , " " ))
280287 print_red (textwrap .indent (result2 .stderr .decode ("utf8" ), " " ))
281288 failures += 1
282- return failures , None
289+ return failures
283290 elif input_bytes == restored_bytes :
284291 print_green ("correct-restore {} {}s" .format (name , elapsed ))
292+ fail = False
285293 if expected_sha is not None and sha != expected_sha :
286294 new_blessed [name ] = sha
287295 else :
288296 print_red ("incorrect-restore {} {}s" .format (name , elapsed ))
289- print (" command:" , restore_command )
297+
298+ print_red (textwrap .indent ("generate command: " + qr_command , " " ))
299+ print_red (textwrap .indent ("restore command: " + restore_command , " " ))
290300 #print(input_bytes, restored_bytes)
291301 failures += 1
292302
@@ -363,7 +373,10 @@ def main(args):
363373 run_restore = run_restore ,
364374 ))
365375
366- failures = test_runner (tests , parallel = parallel )
376+ with tempfile .TemporaryDirectory () as td :
377+ # This fixes https://github.com/za3k/qr-backup/issues/74, where $HOME/.gnupg may not exist and cause decryption to fail
378+ os .environ ["GNUPGHOME" ] = td
379+ failures = test_runner (tests , parallel = parallel )
367380
368381 if len (new_blessed ) > 0 :
369382 print ("NEW BLESSED_OUTPUT = {" )
0 commit comments