From: Oleg Broytman Date: Sun, 30 Apr 2017 16:53:07 +0000 (+0300) Subject: Split test_remove_old_files.py into find_in_path.py X-Git-Tag: 0.2.0~4 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=f49c1ad164e7eb7eda2c52344282401589d0f66f;p=ppu.git Split test_remove_old_files.py into find_in_path.py --- diff --git a/tests/find_in_path.py b/tests/find_in_path.py new file mode 100644 index 0000000..4d00613 --- /dev/null +++ b/tests/find_in_path.py @@ -0,0 +1,9 @@ +import os + + +def find_in_path(name): + for path in os.environ["PATH"].split(os.pathsep): + path = path.strip('"') + test_prog_path = os.path.join(path, name) + if os.path.exists(test_prog_path): + return test_prog_path diff --git a/tests/test_remove_old_files.py b/tests/test_remove_old_files.py index ea36506..95dd98c 100755 --- a/tests/test_remove_old_files.py +++ b/tests/test_remove_old_files.py @@ -6,17 +6,14 @@ import shutil import subprocess import sys from tempfile import mkdtemp +from find_in_path import find_in_path tmp_dir = None old_time = time() - 1000 * 24 * 3600 # 1000 days ago -for path in os.environ["PATH"].split(os.pathsep): - path = path.strip('"') - test_prog_path = os.path.join(path, 'remove-old-files.py') - if os.path.exists(test_prog_path): - break -else: +test_prog_path = find_in_path('remove-old-files.py') +if not test_prog_path: sys.exit("Cannot find remove-old-files.py in %s" % os.environ["PATH"])