Skip to content

Instantly share code, notes, and snippets.

@tigarmo
Forked from nicoddemus/ren_pytest_prefix.py
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tigarmo/e93ee0984bc714e9b875 to your computer and use it in GitHub Desktop.
Save tigarmo/e93ee0984bc714e9b875 to your computer and use it in GitHub Desktop.
import os
import fnmatch
import sys
import subprocess
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)
subprocess.call('git mv %s %s' % (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