From f49c1ad164e7eb7eda2c52344282401589d0f66f Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 30 Apr 2017 19:53:07 +0300 Subject: [PATCH] Split test_remove_old_files.py into find_in_path.py --- tests/find_in_path.py | 9 +++++++++ tests/test_remove_old_files.py | 9 +++------ 2 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 tests/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"]) -- 2.39.5