Esempio n. 1
0
def create_test_files():
	"""Create the directories and files used for testing.
	   These are the same directories and files created in
	   AStyleTestI18n_I18n.
	"""
	prtdir = testdir
	prtdir = prtdir.replace('\\', '/')
	prtdir = libextract.strip_directory_prefix(prtdir)
	# create the test directory
	imax = 2	# max number of retries
	for i in range(0, imax):
		try:
			os.mkdir(testdir)
		except WindowsError:
			# print a message and retry
			print "mkdir WindowsError"
		if os.path.isdir(testdir): break
		if i == imax - 1:
			libastyle.system_exit("mkdir WindowsError " + testdir)
		time.sleep(1)
	# create Russian sub directories
	os.mkdir(testdir + subdir1)
	os.mkdir(testdir + subdir1a)
	os.mkdir(testdir + subdir1b)
	os.mkdir(testdir + subdir2)

	# create the test files
	text = (
		"\nvoid foo()\n"
		"{\n"
		"bar();\n"
		"}\n"
	)
	fileNames = []
	fileNames.append(testdir +  "/recursive1.cpp")
	fileNames.append(testdir + subdir1  + "/recursive2.cpp")
	fileNames.append(testdir + subdir1  + "/recursive3.cpp")
	fileNames.append(testdir + subdir1a + "/recursive4.cpp")
	fileNames.append(testdir + subdir1a + "/recursive5.cpp")
	fileNames.append(testdir + subdir1b + "/recursive6.cpp")
	fileNames.append(testdir + subdir1b + "/recursive7.cpp")
	fileNames.append(testdir + subdir2  + "/recursive8.cpp")
	fileNames.append(testdir + subdir2  + "/recursive9.cpp")
	for file in fileNames:
		outfile = open(file, 'w')
		outfile.write(text)
		outfile.close()
	return fileNames
Esempio n. 2
0
def clean_test_directory(testdir):
    """Find and remove ALL pre-existing files and directories.
	"""
    imax = 2  # max number of retries
    files = glob.glob(testdir)
    for file in files:
        file = file.replace('\\', '/')
        prtfile = libextract.strip_directory_prefix(file)
        # removed the directory - this is a problem with Windows only
        for i in range(0, imax):
            shutil.rmtree(file, True)
            if not os.path.isdir(file): break
            if i == imax - 1:
                print "Directory not removed: " + file
                libastyle.system_exit("Remove the directory manually")
            time.sleep(1)
    # Windows has to wait for the all directories to be removed
    for i in range(0, imax):
        if not os.path.isdir(testdir): break
        time.sleep(1)