import os import sys import shutil DIR = os.path.dirname(os.path.abspath(__file__)) NAME = os.path.basename(__file__) if not sys.argv[1:]: sys.exit('''\ usage: %(NAME)s child -- internal param to launch child process %(NAME)s spaced -- run test for dir with spaces %(NAME)s -- run test for dir with no spaces ''' % dict(NAME=NAME)) elif sys.argv[1] == 'child': print(' %s' % __file__) print(' passed') else: if sys.argv[1] == 'spaced': dirname = os.path.join(DIR, 's pace d') else: dirname = os.path.join(DIR, 'non-spaced') # create dir print('testing %s' % dirname) if not os.path.exists(dirname): os.makedirs(os.path.join(DIR, dirname)) # copy self shutil.copy(__file__, dirname) # execute selfpath = os.path.join(dirname, os.path.basename(__file__)) os.execv(sys.executable, [sys.executable, selfpath, 'child'])