Last active
August 29, 2015 14:22
-
-
Save nicoddemus/58db6fabefdc43652c57 to your computer and use it in GitHub Desktop.
Rename all tests from "pytest_" to "test_", including data directories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import fnmatch | |
import sys | |
directory = sys.argv[1] | |
for root, dirs, names in os.walk(sys.argv[1]): | |
for name in names: | |
if fnmatch.fnmatch(name, 'pytest_*.py') and os.path.basename(root) == '_tests': | |
source = os.path.join(root, name) | |
target = os.path.join(root, name[2:]) | |
if not os.path.isfile(target): | |
data_dir = os.path.splitext(source)[0] | |
if os.path.isdir(data_dir): | |
dir_name = os.path.basename(data_dir)[2:] | |
target_dir = os.path.join(os.path.dirname(data_dir), dir_name) | |
os.rename(data_dir, target_dir) | |
subprocess.call('git mv %s %s' % (source, target)) | |
else: | |
print '***', target, 'already exists: merge the two tests' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment